From c6aa8dce75476de5cdea904d855c0fc78a1d61b6 Mon Sep 17 00:00:00 2001
From: elie
Although instantiation of this class is cheap, in the course of its further
-use, SNMP engine configuration is built and maintained though methods infocation.
+use, SNMP engine configuration is built and maintained though methods invocation.
Therefore it is advised to keep and reuse CommandGenerator instance (or snmpEngine
instance if passed as an initializer) for as long as possible within user applicatin.
-The following code sends SNMP TRAP over SNMPv3:
+The following code sends SNMP TRAP message:
+
+
->>> from pysnmp.entity.rfc3413.oneliner import cmdgen, ntforg ->>> from pysnmp.proto.api import v2c ->>> ->>> ntfOrg = ntforg.NotificationOriginator() ->>> errorIndication = ntfOrg.sendNotification( -... cmdgen.UsmUserData('my-user', 'my-authkey', 'my-privkey'), -... cmdgen.UdpTransportTarget(('localhost', 162)), -... 'trap', -... cmdgen.MibVariable('SNMPv2-MIB', 'coldStart'), -... ('1.3.6.1.2.1.1.3.0', v2c.TimeTicks(44100)) +from pysnmp.entity.rfc3413.oneliner import ntforg + +ntfOrg = ntforg.NotificationOriginator() + +errorIndication = ntfOrg.sendNotification( + ntforg.CommunityData('public'), + ntforg.UdpTransportTarget(('localhost', 162)), + 'trap', + ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), + (ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name') ) ->>> print(errorIndication) -None ->>> print(errorStatus) -0 + +if errorIndication: + print('Notification not sent: %s' % errorIndication) |