What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom EXE/script sensor always shows Up

Votes:

0

Your Vote:

Up

Down

I tried to create a simple PowerShell script to monitor my Hyper-V cluster. The script works if I run it manually on the PRTG server but for some reason the sensor status is always Up. What could be the problem?

$Nodes = Get-ClusterNode -Cluster HVCluster01
$Interfaces = Get-ClusterNetworkInterface -Cluster HVCluster01
$NodeStatus = $null
$InterfaceStatus = $null

ForEach ($Node in $Nodes) {
    $NodeState = $Node.State
    If ($NodeState -ne "Up") {
        $NodeStatus = "Down"
    }
    Else {}
}

ForEach ($Interface in $Interfaces) {
    $InterfaceState = $Interface.State
    If ($InterfaceState -ne "Up") {
        $InterfaceStatus = "Down"
    }
    Else {}
}

If ($NodeStatus -eq "Down" -or $InterfaceStatus -eq "Down") {
    Write-Host "Status:Down"
    exit 2
}
Else {
    Write-Host "Status:Ok"
    exit 0
}
}

custom-sensor exe-script-sensor powershell prtg

Created on Mar 30, 2021 1:22:12 PM by  MikaPesonen (0) 1

Last change on Mar 31, 2021 11:01:42 AM by  Florian Lesage [Paessler Support]



4 Replies

Votes:

0

Your Vote:

Up

Down

Hello Mika,

Thank you for your message.

Regarding your script, can you please tell me what you would like to achieve exactly? Do you want to have a channel for each node / interface with their corresponding state?

If that's the case, then you have to return a JSON to PRTG, which follows the structure indicated this manual: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

For each channel, you must add a result object such as the following:

<result>
           <channel>Node name</channel>
           <value>Node status (must be converted to 0 or 1)</value>
           <valuelookup>YourCustomLookup</valuelookup>
</result>
<result>
           <channel>Interface name</channel>
           <value>Interface status (must be converted to 0 or 1)</value>
           <valuelookup>YourCustomLookup</valuelookup>
</result>

Then, in PRTG you can use a custom lookup to display the status UP or DOWN based on the value returned.

If you have questions, let us know.

Regards.

Created on Mar 31, 2021 11:15:13 AM by  Florian Lesage [Paessler Support]

Last change on Mar 31, 2021 11:15:32 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

The plan was that the script will simply just give output OK (exit code 0) if every ClusterNode and ClusterNetworkInterface are in Up state. And if any of those are in different state then the script will return exit code 2.

Created on Mar 31, 2021 11:24:44 AM by  MikaPesonen (0) 1



Votes:

0

Your Vote:

Up

Down

Thank you for the clarification.

In this case, I would recommend to use the variables $NodeStatus and $InterfaceStatus as arrays, and add the value of each loop in the lists by using += instead of assigning the latest value.

For example, you can use this piece of code to add the value in the array, and by the same occasion, remove the variable $NodeState (same thing for the interface status):

$NodeStatus += $Node.State

Then, at the end of the script, simply check if the list contains the state DOWN an return the according result in PRTG.

Regards.

Created on Mar 31, 2021 12:04:28 PM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello Mika,

Thank you for your feedback.

Regarding PowerShell 64bit, I invite you to have a look to the application PSx64 from PRTG Tools Family as well as the Knowledge base article regarding this matter, such as https://kb.paessler.com/en/topic/15043-force-64-bit-powershell

Regards.

Created on Apr 1, 2021 6:31:26 AM by  Florian Lesage [Paessler Support]



Please log in or register to enter your reply.


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.