function snmpGet()
Jump to navigation
Jump to search
Execute SNMP GET call to given host and oid to read the response. The call is asynchronous: the code execution proceeds immediately and when the response arrives, callback function is called.
nil devices.system.snmpGet(table config)
Parameters
table config{host, oid, callback, snmpVersion,community, timeout}
- string
hosthost IP adress, may contain transport protocol and port (for example tcp:myhost.com:162) - string
oidobject identifier - function{response}
callbackthis function is called when response arrives - string
snmpVersionversion of SNMP (SNMP_VERSION.Snmp1 or SNMP_VERSION.Snmp2c) - string
communitySNMP community string - optional number
timeoutmaximum seconds to wait for response (default 30)
Callback Parameters
table response{result, errorInfo, oid, value}
- number
resulterror code of the response (0 is success) - string
errorInfoerror description (if result>0) - string
oidoid we got - string
valuevalue for the oid
Return value
nil
Usage
-- switch all outputs on NETIO with IP in 'host' parameter
local function snmpcallback(data)
if data.result == 0 then
output=tonumber(string.sub(data.oid, -1))
outputStatus=tonumber(data.value)
devices.system.SetOut{output=output, value=(outputStatus == 0)}
else
log(string.format("snmpget failed with error %d: %s", data.result, data.errorInfo))
end
end
for i = 1,4 do
snmpGet{host='10.0.0.102', timeout=6, oid=string.format(".1.3.6.1.4.1.47952.1.1.1.3.%d", i), snmpVersion=SNMP_VERSION.Snmp1, community='public', callback=snmpcallback}
end
Requirements
Netio FirmWare 3.3.0+