This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

SNMP protocol in Logic Machine
#1
Good morning, the following message is to tell you that I have a monitor and manage the traps of several UPS and PDU that use the SNMP protocol. I read that with the logic Machine I can do this, but I can not find information about it, if I need some packages, if everything has to be done with Script or has menus like Modbus or other protocols. In addition to the above if I can monitor and also receive the traps of them, because going in a forum here, said that you could not receive traps, but I do not know if with the new version of the lite power firmware (20180822) if can do. Thanks and any information that you can give me, it would be very useful.
Reply
#2
(03.09.2018, 13:30)Carlos Padilla Wrote: Good morning, the following message is to tell you that I have a monitor and manage the traps of several UPS and PDU that use the SNMP protocol. I read that with the logic Machine I can do this, but I can not find information about it, if I need some packages, if everything has to be done with Script or has menus like Modbus or other protocols. In addition to the above if I can monitor and also receive the traps of them, because going in a forum here, said that you could not receive traps, but I do not know if with the new version of the lite power firmware (20180822) if can do. Thanks and any information that you can give me, it would be very useful.

Hi, as I know, traps are still not supported
You need packages  luasnmp and libnetsnmp
you can download it for imx28 here https://dl.openrb.com/lm-17/pkg
for imx6 here https://dl.openrb.com/lm-17-imx6/pkg/

and here is example script
Code:
-- открытие сессии с snmp
require "snmp"

-- загрузка миб-файла для ибп
local mib, err = snmp.mib.load('/home/ftp/snmp/GESINGLEUPS.mib')
if not mib then
  log('Failed to load mib: ' .. err)
end

-- подклчюение к ибп
ups1, err = snmp.open{
 version = snmp.SNMPv1,
 community = "public",
 port = 161,
 peer = "10.100.3.21",
}
assert(ups1, err)

-- читаем температуру
vbind, err = ups1:get("upsBatteryTemperaturegen")
grp.write('1/1/7', vbind.value)

-- читаем нагрузку в % по фазам на выходе
vbind, err = ups1:get("upsOutputPercentLoadgen.1")
grp.write('1/1/8', vbind.value)
vbind, err = ups1:get("upsOutputPercentLoadgen.2")
grp.write('1/1/9', vbind.value)
vbind, err = ups1:get("upsOutputPercentLoadgen.3")
grp.write('1/1/10', vbind.value)
Reply
#3
Hi,

This sample is a client, can we also use it as server?

BR,

Erwin
Reply
#4
(04.09.2018, 14:10)Erwin van der Zwart Wrote: Hi,

This sample is a client, can we also use it as server?

BR,

Erwin

Hi Erwin!
Better ask Admin, he implemented this solution
Reply
#5
Trap server can implemented but it's not straightforward because of extra configuration that is required.
Reply
#6
(06.09.2018, 07:57)admin Wrote: Trap server can implemented but it's not straightforward because of extra configuration that is required.

It does not matter if it is difficult, I would like to try to implement it. What makes it difficult? Thanks for answering. On the other hand, I observe in the example that was passed to me, there is a path ('/home/ftp/snmp/GESINGLEUPS.mib') where the MIB file is located, but the path looks like a computer or terminal linux or Is it a file that can be uploaded to the logic machine?
Reply
#7
Files can be uploaded via ftp which can be enabled in System config. Using SNMP traps is difficult because it requires several separate software pieces to work - one to handle trap communication and another to decode trap messages.
Reply
#8
Thank you for responding, I was able to upload a file to you via ftp with the help of winscp, as you can see in the images that I will show you. I am testing the SNMP communication with a Mikrotik router with the resident function of the example that AEK shows me, but it does not work for me. In the log I see that the message appears:

SNMP Mikrotik 10.09.2018 17:09:25
* string: Failed to load mib: mib: can not add mib

The script I use is the following:


Code:
--Abrir una sesión con snmp
require "snmp"

local mib, err = snmp.mib.load('/home/ftp/snmp/Mikrotik.mib')
if not mib then
  log('Failed to load mib: ' .. err)
end


ups1, err = snmp.open{
 version = snmp.SNMPv1,
 community = "ZennioCo",
 port = 161,
 peer = "192.168.0.191",
}
assert(ups1, err)

--Lee los OID del Mib
vbind, err = ups1:get("mtxrHlVoltage")
grp.write('8/0/0', vbind.value)
vbind, err = ups1:get("mtxrHlTemperature")
grp.write('8/0/1', vbind.value)

It should be noted that when configuring the ftp server of the logic machine only had username ftp and apps and in both mount the MIB but none worked and even mount the folder as is the example route ('/ home / ftp / snmp /*.*) since when I accessed the user I only showed "/" and apps (the daemon, daemon, data, lib and user folders), but the reading of the file does not work for me. In addition to the above, also install the 2 SNMP packets that I commented and that are necessary for the SNMP part to work. Thank you and I will be attentive to your comments.

Attached Files Thumbnail(s)
   
Reply
#9
ftp root directory is /home/ftp, you don't have to create full path there, just create snmp directory and upload mib file there. From my experience Mikrotik mib file does not work at all, at least with RB951G that we use for testing. You have to use oid instead of mibs. You can find out oids by going to Mikrotik console and running "print oid" command in a specific section, for example "/system health".
Reply
#10
(11.09.2018, 06:41)admin Wrote: ftp root directory is /home/ftp, you don't have to create full path there, just create snmp directory and upload mib file there. From my experience Mikrotik mib file does not work at all, at least with RB951G that we use for testing. You have to use oid instead of mibs. You can find out oids by going to Mikrotik console and running "print oid" command in a specific section, for example "/system health".
same thing on hAP AC Light
Reply
#11
Okay. Thank you for your cooperation. Effectively change the final name of the route to the one of the OID and it is working for me, in the group addresses the requested OIDs are being written. It is important to clarify that despite the fact that the file is loading, I still get the message:

SNMP Mikrotik 11.09.2018 10:06:57
* string: Failed to load mib: mib: can not add mib

The only way that this message does not appear is to put in comments the part of the code that requests the file loaded by ftp. Based on the above, would the SNMP communication serve me without having to load the MIB file?, Only loading the 2 necessary libraries and making the script so that the information that the OIDs have is written in the group addresses. On the other hand, I currently have 40 OID per ups and are in total 4 ups that I must monitor the variables, to avoid problems, I can place the first Script to make requests every 2 seconds, the second script every 3 seconds, the third script at 5 and 7 respectively to avoid communication problems or I can place all the scripts to run every 2 seconds and I would not have problems with the communication and acquisition of the information.

I attach the code that works for me at the moment:

Code:
--Abrir una sesión con snmp
require "snmp"

--local mib, err = snmp.mib.load('/home/ftp/snmp/Mikrotik.mib')
--if not mib then
  --log('Failed to load mib: ' .. err)
--end


ups1, err = snmp.open{
 version = snmp.SNMPv1,
 community = "ZennioCo",
 port = 161,
 peer = "192.168.0.192",
}
assert(ups1, err)

--Lee los OID del Mib
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.3.8.0")
grp.write('8/0/0', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.3.10.0")
grp.write('8/0/1', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.1.3.1.9.16.0")
grp.write('8/0/2', vbind.value)

On the other hand, admin, if I want to implement the traps, you have information or the form of how to do it, what to do, some example or a base to start. For these UPS, it is not necessary the traps but in other devices if they are and I would like to have a complete solution with the logic machine. Thank you and I will be attentive to your comments.
Reply
#12
(11.09.2018, 16:19)Carlos Padilla Wrote: Okay. Thank you for your cooperation. Effectively change the final name of the route to the one of the OID and it is working for me, in the group addresses the requested OIDs are being written. It is important to clarify that despite the fact that the file is loading, I still get the message:

SNMP Mikrotik 11.09.2018 10:06:57
* string: Failed to load mib: mib: can not add mib

The only way that this message does not appear is to put in comments the part of the code that requests the file loaded by ftp. Based on the above, would the SNMP communication serve me without having to load the MIB file?, Only loading the 2 necessary libraries and making the script so that the information that the OIDs have is written in the group addresses. On the other hand, I currently have 40 OID per ups and are in total 4 ups that I must monitor the variables, to avoid problems, I can place the first Script to make requests every 2 seconds, the second script every 3 seconds, the third script at 5 and 7 respectively to avoid communication problems or I can place all the scripts to run every 2 seconds and I would not have problems with the communication and acquisition of the information.

I attach the code that works for me at the moment:

Code:
--Abrir una sesión con snmp
require "snmp"

--local mib, err = snmp.mib.load('/home/ftp/snmp/Mikrotik.mib')
--if not mib then
  --log('Failed to load mib: ' .. err)
--end


ups1, err = snmp.open{
 version = snmp.SNMPv1,
 community = "ZennioCo",
 port = 161,
 peer = "192.168.0.192",
}
assert(ups1, err)

--Lee los OID del Mib
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.3.8.0")
grp.write('8/0/0', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.3.10.0")
grp.write('8/0/1', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.14988.1.1.1.3.1.9.16.0")
grp.write('8/0/2', vbind.value)

On the other hand, admin, if I want to implement the traps, you have information or the form of how to do it, what to do, some example or a base to start. For these UPS, it is not necessary the traps but in other devices if they are and I would like to have a complete solution with the logic machine. Thank you and I will be attentive to your comments.

Ready, I respond to one of the previous questions, it is only necessary that the 2 packages are downloaded and installed, the resident script is set to run and the ip and the community are well configured, the communication will work. I even try changing from v1 to v2 of SNMP and it works for me without any problem. My doubt in the code is that if I want to write in an OID, some teams ask for a community of reading and writing, it is necessary to configure the same name for both communities in the team or in the script I can indicate the writing community, What name does the variable receive ?. On the other hand if I want to make the communication using SNMP Version 3, it is necessary to use a user name, an authentication code, a privacy code and the protocol of these (MD5, SHA, DES, AES). Where and with what name do I specify the above in the resident code?

Thank you for your cooperation.
Reply
#13
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.

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.
Reply
#14
Great job guys, I follow you with interest and I look forward to new developments!
Reply
#15
Okay. Thank you very much for your collaboration admin and I will be waiting for when you can tell us about the use of traps and also with the V3 of the SNMP protocol. For now with the information and the previous script, I could solve. Thank you very much.
Reply
#16
Good guys, I told them that I have a problem with the request of the OID information of the UPS and that the code works for me, but after several hours, the code stops working and I have to disable and enable the resident function again so that the data can be updated, but after several hours again I can not obtain the values. I look at the error log and the following appears:

Resident script: 16: netsnmp: Unknown host (192.168.0.114) stack traceback: [C]: in function 'assert'
Resident script: 16: netsnmp: Unknown host (192.168.0.111) stack traceback:
  [C]: in function 'assert'

The code is the following:

Code:
--Abrir una sesión con snmp
require "snmp"

local mib, err = snmp.mib.load('/home/ftp/snmp/Mikrotik.mib')
if not mib then
  log('Failed to load mib: ' .. err)
end


ups1, err = snmp.open{
 version = snmp.SNMPv1,
 community = "tekneoCO",
 port = 161,
 peer = "192.168.0.111",
}
assert(ups1, err)

--Lee los OID del Mib
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.2.1.1.0")
grp.write('8/0/0', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.2.2.5.0")
grp.write('8/0/1', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.4.1.1.0")
grp.write('8/0/2', vbind.value)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.2.5.0")
grp.write('8/0/50', vbind.value)
os.sleep(2)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.2.4.0")
grp.write('8/0/7', vbind.value)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.2.3.0")
grp.write('8/0/8', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.2.2.3.0")
grp.write('8/0/51', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.3.2.4.0")
grp.write('8/0/52', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.3.2.1.0")
grp.write('8/0/53', vbind.value)
os.sleep(2)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.4.2.2.0")
grp.write('8/0/54', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.4.2.1.0")
grp.write('8/0/55', vbind.value)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.4.4.1.5.1")
grp.write('8/0/19', vbind.value)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.5.1.0")
grp.write('8/0/56', vbind.value)
vbind, err = ups1:get("1.3.6.1.2.1.33.1.5.3.1.2.1")
grp.write('8/0/23', vbind.value)
os.sleep(2)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.5.1.0")
grp.write('8/0/26', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.5.7.0")
grp.write('8/0/27', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.6.2.0")
grp.write('8/0/28', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.6.3.0")
grp.write('8/0/29', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.6.4.0")
grp.write('8/0/30', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.5.0")
grp.write('8/0/31', vbind.value)
os.sleep(2)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.1.0")
grp.write('8/0/32', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.4.0")
grp.write('8/0/33', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.5.0")
grp.write('8/0/34', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.6.0")
grp.write('8/0/35', vbind.value)
vbind, err = ups1:get("1.3.6.1.4.1.935.1.1.1.8.7.7.0")
grp.write('8/0/36', vbind.value)
I must clarify that I have the UPS are connected to the network, the connection has not fallen and I have installed the two necessary SNMP packages and I do not have any MIB file (either Mikrotik or UPS) loaded, since the UPS that I am using does not they have a single MIB file, since one information is given to me by a MIB that I found and another one is given to me by another MIB and I did not use the code that the admin indicated after, because the current one seemed more comfortable to edit, besides that I had it done. Currently I ask the variables to 4 UPS, the first question is by resident code at 20 seconds, the second at 30 seconds, 40 and 50 seconds respectively. Thank you and I will be attentive to your comments.
Reply
#17
This means that LM cannot connect to certain devices. Check if you can ping devices from LM (System Config > Status > Network Utilities).
Reply
#18
If, as I said, the devices are connected to the network and have communication, but as the hours pass, the updates of the variables are no longer received and the message of:

Resident script: 16: netsnmp: Unknown host (192.168.0.111) stack traceback: [C]: in function 'assert'

The message told me that the communication was lost, but I could access the UPS and verify that it was working normally.

As I was saying, I had to disable and enable the script so that the reading of variables works again.

This is a ping that I made to the UPS
PING 192.168.0.111 (192.168.0.111): 56 data bytes
64 bytes from 192.168.0.111: seq = 0 ttl = 64 time = 1.401 ms
64 bytes from 192.168.0.111: seq = 1 ttl = 64 time = 0.623 ms
64 bytes from 192.168.0.111: seq = 2 ttl = 64 time = 0.721 ms
64 bytes from 192.168.0.111: seq = 3 ttl = 64 time = 0.638 ms

--- 192.168.0.111 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min / avg / max = 0.623 / 0.845 / 1.401 ms

On the other hand, even though I have a MIB file loaded, I get this error:
* string: Failed to load mib: mib: can not add mib

But even so, the variables are updated, only after several hours, the information is no longer updated.
Reply
#19
This can be caused by not properly closed connections. A quick solution is to use a scheduled script which runs every minute instead of a resident script.
Reply
#20
Thanks admin for answering and the script, although it would be scheduled, would have the effect that the connection does not close properly? Because in the end it has the same effects, I mean to ask every so often, in my case every 20, 30, 40 and 50 seconds respectively. In my case I have 4 UPS, so that would be 4 script scheduled, each in the minute option would be / * 1 for the first script, for the second / * 2, the third / * 3 and so respectively. An admin question and if in the script the connection is closed at the end, would it be better? Or it is better to use the second example that you placed, which I have no problem doing after the problem is solved. Thanks and I will be attentive to your comments, by the way it happened again that the scrip stopped working, so I sent a ping from the LM to the host and I had a response from him. I attach some images of it.

Attached Files Thumbnail(s)
           
Reply


Forum Jump: