16.10.2018, 17:50
You can also try adding ups1:close() to the end of each resident script.
SNMP protocol in Logic Machine
|
16.10.2018, 17:50
You can also try adding ups1:close() to the end of each resident script.
02.11.2018, 19:31
Thanks for your collaboration, with the last thing that I indicated, the problem was solved and I no longer drop the connection.
09.04.2019, 18:29
Hi,
I have a problem with snmp conection. I have this script: Code: 123456789101112131415161718192021 require "snmp"
ups1, err = snmp.open{
version = snmp.SNMPv2,
community = "public",
port = 161,
peer = "192.168.2.201",
}
assert(ups1, err)
vbind, err = ups1:get(".1.3.6.1.4.1.24681.1.2.1.0") --Uso de la CP
grp.update('38/2/1', vbind.value)
vbind, err = ups1:get(".1.3.6.1.4.1.24681.1.2.2.0") --Memoria total del sistema
grp.update('38/2/2', vbind.value)
vbind, err = ups1:get(".1.3.6.1.4.1.24681.1.2.3.0") --Memoria libre
grp.update('38/2/3', vbind.value)
vbind, err = ups1:get(".1.3.6.1.4.1.24681.1.2.4.0") --Tiempo en linea
grp.update('38/2/4', vbind.value)
ups1.close()When I play resident script (5s) it work fine, but later, i get the following error: Resident script:18: netsnmp: Unknown host (192.168.2.201) stack traceback: [C]: in function 'assert' Can you help me? Thanks
11.04.2019, 09:08
Hi.
I have been loging data and I have created a script that restarts the snmp script when it fails, and it works again. I have verified that the snmp script fails exactly every 2.5h Any idea?
11.04.2019, 09:52
Your script is incorrect, it must have ups1:close() instead of ups1.close()
This caused open sessions not to close properly so the script hits open socket limit after some time.
17.06.2019, 06:59
Hi, my script still doesn´t work (only sometimes). I get the same error:
Resident script:45: netsnmp: Unknown host ("MyIP") stack traceback: [C]: in function 'assert' Code: 12345678910111213141516171819202122232425 require "snmp"
local IP_NAS = "MyIP"
local OID_NAS = {
{'38/2/1',".1.3.6.1.4.1.24681.1.2.1.0"}, --Uso de la CPU
{'38/2/2',".1.3.6.1.4.1.24681.1.2.2.0"}, --Memoria total del sistema
{'38/2/3',".1.3.6.1.4.1.24681.1.2.3.0"}, --Memoria libre
{'38/2/4',".1.3.6.1.4.1.24681.1.2.4.0"}, --Tiempo en linea
}
ups1, err = snmp.open{
version = snmp.SNMPv2,
community = "public",
port = 161,
peer = IP_NAS,
}
assert(ups1, err)
for i = 1, #OID_NAS, 1 do
vbind, err = ups1:get(OID_NAS[i][2])
grp.update(OID_NAS[i][1], vbind.value)
end
ups1:close()Any idea? Thanks
17.06.2019, 07:34
Change MyIP to real IP address of your SNMP device
MyIP =192.168.2.201
17.06.2019, 08:34
Post full listing of your script. The error that you have is at line 45 whereas the code you posted has only 25 lines.
17.06.2019, 09:29
Sorry, here full script:
Code: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 require "snmp"
--local mib,err = snmp.mib.load ('/home/ftp/snmp/....mib')
--[[
if not mib then
log ('Fallo carga Mib: '..err)
end]]
local IP_NAS = "192.168.2.201"
local OID_NAS = {
{'38/2/1',".1.3.6.1.4.1.24681.1.2.1.0"}, --Uso de la CPU
{'38/2/2',".1.3.6.1.4.1.24681.1.2.2.0"}, --Memoria total del sistema
{'38/2/3',".1.3.6.1.4.1.24681.1.2.3.0"}, --Memoria libre
{'38/2/4',".1.3.6.1.4.1.24681.1.2.4.0"}, --Tiempo en linea
{'38/2/5',".1.3.6.1.4.1.24681.1.2.11.1.3.1"}, --Temperatura HD 1
{'38/2/6',".1.3.6.1.4.1.24681.1.2.11.1.3.2"}, --Temperatura HD 2
{'38/2/7',".1.3.6.1.4.1.24681.1.2.11.1.3.3"}, --Temperatura HD 3
{'38/2/8',".1.3.6.1.4.1.24681.1.2.11.1.3.4"}, --Temperatura HD 4
{'38/2/9',".1.3.6.1.4.1.24681.1.2.11.1.4.1"}, --Estado del HD 1
{'38/2/10',".1.3.6.1.4.1.24681.1.2.11.1.4.2"}, --Estado del HD 2
{'38/2/11',".1.3.6.1.4.1.24681.1.2.11.1.4.3"}, --Estado del HD 3
{'38/2/12',".1.3.6.1.4.1.24681.1.2.11.1.4.4"}, --Estado del HD 4
{'38/2/13',".1.3.6.1.4.1.24681.1.2.11.1.6.1"}, --Capacidad Disco duro 1
{'38/2/14',".1.3.6.1.4.1.24681.1.2.11.1.6.2"}, --Capacidad Disco duro 2
{'38/2/15',".1.3.6.1.4.1.24681.1.2.11.1.6.3"}, --Capacidad Disco duro 3
{'38/2/16',".1.3.6.1.4.1.24681.1.2.11.1.6.4"}, --Capacidad Disco duro 4
{'38/2/17',".1.3.6.1.4.1.24681.1.2.11.1.7.1"}, --Smart Info HD 1
{'38/2/18',".1.3.6.1.4.1.24681.1.2.11.1.7.2"}, --Smart Info HD 2
{'38/2/19',".1.3.6.1.4.1.24681.1.2.11.1.7.3"}, --Smart Info HD 3
{'38/2/20',".1.3.6.1.4.1.24681.1.2.11.1.7.4"}, --Smart Info HD 4
{'38/2/21',".1.3.6.1.4.1.24681.1.2.13.0"}, --Hostname
{'38/2/22',".1.3.6.1.4.1.24681.1.2.17.1.2.1"}, --Descripcion del Volumen
{'38/2/23',".1.3.6.1.4.1.24681.1.2.17.1.4.1"}, --Capacidad total del volumen
{'38/2/24',".1.3.6.1.4.1.24681.1.2.17.1.5.1"}, --Espacio Libre Volumen
{'38/2/25',".1.3.6.1.4.1.24681.1.2.17.1.6"}, --Estado del volumen
}
ups1, err = snmp.open{
version = snmp.SNMPv2,
community = "public",
port = 161,
peer = IP_NAS,
}
assert(ups1, err)
for i = 1, #OID_NAS, 1 do
vbind, err = ups1:get(OID_NAS[i][2])
grp.update(OID_NAS[i][1], vbind.value)
end
ups1:close()
Hi,
Here another error that give me many times: From 17:30 to 8:35AM last time. Now works again. Resident script:49: attempt to index global 'vbind' (a nil value) stack traceback:
18.06.2019, 08:05
This happens because there's no error check for get() calls.
Use this code: Code: 12345678 for _, item in ipairs(OID_NAS) do
vbind, err = ups1:get(item[2])
if vbind then
grp.update(item[1], vbind.value)
else
alert('error reading from snmp: ' .. tostring(err))
end
end
18.06.2019, 10:00
(18.06.2019, 08:05)admin Wrote: This happens because there's no error check for get() calls. Ok, I´ll try it. Thanks!!
10.07.2019, 21:07
Hello forum partners. Now I have two devices. The first is a projector which has an SNMP communication and I want to turn on and off, change the video input for which I have to write a value in the respective OIDs. I tested the projector both by writing and reading the SNMP variables by means of an SNMP management software and it works without any problem, but with the LM I have made a script by event to turn it on, but it does not work for me. On the other hand I have a team that uses SNMP Version 3 which replaces the community by user name, an authentication code, a privacy code and the protocol of these (MD5, SHA, DES, AES) which is not compatible with the current code, in addition to having some Tramps which I have to be aware of and I do not know how to do it, so if they have any way of doing it, it would be very helpful. I include the code I did to write about an SNMP OID, which does not work for me. Thank you and I am attentive to your comments.
Code: 1234567891011121314151617181920212223 val=event.getvalue()
--Abrir una sesión con snmp
require "snmp"
ups1, err = snmp.open{
version = snmp.SNMPv1,
community = "public",
port = 161,
peer = "192.168.0.243",
}
assert(ups1, err)
if value==true then
vbind, err = ups1:set("1.3.6.1.4.1.1248.4.1.1.2.1.0", 1)
else
vbind, err = ups1:set("1.3.6.1.4.1.1248.4.1.1.2.1.0", 0)
end
ups1:close()
11.07.2019, 08:48
See library documentation on how to correctly call set function: http://luasnmp.luaforge.net/snmp.html#snmp_set
I haven't tried using SNMPv3, but you can try this code: Code: 1234567 ups1, err = snmp.open({
port = 161,
peer = "192.168.0.243",
version = snmp.SNMPv3,
user = "username",
password = "123456",
})SNMP traps are not supported at this moment.
11.07.2019, 22:13
Hi Admin, thanks for replying. With the help of the library manual I understand the script a bit more, in addition to the version 3 SNMP, and then I will try to try the version with what the manual says. The problem I have is to write to an OID, I have already tried many things but it still does not work, I have even commented, tried several parts of the code but it still does not work. I put it together to see if I'm wrong about something. Thank you and I am attentive to your comments
Code: 12345678910111213141516171819202122232425262728293031323334353637383940414243 val=event.getvalue()
--Abrir una sesión con snmp
require "snmp"
--value=1
ups1, err = snmp.open{
version = snmp.SNMPv1,
community = "public",
port = 161,
peer = "192.168.0.248",
}
assert(ups1, err)
vbOut, err = ups1:set("1.3.6.1.4.1.1248.4.1.1.2.1.0", 0)
--vlist = {
--{oid = "1.3.6.1.4.1.1248.4.1.1.2.1.0", 0}
--}
--vbind = {
--{oid = "1.3.6.1.4.1.1248.4.1.1.2.1.0", type = TYPE_INTEGER32, value = "0"}
--}
--vbOut, err = ups1:set(vbIn)
--vbOut, err = ups1:set(vbind)
log(vbind)
log(err)
log(index)
--assert(vbOut, err)
--if value==true then
--vbind, err = ups1:set("1.3.6.1.4.1.1248.4.1.1.2.1.0", 1)
--else
--vbind, err = ups1:set("1.3.6.1.4.1.1248.4.1.1.2.1.0", 0)
--end
ups1:close()
12.07.2019, 06:15
Here's an example script that sets identity on Mikrotik router via SNMP. You can modify it for your device. Resulting status or error will be visible in Alerts tab.
Code: 1234567891011121314151617181920212223242526 require('snmp')
conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
peer = '192.168.1.1',
})
if conn then
res, err = conn:set({
{
oid = '1.3.6.1.2.1.1.5.0',
value = 'New_Identity',
}
})
if err then
alert('snmp set failed: ' .. tostring(err))
else
alert('snmp set ok')
end
conn:close()
else
alert('snmp connection failed: ' .. tostring(err))
end
12.07.2019, 15:33
Hi Admin, thanks for replying. Use the code you told me, but it's not working. I have attached the code adapted to my OID and my IP together with an error log. I have made several modifications but none of them work for me. Thank you and I am attentive to your comments.
Code: 1234567891011121314151617181920212223242526272829303132 val=event.getvalue()
--Abrir una sesión con snmp
require('snmp')
conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
peer = '192.168.1.248',
})
if conn then
res, err = conn:set({
{
oid = '1.3.6.1.4.1.1248.4.1.1.2.1.0',
value = '0',
}
})
if err then
alert('snmp set failed: ' .. tostring(err))
log (err)
log ('snmp set failed')
else
alert('snmp set ok')
log ('snmp set ok')
end
conn:close()
else
alert('snmp connection failed: ' .. tostring(err))
log ('snmp connection failed')
endEvent for ON/OFF_PROYECTOR (0/1/0) 12.07.2019 09:47:23 * string: snmp: bad type (2) prim=0 in index 1 Event for ON/OFF_PROYECTOR (0/1/0) 12.07.2019 09:47:23 * string: snmp set failed I have the library libnetsnmp 5.4.4-1 luasnmp 1.0.6-2-2
13.07.2019, 15:12
(This post was last modified: 13.07.2019, 15:17 by Carlos Padilla.)
Hi, I share with you the script by event that works to turn an EPSON projector on and off using snmp.
Code: 12345678910111213141516171819202122232425262728293031 val=event.getvalue()
require('snmp')
conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
peer = '192.168.0.248',
})
assert(conn, err)
if val==true then
vbIn = {
{oid = "1.3.6.1.4.1.1248.4.1.1.2.1.0", type=snmp.TYPE_INTEGER, value = "1"}
}
vbOut, err, index = conn:set(vbIn)
else
vbIn = {
{oid = "1.3.6.1.4.1.1248.4.1.1.2.1.0", type=snmp.TYPE_INTEGER, value = "0"}
}
vbOut, err, index = conn:set(vbIn)
end
conn:close() |
« Next Oldest | Next Newest »
|