I am trying to write a python SNMP agent that I can embed in my python application so that the application can be remotely controlled using OpenNMS. OpenNMS expects the Agent to implement the HOST-RESOURCES-MIB request for the two fields hrSWRunName and hrSWRunStatus .
I took the pysnmp example as the basis of my code and edited it as I considered necessary. The resulting code is as follows:
import logging from pysnmp import debug from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.proto.api import v2c from pysnmp.smi import builder, instrum, exval
The code works without errors. varBinds and the MIB Table walk show what I think I should expect:
[2016-12-29 16:42:49,323-INFO]-(SNMPAgent) Starting.... [2016-12-29 16:42:49,470-DEBUG]-(SNMPAgent) Loading HOST-RESOURCES-MIB module... [2016-12-29 16:42:49,631-DEBUG]-(SNMPAgent) done [2016-12-29 16:42:49,631-DEBUG]-(SNMPAgent) Building MIB tree... [2016-12-29 16:42:49,631-DEBUG]-(SNMPAgent) done [2016-12-29 16:42:49,631-DEBUG]-(SNMPAgent) Building table entry index from human-friendly representation... [2016-12-29 16:42:49,631-DEBUG]-(SNMPAgent) done [2016-12-29 16:42:49,632-DEBUG]-(SNMPAgent) Create/update HOST-RESOURCES-MIB::hrSWRunTable table row: 1.3.6.1.2.1.25.4.2.1.1.1 = 1 [2016-12-29 16:42:49,651-DEBUG]-(SNMPAgent) done 1.3.6.1.2.1.25.4.2.1.2.1 = TradeLoader 1.3.6.1.2.1.25.4.2.1.3.1 = 0 1.3.6.1.2.1.25.4.2.1.4.1 = All is well 1.3.6.1.2.1.25.4.2.1.5.1 = If this was not the case it would say so here 1.3.6.1.2.1.25.4.2.1.6.1 = 'application' 1.3.6.1.2.1.25.4.2.1.7.1 = 'running' [2016-12-29 16:42:49,651-DEBUG]-(SNMPAgent) Read whole MIB (table walk) 1.3.6.1.2.1.25.4.2.1.1.1 = 1 1.3.6.1.2.1.25.4.2.1.2.1 = TradeLoader 1.3.6.1.2.1.25.4.2.1.3.1 = 0 1.3.6.1.2.1.25.4.2.1.4.1 = All is well 1.3.6.1.2.1.25.4.2.1.5.1 = If this was not the case it would say so here 1.3.6.1.2.1.25.4.2.1.6.1 = 'application' 1.3.6.1.2.1.25.4.2.1.7.1 = 'running' 1.3.6.1.2.1.25.5.1.1.1.1 = <no value> 1.3.6.1.2.1.25.5.1.1.2.1 = <no value> [2016-12-29 16:42:53,490-DEBUG]-(SNMPAgent) done
Finally, the dispatcher is running.
The problem is that when you try to request an agent, nothing happens. I do not get an answer. I looked through my code, and one obvious thing about this is that I am not explicitly binding snmpEngine to my created MIB. Should I do this?
Any understanding would be greatly appreciated, as I struggle to figure out where to go at the moment.