I would like to use a LogicMachine as a new "probe" in the network.
The NetWork Management System of a building needs to read some info from the state of the instalation managed by the LogicMachine.
I need to implement this two issues:
1-. Create an accesible MIB within the LogicMAchine with a table of OIDs with the alerts and Info that will be monitorized over SNMP.
2-. Be able to send TRAPS to the IP of the SNMP Manager
I've been looking for info in this forum and it looks like there is a manual or info in http://luasnmp.luaforge.net/
This link is no longer avalable.
So my Question is: "Is It possible to achive this 2 issues with a LogicMAchine and LUAScripting? ... and if so ... Is There a manual or example to start with?"
2. Create a resident script with sleep time set to 5. Edit conf variable as needed. In this example remote host is 192.168.1.230, base OID is .1.3.6.1.4.1.53864.1.1
Note that disabling the script does not stop the snmp daemon.
Code:
local conf = [[
rocommunity public 192.168.1.230
rwcommunity private 192.168.1.230
3. Create user library named "snmphandler". Edit the oids table and supply required oids and group address pairs. Base OID must match the configured OID in the snmpd conf. Make sure that all mapped group addresses exist.
Code:
local oids = {
{ oid = '.1.3.6.1.4.1.53864.1.1.1.0', addr = '1/1/1' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.2.1', addr = '1/1/2' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.3.1', addr = '1/1/4' },
{ oid = '.1.3.6.1.4.1.53864.1.1.3.0', addr = '1/1/5' },
{ oid = '.1.3.6.1.4.1.53864.1.1.4.0', addr = '1/1/6' },
{ oid = '.1.3.6.1.4.1.53864.1.1.5.0', addr = '1/1/7' },
{ oid = '.1.3.6.1.4.1.53864.1.1.6.0', addr = '1/1/8' },
}
require('genohm-scada')
db = require('dbenv').new()
local req, oid = assert(arg[ 1 ]), assert(arg[ 2 ])
local function get(item)
if not item then
return
end
local obj = grp.find(item.addr)
if not obj then
return
end
local value = obj.value
local objtype = 'integer'
if type(value) == 'boolean' then
value = value and 1 or 0
elseif type(value) == 'number' then
value = math.round(value)
elseif type(value) ~= 'string' then
value = require('json').encode(value)
end
print(item.oid)
print(type(value) == 'number' and 'integer' or 'string')
print(value)
end
-- get
if req == '-g' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(item)
break
end
end
-- next
elseif req == '-n' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(oids[ i + 1 ])
break
elseif item.oid:find(oid, 1, true) == 1 then
get(item)
break
end
end
-- set
elseif req == '-s' then
local objtype, value = assert(arg[ 3 ]), assert(arg[ 4 ])
if objtype ~= 'string' then
value = tonumber(value)
end
for i, item in ipairs(oids) do
if item.oid == oid then
grp.write(item.addr, value)
end
end
end
I already checked this thread, but in this case the issue is about the LogicMachine "asking" and "dealing" with an SNMP Probe (agent) trhough an IP.
In fact, in the same thread Erwin aks about the same issue:
qoute: "This sample is a client, can we also use it as server?"
I tried to follow the thread to find out the solution ... but with no success! unless the universal solution provided by the Admin user works also as the own MIB!!
I need that solution but with inverse sense of comunication X)
Thanks!!!
(23.03.2022, 10:09)admin Wrote: Sending traps is not implemented at the moment. SNMP agent (experimental) can be executed via a script. It allows mapping objects to OIDs.
2. Create a resident script with sleep time set to 5. Edit conf variable as needed. In this example remote host is 192.168.1.230, base OID is .1.3.6.1.4.1.53864.1.1
Note that disabling the script does not stop the snmp daemon.
Code:
local conf = [[
rocommunity public 192.168.1.230
rwcommunity private 192.168.1.230
3. Create user library named "snmphandler". Edit the oids table and supply required oids and group address pairs. Base OID must match the configured OID in the snmpd conf. Make sure that all mapped group addresses exist.
Code:
local oids = {
{ oid = '.1.3.6.1.4.1.53864.1.1.1.0', addr = '1/1/1' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.2.1', addr = '1/1/2' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.3.1', addr = '1/1/4' },
{ oid = '.1.3.6.1.4.1.53864.1.1.3.0', addr = '1/1/5' },
{ oid = '.1.3.6.1.4.1.53864.1.1.4.0', addr = '1/1/6' },
{ oid = '.1.3.6.1.4.1.53864.1.1.5.0', addr = '1/1/7' },
{ oid = '.1.3.6.1.4.1.53864.1.1.6.0', addr = '1/1/8' },
}
require('genohm-scada')
db = require('dbenv').new()
local req, oid = assert(arg[ 1 ]), assert(arg[ 2 ])
local function get(item)
if not item then
return
end
local obj = grp.find(item.addr)
if not obj then
return
end
local value = obj.value
local objtype = 'integer'
if type(value) == 'boolean' then
value = value and 1 or 0
elseif type(value) == 'number' then
value = math.round(value)
elseif type(value) ~= 'string' then
value = require('json').encode(value)
end
print(item.oid)
print(type(value) == 'number' and 'integer' or 'string')
print(value)
end
-- get
if req == '-g' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(item)
break
end
end
-- next
elseif req == '-n' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(oids[ i + 1 ])
break
elseif item.oid:find(oid, 1, true) == 1 then
get(item)
break
end
end
-- set
elseif req == '-s' then
local objtype, value = assert(arg[ 3 ]), assert(arg[ 4 ])
if objtype ~= 'string' then
value = tonumber(value)
end
for i, item in ipairs(oids) do
if item.oid == oid then
grp.write(item.addr, value)
end
end
end
Thanks!!! I will try this solucion! thank you for the quick answer!!
23.03.2022, 12:52 (This post was last modified: 23.03.2022, 12:53 by kike.)
It's working!!One more question: with this example it allow querys from one single IP. Is there a setting that allows querys from any ip inthe LAN?This is already OK to me! but I would like to know!Thank you again!!
(23.03.2022, 10:09)admin Wrote: Sending traps is not implemented at the moment. SNMP agent (experimental) can be executed via a script. It allows mapping objects to OIDs.
2. Create a resident script with sleep time set to 5. Edit conf variable as needed. In this example remote host is 192.168.1.230, base OID is .1.3.6.1.4.1.53864.1.1
Note that disabling the script does not stop the snmp daemon.
Code:
local conf = [[
rocommunity public 192.168.1.230
rwcommunity private 192.168.1.230
3. Create user library named "snmphandler". Edit the oids table and supply required oids and group address pairs. Base OID must match the configured OID in the snmpd conf. Make sure that all mapped group addresses exist.
Code:
local oids = {
{ oid = '.1.3.6.1.4.1.53864.1.1.1.0', addr = '1/1/1' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.2.1', addr = '1/1/2' },
{ oid = '.1.3.6.1.4.1.53864.1.1.2.1.3.1', addr = '1/1/4' },
{ oid = '.1.3.6.1.4.1.53864.1.1.3.0', addr = '1/1/5' },
{ oid = '.1.3.6.1.4.1.53864.1.1.4.0', addr = '1/1/6' },
{ oid = '.1.3.6.1.4.1.53864.1.1.5.0', addr = '1/1/7' },
{ oid = '.1.3.6.1.4.1.53864.1.1.6.0', addr = '1/1/8' },
}
require('genohm-scada')
db = require('dbenv').new()
local req, oid = assert(arg[ 1 ]), assert(arg[ 2 ])
local function get(item)
if not item then
return
end
local obj = grp.find(item.addr)
if not obj then
return
end
local value = obj.value
local objtype = 'integer'
if type(value) == 'boolean' then
value = value and 1 or 0
elseif type(value) == 'number' then
value = math.round(value)
elseif type(value) ~= 'string' then
value = require('json').encode(value)
end
print(item.oid)
print(type(value) == 'number' and 'integer' or 'string')
print(value)
end
-- get
if req == '-g' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(item)
break
end
end
-- next
elseif req == '-n' then
for i, item in ipairs(oids) do
if item.oid == oid then
get(oids[ i + 1 ])
break
elseif item.oid:find(oid, 1, true) == 1 then
get(item)
break
end
end
-- set
elseif req == '-s' then
local objtype, value = assert(arg[ 3 ]), assert(arg[ 4 ])
if objtype ~= 'string' then
value = tonumber(value)
end
for i, item in ipairs(oids) do
if item.oid == oid then
grp.write(item.addr, value)
end
end
end