[pysnmp-users] Getting extra blank elements in 4.3.2
Brought to you by:
elie
From: <evi...@em...> - 2016-02-17 02:43:47
|
Basically, the code that was working in 4.2.5 broke in 4.3.0. If I look at it in wireshark, in 4.3.2 I have 2 repeated elements, with Null as the value. I'm not sure if I'm using pysnmp correctly or if a bug got introduced. Rest of message is Python code and MIB file for a minimal reproduction. ----- from pysnmp.smi import builder from pysnmp.entity import engine from pysnmp.entity.rfc3413.oneliner import ntforg import os.path class SNMPSender(object): """Will send a SNMP trap to a specific ip address, based on an event's data""" def __init__(self, ip, port=162): self.ip = ip self.port = int(port) snmp_engine = engine.SnmpEngine() mib_builder = snmp_engine.msgAndPduDsp.mibInstrumController.mibBuilder mib_builder.setMibSources(builder.DirMibSource(os.path.join(os.path.dirname(__file__), "pysnmp_mibs")), *mib_builder.getMibSources()) self.ntf_org = ntforg.NotificationOriginator(snmp_engine) def send_event(self, event_name, event_category): self.ntf_org.sendNotification( ntforg.CommunityData('public'), # Login data; might need to be replaced. ntforg.UdpTransportTarget((self.ip, self.port)), # actual connection info 'trap', # type of data we're sending ntforg.MibVariable('EVENTS-MIB', 'eventNotice'), # actual data we're sending (ntforg.MibVariable('EVENTS-MIB', 'eventName'), event_name), (ntforg.MibVariable('EVENTS-MIB', 'eventCategory'), event_category) ) SNMPSender("4.3.2.1").send_event("event_name", "event_category") ----- EVENTS-MIB DEFINITIONS ::= BEGIN -- If you edit this file, you also need to regenerate the .py file associated with this: -- Use the page at https://www.ibr.cs.tu-bs.de/bin/smitools.cgi to convert to Python format (smidump, target format Python). Save the result to a file. -- On a Linux-like system (cygwin will work), run "cat result_file | python libsmi2pysnmp", sending the result to a file. libsmi2pysnmp is located in Python27/Scripts if pysnmp is installed. IMPORTS MODULE-IDENTITY, NOTIFICATION-TYPE, OBJECT-TYPE, enterprises FROM SNMPv2-SMI MODULE-COMPLIANCE, NOTIFICATION-GROUP, OBJECT-GROUP FROM SNMPv2-CONF; -- Most of this is just for human consumption. If you edit this, I suggest editing LAST-UPDATED and adding a new REVISION/DESCRIPTION set. eventMIB MODULE-IDENTITY LAST-UPDATED "201507010000Z" ORGANIZATION "---" CONTACT-INFO "---" DESCRIPTION "MIB file. Currently just holds event information for generation of SNMP traps." REVISION "201507010000Z" DESCRIPTION "Initial revision" ::= { enterprises 37033 } -- information for notifications eventTraps OBJECT IDENTIFIER ::= { eventMIB 0 } eventObjects OBJECT IDENTIFIER ::= { eventMIB 1 } -- These are basically from the event object. eventName OBJECT-TYPE SYNTAX OCTET STRING -- max length 65536 MAX-ACCESS read-only STATUS current DESCRIPTION "A string indicating the type of notification. Corresponds with event name." ::= { eventObjects 1 } eventCategory OBJECT-TYPE SYNTAX OCTET STRING MAX-ACCESS read-only STATUS current DESCRIPTION "The name of the module/app sending the notification. Corresponds with event category." ::= { eventObjects 2 } -- This is the actual trap. There is no special significance to 2. eventNotice NOTIFICATION-TYPE OBJECTS { eventName, eventCategory } STATUS current DESCRIPTION "An event trap." ::= { eventTraps 2 } -- Conformance information. It's needed, but you don't need to understand it too much. Just add new objects to one of the 2 groups. eventMIBCompliances OBJECT IDENTIFIER ::= { eventMIB 3 } eventMIBGroups OBJECT IDENTIFIER ::= { eventMIB 4 } eventComplianceGroups MODULE-COMPLIANCE STATUS current DESCRIPTION "The compliance statement for this MIB module." MODULE -- this module MANDATORY-GROUPS { trapGroup, objectGroup } ::= { eventMIBCompliances 1 } -- If you add extra traps, they need to go in here. trapGroup NOTIFICATION-GROUP NOTIFICATIONS { eventNotice } STATUS current DESCRIPTION "Basic event notifications." ::= { eventMIBGroups 1 } -- If you add extra objects, they need to go in here. objectGroup OBJECT-GROUP OBJECTS {eventName, eventCategory} STATUS current DESCRIPTION "Grouped event parameters." ::= { eventMIBGroups 2 } END |