• Using eAPI to Provide SNMP Extensions

 
 
Print Friendly, PDF & Email

EOS utilizes net-snmp which offers provisions to extend OIDs.  The following script leverages eAPI to gather OSPFv3 interface information and populates the SNMP ospfv3IfTable.

The OSPFV3-MIB can be downloaded from here: http://www.oidview.com/mibs/0/OSPFV3-MIB.html



#!/usr/bin/python -u # # Arista Networks, Inc. # # Script: ospfv3IfTable.py v1.6 # # This script populates the ospfv3IfTable via a net-snmp extension # # 1. Copy this script to /mnt/flash as ospfv3IfTable.py # # 2. Copy snmp_passpersist to /mnt/flash # https://github.com/nagius/snmp_passpersist # # 3. Enable management api (script uses a unix socket) # management api http-commands # protocol unix-socket # no shutdown # # 4. Configure snmp to respond to the custom OID # snmp-server extension .1.3.6.1.3.102.1.7 flash:/ospfv3IfTable.py # import snmp_passpersist as snmp import sys, os, errno import Logging from jsonrpclib import Server # Configuration section OID_BASE = ".1.3.6.1.3.102.1.7" POLLING_INTERVAL = 10 MAX_RETRY = 10 pp = None # Define log messages Logging.logD( id="SNMP_EXTENSION", severity=Logging.logInfo, format="%s", explanation="Status message from snmp extension file", recommendedAction=Logging.NO_ACTION_REQUIRED ) def ospfIfTable(): ifIndexCommand = "show snmp mib ifmib ifindex" ipv6OspfIntCommand = "show ipv6 ospf interface" switch = Server( "unix:/var/run/command-api.sock" ) getIfIndex = switch.runCmds( 1, [ ifIndexCommand ] )[ 0 ][ 'ifIndex' ] getIpv6OspfInt = switch.runCmds( 1, [ ipv6OspfIntCommand ] )[ 0 ][ 'vrfs' ] # Build the ospfv3ifTable for vrf in getIpv6OspfInt.keys(): for interface in getIpv6OspfInt[ vrf ][ 'instList' ][ '1' ][ 'indices' ]: # Get the ifindex for the interface we are on for key, value in getIfIndex.items(): if key == interface: index = value # Get the key, value pairs for ospfv3 interface values for key,value in getIpv6OspfInt[ vrf ][ 'instList' ][ '1' ][ 'indices' ][ interface ].items(): # Check values and assigne OIDs if key == 'area': pp.add_ip( '1.2.' + str(index), value ) elif key == 'interfaceType': if value == 'broadcast': pp.add_int( '1.3.' + str(index), '1' ) elif value == 'nbma': pp.add_int( '1.3.' + str(index), '2' ) elif value == 'p2p': pp.add_int( '1.3.' + str(index), '3' ) elif value == 'p2mp': pp.add_int( '1.3.' + str(index), '5' ) elif key == 'priority': pp.add_int( '1.5.' + str(index), value ) elif key == 'retransmitInterval': pp.add_int( '1.7.' + str(index), value ) elif key == 'helloInterval': pp.add_int( '1.8.' + str(index), value ) elif key == 'deadInterval': pp.add_int( '1.9.' + str(index), value ) elif key == 'state': if value == 'down': pp.add_int( '1.11.' + str(index), '1' ) elif value == 'loopback': pp.add_int( '1.11.' + str(index), '2' ) elif value == 'waiting': pp.add_int( '1.11.' + str(index), '3' ) elif value == 'p2p': pp.add_int( '1.11.' + str(index), '4' ) elif value == 'dr': pp.add_int( '1.11.' + str(index), '5' ) elif value == 'backupDr': pp.add_int( '1.11.' + str(index), '6' ) elif key == 'designatedRouter': pp.add_ip( '1.12.' + str(index), value ) elif key == 'backupDesignatedRouter': pp.add_ip( '1.14.' + str(index), value ) elif key == 'options': for key, value in getIpv6OspfInt[ vrf ][ 'instList' ][ '1' ][ 'indices' ][ interface ][ 'options' ].items(): if key == 'multicastForwarding': if value == False: pp.add_int( '1.18.' + str(index), '0' ) if value == True: pp.add_int( '1.18.' + str(index), '1' ) elif key == 'cost': pp.add_int( '1.20.' + str(index), value ) def main(): global pp retry_counter = MAX_RETRY while retry_counter > 0: try: Logging.log( SNMP_EXTENSION, "snmp extension script starting" ) pp=snmp.PassPersist( OID_BASE ) pp.start( ospfIfTable, POLLING_INTERVAL ) # Handle possible errors starting the script except KeyboardInterrupt: Logging.log( SNMP_EXTENSION, "Exiting on user request" ) sys.exit( 0 ) except IOError, e: if e.errno == errno.EPIPE: Logging.log( SNMP_EXTENSION, "snmpd has closed the pipe" ) sys.exit( 0 ) else: Logging.log( SNMP_EXTENSION, "updater thread has died: %s" %e ) except Exception, e: Logging.log( SNMP_EXTENSION, "main thread has died %s: %s" % ( e.__class__.__name__, e ) ) else: Logging.log( SNMP_EXTENSION, "updater thread has died %s: %s" % ( e.__class__.__name__, e ) ) retry_counter -= 1 Logging.log( SNMP_EXTENSION, "too many retrys, exiting" ) sys.exit( 1 ) if __name__ == '__main__': main()

 

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: