Skip to main content

SNMPHardware UCMVirtual UCM

The snmp module implements SNMP communication protocol.

snmp.new()

-- @param connection_uri string Connection URI
-- @return table
function snmp.new(connection_uri)
end

Creates a new SNMP client. The connection URI defines the SNMP connection configuration.

Use enapter-snmp as the connection schema, the SNMP server address as the connection target, and community as a connection parameter.

Example

-- Connect to server at snmpserver:161 with "public" community string
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 ~= nil then
enapter.log("Error get: " .. err, "error")
else
for _, v in ipairs(vars) do
enapter.log(v.type .. ": " .. utf8_from(v.value))
end
end

All Rights Reserved © 2025 Enapter AG.