What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

WMI CUSTOM STRING: need help with output

Votes:

0

Hi,

I am attempting to monitor RD Gateway Connections to see if anyone is logged in. My WMI query is

SELECT UserName FROM Win32_TSGatewayConnection

I have successfully created a WQL file and a simple sensor in PRTG, which returns the result <domain>\<username> when 1 user is logged in. I'm not sure yet what happens, or what result is shown, when more than 1 person is logged in.

Anyway, I have a few issues:

1. The query result (the username) is shown as the 'sensor message', rather than as a 'channel' value - how can I show the username(s) as channel values?

If it is not possible to list names of logged in users, perhaps I could simply query the total number of logged in users?

2. When no users are logged in the sensor appears 'down' as no results are returned. How can I change it so that this does not cause the sensor to go down?

Under 'Scanning Interval' settings, there are options for 'If a Sensor Query fails' but the only options available are 'set sensor to warning for x intervals, then set to down'.

3. There are two default channels created; Downtime and Response Time. I'm not interested in either. Can I create my own channels in the query? Can I remove the default channels?

This is my first time setting up a WMI custom query. I have read the /help/wmi_custom_string_sensor.htm page, but I don't understand how a lot of the settings relate to my query.

Any help would be appreciated. Thanks

custom-sensor wmi wmi-custom-sensor

Created on May 30, 2018 10:45:29 AM



7 Replies

Votes:

0

Be aware of the following:

  • PRTG only evaluates numeric numbers
  • WQL (WMI Query Language) does not have a COUNT(*) option

With that in mind, you'll need to use PowerShell to evaluate the output of the WMI query and put it in the following format: <value>:<message>

The sensor will always go down if there are no actual values to return, which is not the case with a PowerShell sensor. It will simply stay at 0, when the variable is initialized with the same: $value = 0;


Kind regards,
Stephan Linke, Tech Support Team

Created on May 31, 2018 10:07:36 AM by  Stephan Linke [Paessler Support]



Votes:

0

Thanks Stephan,

So, just that I understand, if I use Powershell to query WMI, I would need to re-write it in PowerShell? Then presumably change my sensor so that it uses (and points to) the new PowerShell script?

Sorry for the noob questions. This is my first time dabbling with WMI/WQL and custom scripts.

Thanks in advance.

Created on Jun 7, 2018 9:07:47 AM



Votes:

0

Thank you. After re-reading your answer are you suggesting I use two solutions; WQL for the message and powershell to count the number of users logged in?

Or can both be achieved with a single Powershell script?

If so, can you elaborate on how I can evaluate the WMI query results with Powershell? I'm not sure where to put <value>:<message>

Thanks.

Created on Jun 7, 2018 11:22:07 AM



Votes:

0

Ok, after some more trial and error, I now have the following, which gives me a sensor count of the number of logged in users...

$RDSGatewayServer = "gatewayserver.domain.com" $Namespace = "root\cimv2\TerminalServices" $GatewayLoggedInUsers = @(get-wmiobject -class Win32_TSGatewayConnection -computername $RDSGatewayServer -namespace $Namespace).Count Write-Host "<prtg>" "<result>" "<channel>Users Logged into RDS Gateway</channel>" "<value>"+$GatewayLoggedInUsers+"</value>" "</result>" "</prtg>"

Now, is it possible to add the FullUserName output from the WQL script to this, so I can identify who the users are?

Created on Jun 7, 2018 11:35:54 AM



Votes:

0

$Users = (Get-WmiObject -Query "<wql query>" -ComputerName <targethost>)

:)

Created on Jun 7, 2018 1:25:09 PM by  Stephan Linke [Paessler Support]



Votes:

0

Um, ok, thanks. I'm not sure what to do with the code in your reply, so I have guessed where it should go and how to deal with the output.

$RDSGatewayServer = "gatewayserver.domain.com" $Namespace = "root\cimv2\TerminalServices" $GatewayLoggedInUsers = @(get-wmiobject -class Win32_TSGatewayConnection -computername $RDSGatewayServer -namespace $Namespace).Count $Users = (Get-WmiObject -Query "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\WMI WQL scripts\RDSGatewayMonitoring.wql" -ComputerName $RDSGatewayServer) Write-Host "<prtg>" "<result>" "<channel>Users Logged into RDS Gateway</channel>" "<value>"+$GatewayLoggedInUsers+"</value>" "</result>" "<result>" "<channel>Users</channel>" "<value>"+$Users+"</value>" "</result>" "</prtg>"

I'm getting the following error

Get-WmiObject : Invalid query "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\WMI WQL scripts\RDSGatewayMonitoring.wql" At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\RDSGatewayLoggedOnUsers.ps1:4 char:11 + $Users = (Get-WmiObject -Query "C:\Program Files (x86)\PRTG Network M ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCo mmand

I have double-checked the path to WQL is correct.

Created on Jun 7, 2018 1:44:39 PM



Votes:

0

You'll need to use the actual query, not the path to the query file :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 8, 2018 12:44:49 PM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.