Windows WQL query over WinRM (win_wql)
Runs a WQL SELECT of your own over WinRM and reports numeric properties of one row as channels. Use it for what the Windows sensors do not cover: a vendor's WMI class, the health of a storage pool, a battery, a queue length kept in a class of its own.
Transport. Under a Windows probe the device can be set to read this sensor over native WMI instead of WinRM; the query and the result are the same. The target is then set up as in the WMI setup guide instead.
What it looks like

The sensor's page after a few polls, reading the free space and size of C: from Win32_LogicalDisk on a Windows Server domain controller reached over WinRM. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.
Who can attach it
Only administrators can create a win_wql sensor or change its parameters, as with the sensors that run programs. An operator can still rename it, pause it and set its limits. A device template cannot attach one, so discovery never proposes it. The sensor does not run anything on the probe, and it can only read, but:
- the query is the administrator's, so it can be expensive for the target: a
SELECT *onWin32_Productmakes Windows verify every installed package, and a class with hundreds of thousands of rows is read in full when you look for a key; - it reads whatever the stored credential may read through WMI, which is more than the fixed sensors read, and the person who attaches it need not be allowed to see that credential.
win_perf reads performance classes only and stays open to operators.
What is accepted
The query is checked when the sensor is saved and again before every poll. Only this form is accepted:
SELECT <* | property, property, ...> FROM <class> [WHERE <condition>]
Everything else is refused, with the reason, and never sent to the target:
- more than one statement, and any
;outside a quoted string; ASSOCIATORS OF,REFERENCES OF, and event queries (WITHIN,GROUP,HAVING), which would wait for events or follow relationships instead of returning rows;- classes whose name starts with
__(WMI's own system and event classes); ORDER BY, aggregates, joins, nestedSELECT, comments, and any character a plainSELECTdoes not use ({ } [ ] $ @ ; # /and the like) outside a quoted string;- queries longer than 2000 characters, and control characters inside a quoted string.
Quoted strings ('...' or "...", with \ escaping the next character) are data: a ; or the word DELETE inside one is just text. Beyond this check the WinRM client only enumerates; it has no way to call a method, so a query cannot change the target even if it were accepted.
Select only the properties you need and filter in the WHERE clause, so the target does the least work. When the query lists its properties, every channel's property and the key property must be among them.
Channels
| Key | Name | Unit | Default limits |
|---|---|---|---|
values_read | Values read | none | |
one per entry of channels | its name, or its key | its unit, or none | none. Set limits on the sensor. |
values_read is how many channels had a number in this poll.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
query | required | The SELECT, as above. |
namespace | root\cimv2 | The WMI namespace, such as root\wmi or root\Microsoft\Windows\Storage. Slashes and backslashes both work. It must start with root, have at most 8 levels, and contain only letters, digits and underscores. |
key_property and key_value | none | Give both or neither. The sensor reads the row whose key_property equals key_value (case does not matter), out of the rows the query returns. Without them it reads the first row, and asks the target for no more than that one. |
channels | required | 1 to 30 entries, below. |
port | 5985, or 5986 with https | TCP port of the WinRM listener. |
https | false | Use the HTTPS listener instead of HTTP with message encryption. |
accept_self_signed | false | Accept an HTTPS certificate that cannot be verified. The credential has the same switch; either one is enough. |
A channel:
| Field | Default | Meaning |
|---|---|---|
key | required | Lower case letters, digits and _, at most 40 characters. values_read is reserved. History is stored under it. |
property | required | The property of the chosen row. Letters, digits and underscores only; case does not matter. |
scale | 1 | A numeric value is multiplied by this. Not zero. |
value_map | none | {"from": "Running", "to": 4} entries turn strings, numbers or booleans into numbers. Checked before numeric conversion. A text or boolean from is also the label shown for the whole number it maps to. At most 50. |
expected | none | The raw value must equal this (a string, a number or a boolean; text is compared without regard to case). Anything else makes the sensor Down. |
required | true | A missing value makes the sensor Down. With false the channel is just unknown. |
name | the key | The name shown for the channel, up to 80 characters. |
unit | none | The unit of the reported value (after scale), up to 20 characters. |
The value map, expected, required and the rule that a value which is not a number and has no map entry makes the sensor Down work as they do in rest_json. An array property (an OperationalStatus of several codes) is read as its first element.
Suggested interval: 300 seconds. Credential: Windows. Discovery does not propose it.
Examples
Free space of one volume, found by its key:
{
"query": "SELECT DeviceID,FreeSpace,Size FROM Win32_LogicalDisk",
"key_property": "DeviceID",
"key_value": "D:",
"channels": [
{ "key": "free", "property": "FreeSpace", "name": "Free space", "unit": "B" },
{ "key": "size", "property": "Size", "unit": "B" }
]
}The health of the first disk the storage subsystem knows, in its own namespace, Down when it is not healthy:
{
"query": "SELECT HealthStatus,IsOffline FROM MSFT_Disk",
"namespace": "root\\Microsoft\\Windows\\Storage",
"channels": [
{ "key": "health", "property": "HealthStatus", "expected": 0 },
{ "key": "offline", "property": "IsOffline", "expected": false,
"value_map": [{ "from": false, "to": 0 }, { "from": true, "to": 1 }] }
]
}On the target
WinRM enabled and an account set up as in the WinRM setup guide, with remote read access to the namespace you query. Namespaces other than root\cimv2 often need that right granted on them separately.
Failures
The WinRM failures every Windows sensor shares are listed in the setup guide. Specific to this sensor:
| Message | Meaning |
|---|---|
the query is refused: ... (kind config) | The query is not a single plain SELECT. The sensor was saved before the check existed, or came in with a file that was not checked. Fix the query. |
the WQL query was rejected (kind config) | WMI does not accept the query, usually a property that does not exist. WMI does not say which. |
the WMI class does not exist, the WMI namespace does not exist (kind config) | The class or namespace is not on the target. |
the query returned no rows (kind config) | Nothing matched. |
none of the N row(s) the query returned has <key> equal to <value> (kind config) | No row has the key. The sensor reads at most 5000 rows. |
N rows have <key> equal to <value>; the sensor cannot tell which one it monitors (kind protocol) | The key is not unique. Add to the WHERE clause or choose another key. |
<property> is x, which is not a number; add a value map entry for it | Down. Text from the target is cut to 60 characters and stripped of control characters before it is repeated. |
<property> has no value, <property> is x but y was expected | Down. |
Verification
Checked against WS-Man responses recorded from a Windows Server 2022 domain controller (volumes, services, the storage namespace), and that server live over NTLM: a row by key and a first row, a value map, expected values, a boolean, another namespace written with backslashes, and each failure above. The accept and refuse rules are checked with a table of about fifty queries, including statements chained with ;, relationship and event queries, comments, quotes that are not closed and control characters; the API test shows an operator refused and an administrator accepted. Native WMI is checked through the same client interface, not against a Windows probe.