I created a VBS script that checks the state of a specific service. If the service is in a "running" state the script returns: "0: ok" If it's not running the script will return some other value. I tried having return "2: error" but that does not cause PRTG to show it as down, it just logs the result. The only way I can get the sensor to report the service as down is to not return a result, which throwns an error, but not one that is descriptive of the actual problem.
Here's the script:
strComputer = "servername" Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service where Name = 'servicename'",,48) For Each objItem in colItems If objItem.State = "Running" then Wscript.Echo "0: ok" Else 'Wscript.echo "2: error" End If Next
If the service isn't running I get this msg in PRTG:
"Last Message External EXE/Script did not return a response (code: PE087)"
How do I get this to throw a meaningful error in the case where the script returns a legal value like "2: error" ?
Thanks
EDITED: Added formatting for the script
Hi,
in order to set the script to error you will have return the correct exit codes. Based on these, the script will go into error state. Please find the supported exit codes below:
So please adjust your script to return the exit codes (when no exit code is returned explicitly it is always 0). Please find below an adjusted script (not tested):
Best regards
Dec, 2013 - Permalink