Logic Machine Forum
SNMP v1/v2c trap support - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: SNMP v1/v2c trap support (/showthread.php?tid=2371)



SNMP v1/v2c trap support - admin - 28.11.2019

New package with trap support: https://dl.openrb.com/lm-19-imx6/pkg/luasnmp_1.0.6-2-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.
Code:
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



RE: SNMP v1/v2c trap support - Carlos Padilla - 30.11.2019

Thanks admin. We will be testing it. Thank you


RE: SNMP v1/v2c trap support - MarcusH - 20.02.2020

Hi,

Im trying to use snmp to get information from an APC PDU 88xx series, but i don't fully understand the lua scipts for this function.
Could some one help me with this?


RE: SNMP v1/v2c trap support - Daniel - 20.02.2020

Do you have anything in the logs?


RE: SNMP v1/v2c trap support - MarcusH - 20.02.2020

I've tried some things and then i only get errors, but thats because i don't understand the script above since im not sure what I need to edit to connect to the device. If i only copy the script nothing appears in the logs


RE: SNMP v1/v2c trap support - Daniel - 20.02.2020

From what I see the only thing you can change here is the UDP port.


RE: SNMP v1/v2c trap support - MarcusH - 20.02.2020

Okey, so as far as i understand, this script will continusly listen on the 162 port for information.
Then it might be the PDU setup that is wrong and not sending the info to the logicmachine correctly


RE: SNMP v1/v2c trap support - admin - 20.02.2020

This example is for SNMP traps (notifications). LM acts a server so you might need to adjust trap sending settings on your SNMP device.
What you probably need is to read/write data from SNMP device. See this thread for examples: https://forum.logicmachine.net/showthread.php?tid=1573