12.09.2018, 05:58
Here's a universal solution for reading from multiple SNMP peers. Create a resident script with sleep time > 0, adjust devices table as needed. You have to fully restart the script via enabled/disable when changing anything in devices table.
As for traps and SNMP v3 - we'll look into it later on.
Code:
if not devices then
require('snmp')
devices = {
{
ip = '192.168.1.1',
mapping = {
{ oid = '1.3.6.1.2.1.1.1.0', addr = '8/0/0' },
{ oid = '1.3.6.1.4.1.14988.1.1.1.3.1.4.6', addr = '8/0/1' },
}
},
{
ip = '192.168.1.4',
mapping = {
{ oid = '1.3.6.1.4.1.14988.1.1.3.8.0', addr = '8/0/0' },
{ oid = '1.3.6.1.4.1.14988.1.1.3.10.0', addr = '8/0/1' },
}
},
}
end
for _, dev in ipairs(devices) do
local conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
port = dev.port or 161,
peer = dev.ip,
})
if conn then
for _, map in ipairs(dev.mapping) do
local res, err = conn:get(map.oid)
if res and res.value ~= nil then
grp.checkwrite(map.addr, res.value)
else
alert('SNMP read from %s %s failed (%s)', dev.ip, map.oid, tostring(err))
end
end
conn:close()
else
alert('SNMP connection to %s failed (%s)', dev.ip, tostring(err))
end
end
As for traps and SNMP v3 - we'll look into it later on.