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
Add comment