Guest User

Untitled

a guest
Nov 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. from pysnmp.entity import engine, config
  2. from pysnmp.carrier.asyncore.dgram import udp
  3. from pysnmp.entity.rfc3413 import ntforg
  4. from pysnmp.proto.api import v2c
  5. import subprocess
  6.  
  7. #subsprocess.popen(['asterisk', '-rx', 'sip', 'show', 'registry'])
  8. return_val=subprocess.Popen(['asterisk -rx "sip show registry"'],stdout=subprocess.PIPE).communicate()
  9. print return_val
  10.  
  11. # Create SNMP engine instance
  12. snmpEngine = engine.SnmpEngine()
  13.  
  14. # SecurityName <-> CommunityName mapping
  15. config.addV1System(snmpEngine, 'my-area', 'public', transportTag='all-my-managers')
  16.  
  17. # Specify security settings per SecurityName (SNMPv1 -> 0)
  18. config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 0)
  19.  
  20. # Setup transport endpoint and bind it with security settings yielding
  21. # a target name
  22. config.addTransport(
  23. snmpEngine,
  24. udp.domainName,
  25. udp.UdpSocketTransport().openClientMode()
  26. )
  27. config.addTargetAddr(
  28. snmpEngine, 'my-nms',
  29. udp.domainName, ('127.0.0.1', 162),
  30. 'my-creds',
  31. tagList='all-my-managers'
  32. )
  33.  
  34. # Specify what kind of notification should be sent (TRAP or INFORM),
  35. # to what targets (chosen by tag) and what filter should apply to
  36. # the set of targets (selected by tag)
  37. config.addNotificationTarget(
  38. snmpEngine, 'my-notification', 'my-filter', 'all-my-managers', 'trap'
  39. )
  40.  
  41. # Allow NOTIFY access to Agent's MIB by this SNMP model (1), securityLevel
  42. # and SecurityName
  43. config.addContext(snmpEngine, '')
  44. config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))
  45.  
  46. # *** SNMP engine configuration is complete by this line ***
  47.  
  48. # Create Notification Originator App instance.
  49. ntfOrg = ntforg.NotificationOriginator()
  50.  
  51.  
  52.  
  53. #Build and submit notification message to dispatcher
  54. ntfOrg.sendVarBinds(
  55. snmpEngine,
  56. # Notification targets
  57. 'my-notification', # notification targets
  58. None, '', # contextEngineId, contextName
  59. # var-binds
  60. [
  61. # managed object '1.3.6.1.2.1.1.1.0' = 'my system'
  62. (v2c.ObjectIdentifier('1.3.6.1.4.1.36119.1.1.0'),
  63. v2c.OctetString('my system 1')),
  64. (v2c.ObjectIdentifier('1.3.6.1.4.1.36119.1.2.0'),
  65. v2c.OctetString('my system 2')),
  66. ]
  67. )
  68.  
  69. print('Notification is scheduled to be sent')
  70.  
  71. snmpEngine.transportDispatcher.runDispatcher()
Add Comment
Please, Sign In to add comment