Knowledge Base

Using SNMP GET requests in a Custom Script Sensor

This article shows how you can use SNMP GET requests inside a script for a custom sensor.

Using the SNMPGET command you can request any OID of a device and process the results. Note: The IP adress is taken from the associated server of the current sensor.

Sample Code

' This sample IPCheck Custom Sensor Script reads the system uptime and does nothing serious with it... 
		'initialize sensor's result to status of "error"
		sensor.result_value=0
		'For Version 5.2 or earlier use: sensor.resultvalue=0
		sensor.status=srError
		sensor.errortype=etNone
		'get the snmp values (as string)
		'this OID gives us the system uptime, supported by most devices
		result=snmpget("public","1.3.6.1.2.1.1.3.0")
		'check for errors (always begins with the word "ERROR")
		if pos("ERROR",result)=1 then sensor.errorstring=result sensor.errortype=etprotocol
		else mynumber=strtoint(result) \'set result and status sensor.result_value=mynumber
		'For Version 5.2 or earlier use: sensor.resultvalue=mynumber \'set to error if result is < 10 if freememory < 10 then sensor.status=srError else sensor.status=srok end if
		end if