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

custom VBS script doesn't trigger a Down state

Votes:

0

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

custom-script-exe custom-sensor prtg vbscript

Created on Dec 4, 2013 4:37:07 PM

Last change on Mar 19, 2015 3:50:31 PM by  Martina Wittmann [Paessler Support]



1 Reply

Votes:

0

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:

ValueDescription
0OK
1WARNING
2System Error (e.g. a network/socket error)
3Protocol Error (e.g. web server returns a 404)
4Content Error (e.g. a web page does not contain a required word)

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):

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"
                Wscript.Quit 0
	Else
		'Wscript.echo "2: error"
                 Wscript.Quit 2
	End If	
Next

Best regards

Created on Dec 5, 2013 5:53:30 AM by  Konstantin Wolff [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.