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
host
host IP adress, may contain transport protocol and port (for example tcp:myhost.com:162) - string
oid
object identifier - function{response}
callback
this function is called when response arrives - string
snmpVersion
version of SNMP (SNMP_VERSION.Snmp1 or SNMP_VERSION.Snmp2c) - string
community
SNMP community string - optional number
timeout
maximum seconds to wait for response (default 30)
Callback Parameters
table response{result
,errorInfo
,oid
,value
}
- number
result
error code of the response (0 is success) - string
errorInfo
error description (if result>0) - string
oid
oid we got - string
value
value 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+