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

Need help with custom Powershell sensor

Votes:

0

Hello - I've written a powershell script for this but I need a little help tweaking the output. I need to monitor the "Connections Allowed" status of our Remote Desktop session host servers. The script appears to be working when I run it manually, but no matter what the actual data is in the XML output, the sensor always shows a status of 0. What am I missing here?

Here's some sample output:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>powershell.exe -command .\PRTG_RDSH_Session_Connections_Allowed.ps1 -RDSH_Server "rdsh1.domain.com"
<prtg>
                <result>
                    <channel>New Connections</channel>
                    <unit>Custom</unit>
                    <CustomUnit>Status</CustomUnit>
                    <value>2</value>
                </result>
    <text>OK</text>
</prtg>

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>powershell.exe -command .\PRTG_RDSH_Session_Connections_Allowed.ps1 -RDSH_Server "rdsh2.domain.com"
<prtg>
                <result>
                    <channel>New Connections</channel>
                    <unit>Custom</unit>
                    <CustomUnit>Status</CustomUnit>
                    <value>0</value>
                </result>
    <text>OK</text>
</prtg>

Here's the script itself:

param(
[string]$RDSH_Server
)

#variables

$name = 'New Connections'
$unit = "Custom"
$customUnit = "Status"
$mode = "Absolute"
$warning = 0
$float = 1

$ConnectionsEnabled=Get-RDSessionHost -ConnectionBroker rdcb.domain.com -CollectionName "Apps - General" | where {$_.SessionHost -eq $RDSH_Server} | Select NewConnectionAllowed -ExpandProperty NewConnectionAllowed
if ($ConnectionsEnabled -eq "Yes") {$ConnectionsEnabledInt=0}
if ($ConnectionsEnabled -eq "NotUntilReboot") {$ConnectionsEnabledInt=1}
if ($ConnectionsEnabled -eq "No") {$ConnectionsEnabledInt=2}

#Create xml for sensor
$xml = @"
<prtg>

"@


#Main XML body for result
$xml += @"
                <result>
                    <channel>$name</channel>                    
                    <unit>$unit</unit>
                    <CustomUnit>$customUnit</CustomUnit>
                    <value>$ConnectionsEnabledInt</value>
                </result>

"@
#Text for sensor
$xml += @"
    <text>OK</text>

"@
#add /prtg to close out the xml.
 $xml += @"
</prtg>

"@           
 #output the XML
 $xml

exexml powershell prtg

Created on Nov 16, 2015 11:16:09 PM



1 Reply

Votes:

0

Can you please enable the write result to disk option in the settings of the sensor and post that result here?

Created on Nov 17, 2015 12:48:31 PM by  Greg Campion [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.