/usr/share/doc/python-pysnmp4-doc/examples/v3arch/manager/ntfrcv.py is in python-pysnmp4-doc 4.1.9a-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # Notification Receiver (TRAP/INFORM)
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
from pysnmp.entity.rfc3413 import ntfrcv
from pysnmp import debug
# Optionally enable stdout debugging
#debug.setLogger(debug.Debug('all'))
# Create SNMP engine with autogenernated engineID and pre-bound
# to socket transport dispatcher
snmpEngine = engine.SnmpEngine()
# Setup transport endpoint
config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openServerMode(('127.0.0.1', 162))
)
# v1/2 setup
config.addV1System(snmpEngine, 'test-agent', 'public')
# v3 setup
config.addV3User(
snmpEngine, 'test-user',
config.usmHMACMD5AuthProtocol, 'authkey1',
config.usmDESPrivProtocol, 'privkey1'
# '\x80\x00\x4f\xb8\x1c\x3d\xaf\xe6' # ContextEngineID of
# Notification Originator
)
# Callback function for receiving notifications
def cbFun(snmpEngine,
contextEngineId, contextName,
varBinds,
cbCtx):
print 'Notification from SNMP Engine \"%s\", Context \"%s\"' % (
contextEngineId, contextName
)
for name, val in varBinds:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
# Apps registration
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
snmpEngine.transportDispatcher.runDispatcher()
|