예제 #1
0
 def security_aes128(self, user, authkey, privkey):
     """
     v3 snmp, secure
     """
     self.authData, = ntforg.UsmUserData(user, authkey, privkey,
                                         authProtocol=ntforg.usmHMACSHAAuthProtocol,
                                         privProtocol=ntforg.usmAesCfb128Protocol)
예제 #2
0
파일: ntforg.py 프로젝트: ithek/pysnmp
    ntforg.UdpTransportTarget(
        ('localhost', 162)), 'trap', '1.3.6.1.6.3.1.1.5.2',
    ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
    ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')))

if errorIndication:
    print('Notification not sent: %s' % errorIndication)

# Using
#     SNMPv3 user 'usr-md5-des', auth: MD5, priv 3DES
#     over IPv4/UDP
#     send INFORM notification
#     with TRAP ID 'warmStart' specified as a string OID
#     include managed object information 1.3.6.1.2.1.1.5.0 = 'system name'
errorIndication = ntfOrg.sendNotification(
    ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
    ntforg.UdpTransportTarget(
        ('localhost', 162)), 'inform', '1.3.6.1.6.3.1.1.5.2',
    ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name')))

if errorIndication:
    print('Notification not sent: %s' % errorIndication)

# Using
#     SNMPv3 user 'usr-sha-aes', auth: SHA, priv: AES128
#     over IPv6/UDP
#     send TRAP notification
#     with TRAP ID 'authenticationFailure' specified as a MIB symbol
#     include managed object information 1.3.6.1.2.1.1.1.0 = 'my system'
#     include managed object information 1.3.6.1.2.1.1.3.0 = 567
errorIndication = ntfOrg.sendNotification(
예제 #3
0
# requires having a collection of Managed Objects registered under
# the ContextName being used.
#
from pysnmp.entity import engine
from pysnmp.entity.rfc3413 import context
from pysnmp.entity.rfc3413.oneliner import ntforg

snmpEngine = engine.SnmpEngine()
snmpContext = context.SnmpContext(snmpEngine)

# register default collection of Managed Objects under new contextName
snmpContext.registerContextName('my-context', snmpContext.getMibInstrum())

ntfOrg = ntforg.NotificationOriginator(snmpEngine, snmpContext)

errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
    ntforg.UsmUserData('usr-md5-none', 'authkey1'),
    ntforg.UdpTransportTarget(('localhost', 162)),
    'inform',
    '1.3.6.1.6.3.1.1.5.2',
    contextName='my-context')

if errorIndication:
    print('Notification not sent: %s' % errorIndication)
elif errorStatus:
    print('Notification Receiver returned error: %s @%s' %
          (errorStatus, errorIndex))
else:
    for name, val in varBinds:
        print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
예제 #4
0
# * with user 'usr-sha-aes128', auth: SHA, priv: AES128
# * over IPv4/UDP
# * send TRAP notification
# * with TRAP ID 'authenticationFailure' specified as a MIB symbol
# * do not include any additional managed object information
#
# SNMPv3 TRAPs requires pre-sharing the Notification Originator's
# value of SnmpEngineId with Notification Receiver. To facilitate that
# we will use static (e.g. not autogenerated) version of snmpEngineId.
#
from pysnmp.entity import engine
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902

# This SNMP Engine ID value should also be configured to TRAP receiver.
snmpEngineId = rfc1902.OctetString(hexValue='8000000001020304')

ntfOrg = ntforg.NotificationOriginator(engine.SnmpEngine(snmpEngineId))

errorIndication = ntfOrg.sendNotification(
    ntforg.UsmUserData('usr-sha-aes128',
                       'authkey1',
                       'privkey1',
                       authProtocol=ntforg.usmHMACSHAAuthProtocol,
                       privProtocol=ntforg.usmAesCfb128Protocol),
    ntforg.UdpTransportTarget(('127.0.0.1', 162)), 'trap',
    ntforg.MibVariable('SNMPv2-MIB', 'authenticationFailure'))

if errorIndication:
    print('Notification not sent: %s' % errorIndication)
예제 #5
0
# Notification Originator
#
# Send SNMP notification using the following options:
#
# * SNMPv3
# * with user 'usr-md5-des', auth: MD5, priv DES
# * over IPv4/UDP
# * send INFORM notification
# * with TRAP ID 'warmStart' specified as a string OID
# * include managed object information 1.3.6.1.2.1.1.5.0 = 'system name'
#
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902

ntfOrg = ntforg.NotificationOriginator()

errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
    ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
    ntforg.UdpTransportTarget(
        ('localhost', 162)), 'inform', '1.3.6.1.6.3.1.1.5.2',
    ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name')))

if errorIndication:
    print('Notification not sent: %s' % errorIndication)
elif errorStatus:
    print('Notification Receiver returned error: %s @%s' %
          (errorStatus, errorIndex))
else:
    for name, val in varBinds:
        print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
예제 #6
0
# Notification Originator (TRAP/INFORM)
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902

errorIndication = ntforg.NotificationOriginator().sendNotification(
    # SNMP v1
    #    ntforg.CommunityData('test-manager', 'public', 0),
    # SNMP v2
    #   ntforg.CommunityData('test-manager', 'public'),
    # SNMP v3
    ntforg.UsmUserData('test-user', 'authkey1', 'privkey1'),
    ntforg.UdpTransportTarget(('localhost', 162)),
    # Trap type
    #    'trap',
    'inform',
    # Trap OID
    (
        ('SNMPv2-MIB', 'coldStart'), ),
    # MIB symbol name, plain string value
    ((('SNMPv2-MIB', 'sysName'), 0), 'new name'),
    # Plain OID name, rfc1902 class instance value
    ((1, 3, 6, 1, 2, 1, 1, 5, 0), rfc1902.OctetString('new name')))

if errorIndication:
    print errorIndication