28.11.2019, 10:33
New package with trap support: https://dl.openrb.com/lm-19-imx6/pkg/lua...4_imx6.ipk
Resident script (0 second sleep time). It binds to UDP port 162 and listens to incoming messages then parses them. snmp.parsetrap returns community name (string) and variable list (table) on success, nil plus error message otherwise.
Resident script (0 second sleep time). It binds to UDP port 162 and listens to incoming messages then parses them. snmp.parsetrap returns community name (string) and variable list (table) on success, nil plus error message otherwise.
Code:
12345678910111213141516171819202122232425
if not sock then
snmp = require('snmp')
socket = require('socket')
-- create UDP socket, listen on port 162
sock = socket.udp()
sock:setsockname('*', 162)
sock:settimeout(1)
end
data, ip, port = sock:receivefrom()
-- incoming message
if data then
-- parse message
commres, vberr = snmp.parsetrap(data)
-- valid message
if commres then
log(ip, commres, vberr)
-- parse failed, see logs for more info
else
log('error', vberr)
end
end