Skip to content

Instantly share code, notes, and snippets.

@markberly
Last active February 6, 2020 21:10
Show Gist options
  • Save markberly/6bf398697a7c4809ee72 to your computer and use it in GitHub Desktop.
Save markberly/6bf398697a7c4809ee72 to your computer and use it in GitHub Desktop.
Monitor an interface on an Arista Networks EOS powered switch (via Python and eAPI) and uses Growl to provide its status
#!/usr/bin/python
#
# Written by: Mark Berly
import argparse
from jsonrpclib import Server
from gntp.notifier import mini
intf2Monitor = "Ethernet 48"
# connect to the switch either via http or https
def connect( sIpOrHostname, username, password, secure=True ):
return Server( "%s://%s:%s@%s/command-api"
% ( "http" if not secure else "https", password, username, sIpOrHostname ) )
# collect MAC address table
def getintfInfo( switch, enablePass ):
rc = switch.runCmds( 1, [ { "cmd": "enable", "input": enablePass },
"configure",
"show interfaces %s" % intf2Monitor ] )
return rc[2]
def main():
# Create the command line parser / arguments
parser = argparse.ArgumentParser(description='Get MAC table information')
parser.add_argument( 'sIpOrHostname', help='Switch IP address or Hostname' )
parser.add_argument( 'username', help='Username' )
parser.add_argument( 'password', help='Password' )
parser.add_argument( "--http", help="Use unsecure http connection (default is https)",
action="store_false", default=True )
parser.add_argument( "--enable-password", help="Enable-mode password",
default="" )
args = parser.parse_args()
# connect to switch
switch = connect ( args.sIpOrHostname, args.username, args.password, args.http )
# Collect the mac address table
intfInfo = getintfInfo ( switch, args.enable_password )
intfDetails = intfInfo['interfaces']['Ethernet48']
linkChange = intfDetails['interfaceCounters']['linkStatusChanges']
intfStatus = intfDetails['interfaceStatus']
intfDesc = intfDetails['description']
update = 'Interface %s \nis: %s \nlink flaps: %s\nConnected to: %s' % ( intf2Monitor, intfStatus, linkChange, intfDesc )
mini(update)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment