We are trying to send a custom SNMP notification using PYSNMP module using custom MIB's but when it send the notification we get an DISMAN-EVENT-MIB::sysUpTimeInstance event also as part of the notification. We want to avoid the same. Below is the sample script
from pysnmp.entity.rfc3413.oneliner import ntforg
ntfOrg = ntforg.NotificationOriginator()
errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
ntforg.CommunityData('public'),
ntforg.UdpTransportTarget(('localhost', 162)),
'inform',
ntforg.MibVariable('SNMPv2-MIB', 'sysDescr'),
( ntforg.MibVariable('SNMPv2-MIB', 'sysDescr', 0), 'Hello' ),
lookupNames=True, lookupValues=True
)
if errorIndication:
print('Notification not sent: %s' % errorIndication)
elif errorStatus:
print('Notification Receiver returned error: %s @%s' %
(errorStatus, errorIndex))
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
Below is the out I get in /var/log/messages
Jun 1 18:56:14 localhost snmptrapd[1194]: 2015-06-01 18:56:14 localhost [UDP: [127.0.0.1]:56469->[127.0.0.1]:162]:
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (0) 0:00:00.00 SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-MIB::sysDescr SNMPv2-MIB::sysDescr.0 = STRING: Hello
So how we can avoid not sending DISMAN-Event as part of it.
A well-formed SNMP v2c/v3 Notification must contain two specific OIDs at the beginning of its var-bindings list. Those OIDs are sysUpTime and snmpTrapOID. If you leave them out, that would be a violation of the protocol. So pysnmp adds those OIDs for you into PDU.
If that's OK to send malformed packet, you have two options:
Both APIs will let you sending your own PDU with whatever variable-bindings you consider appropriate in your situation.