Created
February 13, 2014 18:49
-
-
Save fredhsu/8981308 to your computer and use it in GitHub Desktop.
Example of polling an interface for statistics in eAPI and Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jsonrpclib import Server | |
import time | |
username = "fredlhsu" | |
password = "arista" | |
host = "172.22.28.37" | |
def getInterfaceStats(): | |
dictionary = eApiCall() | |
interfaces = [] | |
response = "" | |
for i in range(1,5): | |
name = "Ethernet{}".format(i) | |
intf = {"name":name, "stats":dictionary["interfaces"][name]["interfaceStatistics"]} | |
interfaces.append(intf) | |
return interfaces | |
def eApiCall(): | |
switch = Server( "http://{}:{}@{}/command-api".format(username, password, host)) | |
response = switch.runCmds( 1, ["show interfaces"] ) | |
return response[0] | |
if __name__ == '__main__': | |
sleepTime = 1 | |
while True: | |
time.sleep(sleepTime) | |
print getInterfaceStats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment