summaryrefslogtreecommitdiff
path: root/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py')
-rw-r--r--examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
new file mode 100644
index 00000000..e1084f6d
--- /dev/null
+++ b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
@@ -0,0 +1,35 @@
+"""Notification Originator Application (TRAP)"""
+from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher
+from pysnmp.carrier.asynsock.dgram import udp
+from pyasn1.codec.ber import encoder
+from pysnmp.proto import api
+
+# Protocol version to use
+verID = api.protoVersion1
+pMod = api.protoModules[verID]
+
+# Build PDU
+trapPDU = pMod.TrapPDU()
+pMod.apiTrapPDU.setDefaults(trapPDU)
+
+# Traps have quite different semantics among proto versions
+if verID == api.protoVersion1:
+ pMod.apiTrapPDU.setEnterprise(trapPDU, (1,3,6,1,1,2,3,4,1))
+ pMod.apiTrapPDU.setGenericTrap(trapPDU, 'coldStart')
+
+# Build message
+trapMsg = pMod.Message()
+pMod.apiMessage.setDefaults(trapMsg)
+pMod.apiMessage.setCommunity(trapMsg, 'public')
+pMod.apiMessage.setPDU(trapMsg, trapPDU)
+
+transportDispatcher = AsynsockDispatcher()
+transportDispatcher.registerTransport(
+ udp.domainName, udp.UdpSocketTransport().openClientMode()
+ )
+transportDispatcher.sendMessage(
+ encoder.encode(trapMsg), udp.domainName, ('localhost', 162)
+ )
+transportDispatcher.stopDispatcher() # XXX run only once
+transportDispatcher.runDispatcher()
+transportDispatcher.closeDispatcher()