I have a very simple powershell script. In a function is some logic and the return value of the function should be the exit code for the script. For the result 0 and 1 (ok and warning) the script works well, but if the function returns 2 (Error) I get no result in PRTG. The returned message is shown as "2 :2 RL disabled!" and the last value is empty! What is the reason for this behaviour? I hope it is reproducable for you.
The script:
[int]$retvalue = 0
[string]$retmsg = "Dummy"
function TestFunction()
{
[int]$myretvalue=0
$retmsg=""
$countDisabled=2
#... here comes some logic ...
if($countDisabled -eq 0) {
$script:retmsg = "All enabled"
$myretvalue = 0
}
else {
$script:retmsg = ("{0} RL disabled") -f $countDisabled
$myretvalue = 2 # 0 or 1 works, 2 not!
}
return $myretvalue
}
$retvalue=TestFunction
$output = ("{0} :{1}") -f $retvalue,$retmsg
Write-Host $output
exit $retvalue
Article Comments
Or as an alternative, if you need that values, try to modify you scrip so it can be used as an exexml sensortype:
So add this to your Script, before the exit command:
$CHANNELNAME= "name your channel" "<prtg>" "<result>" "<channel>" "$CHANNELNAME" "</channel>" "<value>" "$retvalue" "</value>" "</result>" "</prtg>"
and replace "exit $retvalue" by "exit 0"
Finally, after you have the sensor working in prtg, let prtg make the decision how to deal with the channel value (config in sensors channeltab).
Nov, 2011 - Permalink
By design, PRTG does not accept values from sensors in a Down status. This is because a down status is considered a major outage and no values are expected in such a case.
If you still want to receive values in your custom sensor, please do not use the return value 2.
Oct, 2011 - Permalink