diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-03-18 13:23:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-18 13:23:38 +0100 |
commit | 708062acdea970883a7c7de465f719451012ad6f (patch) | |
tree | 81d0a591d191278dd8bdd9706038d7071483c6b0 /examples | |
parent | 010e34e40a8eaf142e8393eab6f29a467fe8fa92 (diff) | |
download | pysnmp-git-708062acdea970883a7c7de465f719451012ad6f.tar.gz |
More twisted examples (#47)
* twisted inline callback example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py b/examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py new file mode 100644 index 00000000..e326108c --- /dev/null +++ b/examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py @@ -0,0 +1,44 @@ +""" +SNMPv2c TRAP via Twisted inline callbacks ++++++++++++++++++++++++++++++++++++++++++ + +Send SNMPv2c TRAP through unified SNMPv3 message processing framework +using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2 1.3.6.1.2.1.1.1.0 s "Hello from Twisted" + +"""# +from twisted.internet.task import react, defer +from pysnmp.hlapi.twisted import * + + +@defer.inlineCallbacks +def sendtrap(reactor, snmpEngine, hostname): + + yield sendNotification( + snmpEngine, + CommunityData('public', mpModel=0), + UdpTransportTarget((hostname, 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'), OctetString('Hello from Twisted')) + ) + ) + +# Preserve SnmpEngine instance across [potentially] multiple calls to safe on initialization +snmpEngine = SnmpEngine() + +react(sendtrap, [snmpEngine, 'demo.snmplabs.com']) + |