Exemple #1
0
def error_check(error):
        #checks if the discovery or compilations returns with an error
        #if so a snmp trap is sent to yetnet and tbs zenoss
        if error == True:
                print ("- Houston we have a problem! -")
                ntfOrg = ntforg.NotificationOriginator()
                #send notification to yetnet
                ntfOrg.sendNotification(
                        ntforg.CommunityData('tbsro'),
                        ntforg.UdpTransportTarget(('10.10.10.207', 162)),
                        'trap',
                        '1.3.6.1.4.1.14697.1',
                        ('1.3.6.1.4.1.14697.1.1.1.7', rfc1902.OctetString('YETNET')),
                        ('1.3.6.1.4.1.14697.1.1.1.8', rfc1902.OctetString('3')),
                        ('1.3.6.1.4.1.14697.1.1.1.5', rfc1902.OctetString('////tor_auto_update.py')),
                        ('1.3.6.1.4.1.14697.1.1.1.3', rfc1902.OctetString('')),
                        ('1.3.6.1.4.1.14697.1.1.1.9', rfc1902.OctetString('Houston, we have a problem!')),
                        ('1.3.6.1.4.1.14697.1.1.1.10', rfc1902.OctetString('tor_auto_update.py'))
                )
                #send notification to tbs
                ntfOrg.sendNotification(
                        ntforg.CommunityData('tbsro'),
                        ntforg.UdpTransportTarget(('10.10.10.202', 162)),
                        'trap',
                        '1.3.6.1.4.1.14697.1',
                        ('1.3.6.1.4.1.14697.1.1.1.7', rfc1902.OctetString('TBS')),
                        ('1.3.6.1.4.1.14697.1.1.1.8', rfc1902.OctetString('3')),
                        ('1.3.6.1.4.1.14697.1.1.1.5', rfc1902.OctetString('////tor_auto_update.py')),
                        ('1.3.6.1.4.1.14697.1.1.1.3', rfc1902.OctetString('')),
                        ('1.3.6.1.4.1.14697.1.1.1.9', rfc1902.OctetString('Houston, we have a problem!')),
                        ('1.3.6.1.4.1.14697.1.1.1.10', rfc1902.OctetString('tor_auto_update.py'))
                )
                print("- snmp trap has been sent -")
        else:
                print("- no error - ")
Exemple #2
0
 def send_trap(self):
     ntf = ntforg.NotificationOriginator()
     err = ntf.sendNotification(
         ntforg.CommunityData(self.community),
         ntforg.UdpTransportTarget((self.manager_ip, 162)), 'trap',
         self.trapname, *self.binds)
     return err
Exemple #3
0
def sendEricssonAlarm(alarm):
    errorIndication = ntfOrg.sendNotification(
        ntforg.CommunityData('public'),
        ntforg.UdpTransportTarget(('localhost', 162)), 'trap',
        ntforg.MibVariable('ERICSSON-ALARM-MIB', alarm['severity']),
        (ntforg.MibVariable(
            'ERICSSON-ALARM-MIB',
            'eriAlarmActiveManagedObject'), alarm['moClasses']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB',
                            'eriAlarmActiveMajorType'), alarm['majorType']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB', 'eriAlarmActiveMinorType'),
         alarm['minorType']), (ntforg.MibVariable(
             'ERICSSON-ALARM-MIB',
             'eriAlarmActiveLastSequenceNo'), alarm['lastSequenceNumber']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB',
                            'eriAlarmActiveEventType'), alarm['eventType']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB', 'eriAlarmActiveEventTime'),
         alarm['eventTime']), (ntforg.MibVariable(
             'ERICSSON-ALARM-MIB',
             'eriAlarmActiveProbableCause'), alarm['probableCause']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB',
                            'eriAlarmActiveSpecificProblem'),
         alarm['specificProblem']), (ntforg.MibVariable(
             'ERICSSON-ALARM-MIB',
             'eriAlarmNObjAdditionalText'), alarm['additionalText']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB',
                            'eriAlarmNObjMoreAdditionalText'), 'false'),
        (ntforg.MibVariable(
            'ERICSSON-ALARM-MIB',
            'eriAlarmActiveProbableCause'), alarm['probableCause']),
        (ntforg.MibVariable('ERICSSON-ALARM-MIB',
                            'eriAlarmNObjResourceId'), alarm['resourceId']))
Exemple #4
0
    def send_trap(self):
        """ Send a SNMP trap with id `trapid` to the IP address `manager`
        """
        oid = self.options.eoid             # cascade enterprise Object ID
        trapid = self.options.trapid        # base string for trap indicators

        community = self.options.community
        manager_ip = self.options.manager_ip

        severity = self.options.severity
        description = self.trap_description
        url = self.options.trap_url
        alert_level = self.options.alert_level
        now = timeutils.datetime_to_seconds(datetime.datetime.now())

        trapname = '.'.join([oid, trapid])

        ntf = ntforg.NotificationOriginator()

        err = ntf.sendNotification(ntforg.CommunityData(community),
                                   ntforg.UdpTransportTarget((manager_ip, 162)),
                                   'trap',
                                   trapname, 
                                   ('1.3.6.1.2.1.1.3.0', rfc1902.Integer(0)),                         # Uptime
                                   ('1.3.6.1.4.1.7054.71.2.1.0', rfc1902.Integer(severity)),            # Severity
                                   ('1.3.6.1.4.1.7054.71.2.3.0', rfc1902.OctetString(description)),
                                   ('1.3.6.1.4.1.7054.71.2.4.0', rfc1902.Integer(0)),                   # Event ID
                                   ('1.3.6.1.4.1.7054.71.2.5.0', rfc1902.OctetString(url)),
                                   ('1.3.6.1.4.1.7054.71.2.7.0', rfc1902.Integer(alert_level)),         # Alert Level
                                   ('1.3.6.1.4.1.7054.71.2.8.0', rfc1902.Integer(now)),                 # Start Time
                                   ('1.3.6.1.4.1.7054.71.2.16.0', rfc1902.Integer(0)),                  # Source Count
                                   ('1.3.6.1.4.1.7054.71.2.18.0', rfc1902.Integer(0)),                  # Destination Count
                                   ('1.3.6.1.4.1.7054.71.2.20.0', rfc1902.Integer(0)),                  # Protocol Count
                                   ('1.3.6.1.4.1.7054.71.2.22.0', rfc1902.Integer(0)),                  # Port Count                                
                                   )
    def send_notification(self, notify_type, notification_trap, notification_args):
        agent_host = self.config['snmp']['transport']['listen_address']
        agent_port = self.config['snmp']['transport']['listen_port']
        community = self.config['snmp']['auth']['version2']['community']

        # Initialize Notification Originator
        notifier = ntforg.NotificationOriginator()

        # Build Tarp Argument List
        varbinds = []
        for varName, val in notification_args.items():
            varbinds.append((ntforg.MibVariable(*varName), val))

        # Send Notification
        error = notifier.sendNotification(ntforg.CommunityData(community),
                                          ntforg.UdpTransportTarget((agent_host, agent_port)),
                                          notify_type,
                                          ntforg.MibVariable(*notification_trap),
                                          *varbinds)

        # Check if Notification was successfully sent
        if error:
            self.fail('Notification not sent: %s' % error)

        log.debug("Sent Trap: %s:%d %r" % (agent_host, agent_port, notification_trap))

        # stupid hack for race condition
        time.sleep(1)
 def send_trap(self, host, notification):
     ntfOrg = ntforg.NotificationOriginator()
     errorIndication = ntfOrg.sendNotification(
         ntforg.CommunityData(host['community']),
         ntforg.UdpTransportTarget(
             (host['hostname'], host['port'])), 'trap',
         ntforg.MibVariable('SNMPv2-MIB', host['oid']),
         (ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name'))
     if errorIndication:
         self.log('info', 'Notification did not sent: %s' % errorIndication)
    def send_trap(self):
        self.generate()

        ntfOrg = ntforg.NotificationOriginator()

        ntfOrg.sendNotification(
            ntforg.CommunityData('public'),
            ntforg.UdpTransportTarget((self.cm.getTrapIp(), 5050)), 'trap',
            ntforg.MibVariable('SNMPv2-MIB', 'sysLocation'),
            ('1.3.6.1.6.3.1.1.5.4', v2c.OctetString(self.data)))
Exemple #8
0
def notification_send(SITE_IP):
    ntfOrg = ntforg.NotificationOriginator()

    #ntforg.CommunityData('public', mpModel=0),
    errorIndication = ntfOrg.sendNotification(
        ntforg.CommunityData(COMMUNITY, mpModel=0),
        ntforg.UdpTransportTarget((NOC_SERVER, SNMP_PORT)),
        'trap',
        '1.3.6.1.4.1.20408.4.1.1.2.0.432',
        ('1.3.6.1.2.1.1.3.0', 12345),
        ('1.3.6.1.6.3.18.1.3.0', SITE_IP),
        ('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', "Down"),
    )
    print "Sent trap to manager"
    if errorIndication:
        print('Notification not sent: %s' % errorIndication)
Exemple #9
0
    def send(self, mib, value, value_type='OctetString'):
        """
        v1 snmp, public
        """
        if not self.authData:
            raise ValueError('Credentials not set, use .security_XXX() methods')
        obj_class = getattr(rfc1902, value_type)
        errorIndication = self.ntfOrg.sendNotification(self.authData,
                                                       ntforg.UdpTransportTarget((self.host, self.port)), #transportTarget
                                                       'trap', #notifyType
                                                       ntforg.MibVariable('SNMPv2-MIB', 'snmpOutTraps'), #notificationType
                                                       ((rfc1902.ObjectName(mib),
                                                         obj_class(value))))

        if errorIndication:
            raise RuntimeError('Notification not sent: %s' % errorIndication)
        print('Sent SNMP TRAP {} "{}" to {} {}'.format(mib, value, self.host, self.port))
def send_trap(ip_addr='127.0.0.1'):
    from pysnmp.entity.rfc3413.oneliner import ntforg
    from pysnmp.proto import rfc1902

    def cbFun(sendRequestHandle, errorIndication, cbCtx):
        if errorIndication:
            print(errorIndication)
        else:
            print('INFORM %s delivered' % sendRequestHandle)

    ntfOrg = ntforg.AsynNotificationOriginator()

    ntfOrg.sendNotification(
        ntforg.CommunityData('public'),
        ntforg.UdpTransportTarget((ip_addr, 162)), 'inform',
        ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
        (('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name')), ),
        (cbFun, None))

    ntfOrg.snmpEngine.transportDispatcher.runDispatcher()
Exemple #11
0
#
# * SNMPv2c
# * with community name 'public'
# * over IPv4/UDP
# * send INFORM notification
# * with TRAP ID 'coldStart' specified as a MIB symbol
# * include managed object information specified as a MIB symbol
# * perform response OIDs and values resolution at MIB
#
from pysnmp.entity.rfc3413.oneliner import ntforg

ntfOrg = ntforg.NotificationOriginator()

errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
    ntforg.CommunityData('public'),
    ntforg.UdpTransportTarget(('localhost', 162)),
    'inform',
    ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
    (ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'my system'),
    lookupNames=True,
    lookupValues=True)

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()))
Exemple #12
0
# Various uses of the Notification Originator (TRAP/INFORM)
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902

ntfOrg = ntforg.NotificationOriginator()

# Using
#     SNMPv2c
#     over IPv4/UDP
#     send TRAP notification
#     with TRAP ID 'coldStart' specified as a MIB symbol
#     include managed object information specified as a MIB symbol
errorIndication = ntfOrg.sendNotification(
    ntforg.CommunityData('public'),
    ntforg.UdpTransportTarget(('localhost', 162)),
    'trap',
    ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
    # MIB symbol: (mib-name, mib-symbol, instance-id), new-value
    (ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name'))

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

# Using
#     SNMPv1
#     over IPv4/UDP
#     send TRAP notification
#     with Generic Trap #6 (enterpriseSpecific) and Specific Trap 432
#     with Uptime value 12345
#     with Agent Address '127.0.0.1'
#     with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2
Exemple #13
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)
Exemple #14
0
    ('1.3.6.1.4.1.14697.1.1.1.1', rfc1902.OctetString('1')),
    ('1.3.6.1.4.1.14697.1.1.1.2', rfc1902.OctetString('T12601')),
    ('1.3.6.1.4.1.14697.1.1.1.3', rfc1902.OctetString('docsis-snr-2')),
    ('1.3.6.1.4.1.14697.1.1.1.4', rfc1902.OctetString('3')),
    ('1.3.6.1.4.1.14697.1.1.1.5', rfc1902.OctetString('/Network/UBR01SHR/Docsis_Upstream/Cable6_2_4_upstream0/SNR')),
    ('1.3.6.1.4.1.14697.1.1.1.6', rfc1902.OctetString('2014-03-15T17:05:00.000-01:00')),
    ('1.3.6.1.4.1.14697.1.1.1.7', rfc1902.OctetString('YETNET')),
    ('1.3.6.1.4.1.14697.1.1.1.8', rfc1902.OctetString('4')),
    ('1.3.6.1.4.1.14697.1.1.1.9', rfc1902.OctetString('Signal/Noise-Ratio lower than 19dB')),
    ('1.3.6.1.4.1.14697.1.1.1.10', rfc1902.OctetString('Graenichen Ost INT, US A'))
)
"""
"""
#sending BGP Notification
ntfOrg.sendNotification(
    ntforg.CommunityData('tbsro'),
    ntforg.UdpTransportTarget(('10.10.10.202', 162)),
    'trap',
    '1.3.6.1.4.1.9.9.41.2.0.1',
    ('1.3.6.1.4.1.9.9.41.1.2.3.1.5', rfc1902.OctetString('This BGP neighbor is Down'))
)
"""
#sending Link Down
#1.3.6.1.6.3.1.1.5.3: linkDown
#1.3.6.1.2.1.2.2.1.2: ifDescr
ntfOrg.sendNotification(
    ntforg.CommunityData('tbsro'),
    ntforg.UdpTransportTarget(
        ('10.10.10.202', 162)), 'trap', '1.3.6.1.6.3.1.1.5.3',
    ('.1.3.6.1.2.1.2.2.1.2', rfc1902.OctetString('Gigabit')))
Exemple #15
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()))
Exemple #16
0
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902

ntfOrg = ntforg.NotificationOriginator()

print ntfOrg.sendNotification(
    ntforg.CommunityData('public'),
    ntforg.UdpTransportTarget(('192.168.10.91', 162)), 'trap',
    ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
    ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')))