コード例 #1
0
ファイル: ntforg.py プロジェクト: ithek/pysnmp
snmpContext = context.SnmpContext(snmpEngine)

#
# Twisted API follows
#


# Error/confirmation reciever
def receiveResponse(cbCtx):
    (sendRequestHandle, errorIndication) = cbCtx
    print('Notification %s, status - %s' %
          (sendRequestHandle, errorIndication and errorIndication
           or 'delivered'))
    reactor.stop()


df = ntforg.NotificationOriginator(snmpContext).sendNotification(
    snmpEngine,
    # Notification targets
    'my-notification',
    # Trap OID (SNMPv2-MIB::coldStart)
    (1, 3, 6, 1, 6, 3, 1, 1, 5, 1),
    # ((oid, value), ... )
    (((1, 3, 6, 1, 2, 1, 1, 1), v2c.OctetString('Example Notificator')),
     ((1, 3, 6, 1, 2, 1, 1, 5), v2c.OctetString('Notificator Example'))),
)

if doInform:
    df.addCallback(receiveResponse)
    reactor.run()
コード例 #2
0
# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(snmpEngine, 'my-notification', 'my-filter',
                             'all-my-managers', 'trap')

# Allow NOTIFY access to Agent's MIB by this SNMP model (3), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1, 3, 6))

# Create default SNMP context where contextEngineId == SnmpEngineId
snmpContext = context.SnmpContext(snmpEngine)

# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator(snmpContext)

# Build and submit notification message to dispatcher
ntfOrg.sendNotification(
    snmpEngine,
    # Notification targets
    'my-notification',
    # Trap OID (SNMPv2-MIB::coldStart)
    (1, 3, 6, 1, 6, 3, 1, 1, 5, 1),
    # ( (oid, value), ... )
    (
        ((1, 3, 6, 1, 2, 1, 1, 5, 0), rfc1902.OctetString('system name')), ))

print('Notification is scheduled to be sent')

# Schedule Twisted mainloop shutdown shortly
コード例 #3
0
# Specify what kind of notification should be sent (TRAP or INFORM),
# to what targets (chosen by tag) and what filter should apply to
# the set of targets (selected by tag)
config.addNotificationTarget(snmpEngine, 'my-notification', 'my-filter',
                             'all-my-managers', 'trap')

# Allow NOTIFY access to Agent's MIB by this SNMP model (1), securityLevel
# and SecurityName
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1, 3, 6))

# Create default SNMP context where contextEngineId == SnmpEngineId
snmpContext = context.SnmpContext(snmpEngine)

# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator(snmpContext)

# Prepare notification to be sent yielding Twisted deferred object
ntforg.NotificationOriginator(snmpContext).sendNotification(
    snmpEngine,
    # Notification targets
    'my-notification',
    # TRAP OID: Generic Trap #6 (enterpriseSpecific) and Specific Trap 432
    '1.3.6.1.4.1.20408.4.1.1.2.0.432',
    # additional var-binds holding SNMPv1 TRAP details
    (
        # Uptime value with 12345
        (rfc1902.ObjectName('1.3.6.1.2.1.1.3.0'), rfc1902.TimeTicks(12345)),
        # Agent Address with '127.0.0.1'
        (rfc1902.ObjectName('1.3.6.1.6.3.18.1.3.0'),
         rfc1902.IpAddress('127.0.0.1')),