Use the SNMP library in Lua to monitor OIDs obtained from an SNMP-enabled device's MIB file.
Note: In the SNMP model, Q-SYS acts as the SNMP Manager, while the device you intend to monitor runs an SNMP Agent that allows for monitoring.
Create a new SNMP session.
SNMPSession.New(type)
type
SNMPSessionType.V2c
: Instantiate an SNMP v2 session.
SNMPSessionType.V3
: Instantiate an SNMP v3 session.
snmp_session = SNMPSession.New(SNMP.SessionType.v3)
Specify the host to which to connect.
setHostName("hostname")
hostname : String. The target host name.
snmp_session:setHostName("mydevice")
For SNMP v3 only, set the authorization type for the session.
setAuthType(type)
type
SNMP.AuthType.NoAuth
: No authorization type and no privacy type.
SNMP.AuthType.AuthNoPriv
: Authorization with no privacy.
SNMP.AuthType.AuthPriv
: Both authorization and privacy.
snmp_session:setAuthType(SNMP.AuthType.AuthNoPriv)
For SNMP v3 only, set the authorization protocol for the session.
setAuthProt(type)
type
SNMP.AuthProtocol.NoAuth
: Disable the authorization protocol.
SNMP.AuthProtocol.MD5
: Enable the MD5 authorization protocol.
SNMP.AuthProtocol.SHA
: Enable the SHA authorization protocol.
snmp_session:setAuthProt(SNMP.AuthProtocol.MD5)
For SNMP v3 only, set the privacy protocol for the session.
setPrivProt(type)
type
SNMP.PrivProtocol.NoPriv
: Disable the privacy protocol.
SNMP.PrivProtocol.AES
: Enable the AES privacy protocol.
SNMP.PrivProtocol.DES
: Enable the DES privacy protocol.
snmp_session:setPrivProt(SNMP.PrivProtocol.DES)
For SNMP v3 only, set the user name for the session.
setUserName("username")
username : String. The user name for the session.
snmp_session:setUserName("MD5User")
For SNMP v3 only, set the authorization pass phrase for the session.
setPassPhrase("passphrase")
passphrase : String. The pass phrase for the corresponding user name.
snmp_session:setPassPhrase("My Demo Password")
For SNMP v3 only, set the privacy pass phrase for the session.
setPrivPassPhrase("privpass")
privpass : String. The privacy pass phrase for the session.
snmp_session:setPrivPassPhrase("password")
For SNMP v2 sessions only, set the community name for the session.
setCommunity("community")
community : String. The community name for the session.
snmp_session:setCommunity("demopublic")
Initiate the connection to the corresponding session.
startSession()
snmp_session:startSession()
Request an object ID (OID) and pass the response to a Lua callback.
getRequest("oid", callback)
oid : String. The object ID to request.
callback : The Lua callback to which to pass the response.
function myCallback(dataout) for k,v in pairs(dataout) do print(k,v) end end snmp_session:getRequest(".1.3.6.1.2.1.1.3.0", myCallback)
Set a new value for a specified OID.
setRequest("oid", "new_value", type, callback)
oid : String. The object ID to set in the request.
new_value : String. The new value to which to set the specified object ID.
type
SNMP.SNMPDataType.unknown
SNMP.SNMPDataType.integer32
SNMP.SNMPDataType.unsigned32
SNMP.SNMPDataType.unsigned_integer32
SNMP.SNMPDataType.timeticks
SNMP.SNMPDataType.ip_address
SNMP.SNMPDataType.object_id
SNMP.SNMPDataType.octet_string
SNMP.SNMPDataType.hex
SNMP.SNMPDataType.decimal
SNMP.SNMPDataType.bit_string
SNMP.SNMPDataType.integer64
SNMP.SNMPDataType.unsigned64
SNMP.SNMPDataType.float32
SNMP.SNMPDataType.double64
callback : The Lua callback to which to pass the response.
function myCallback(dataout) for k,v in pairs(dataout) do print(k,v) end end snmp_session:setRequest(".1.3.6.1.2.1.1.5.0", "new_switch_name", SNMP.SNMPDataType.octet_string, myCallback)
Assign the Lua callback for successful SNMP events.
RequestID : Integer. The request ID for bookkeeping purposes.
OID : String. The object ID for the response.
Value : String. The string representation for the current state of the object ID.
HostName : String. The host name for the response.
snmp_object.EventHandler = function(response) print(response.OID) print(response.Value) end
Assign the Lua callback for unsuccessful SNMP events.
Error : String. The error message for the request.
snmp_object.ErrorHandler = function(response) print(response.Error) end
Software and Firmware | Resources | QSC Self Help Portal | Q-SYS Help Feedback
Copyright © 2019 QSC, LLC. Click here for trademark and other legal notices. | Q-SYS 8.1.1