SNMP
snmp
module implements SNMP communication protocol.
note
SNMP is available since Gateway version 2.3.
snmp.new()
-- @param connection_string string
-- @return table
function snmp.new(connection_string)
end
Creates a new SNMP client
instance with the given configuration. The configuration is represented as a connection_string
in URI format enapter-snmp://host:port?community=public
:
enapter-snmp://
: internal SNMP scheme definition;host:port
: SNMP target host and port;community
: community string value.
Example
local client = snmp.new("enapter-snmp://snmpserver:161?community=public")
client
Object
client:get()
-- @param oids table Object Identifiers
-- @return table|nil, string|nil Variables and error
function client:get(oids)
end
Retrieves variables based on entered Object Identifiers. If the method call fails, the error
will contain a non-nil string. If the method call succeeds error
will be nil. The result represents a table of variable objects, where each object contains type
and value
fields. The variables are returned in the order they were requested.
Example
function utf8_from(t)
local bytearr = {}
for _, v in ipairs(t) do
local utf8byte = v < 0 and (0xff + v + 1) or v
table.insert(bytearr, string.char(utf8byte))
end
return table.concat(bytearr)
end
local client = snmp.new("enapter-snmp://snmpserver:161?community=public")
local vars, err = client:get({".1.3.6.1.2.1.1.4.0", ".1.3.6.1.2.1.1.6.0"})
if err then
enapter.log("Error get: "..err, "error")
else
for _, v in ipairs(vars) do
enapter.log(v.type..": "..utf8_from(v.value))
end
end