This repository has been archived by the owner on Jul 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit_all_states.py
48 lines (42 loc) · 1.85 KB
/
audit_all_states.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import yaml
import os
from jsonrpclib import Server
import time
username = "arista"
password = "arista"
# Devices inventory
inventory_f=open('inventory.yml', 'r')
inventory_s=inventory_f.read()
inventory_f.close()
inventory=yaml.load(inventory_s, Loader=yaml.FullLoader)
# Printing some details regarding the devices
for device in inventory:
print ('-'*60)
print ('Printing some details regarding the device ' + device)
ip = inventory[device]['ip']
url = "http://" + username + ":" + password + "@" + ip + "/command-api"
switch = Server(url)
result=switch.runCmds(version=1,cmds=["sh ver"], format='json', autoComplete=True)
print('model is ' + result[0]['modelName'])
print('version is ' + result[0]['version'])
# auditing the devices
print ('-'*60)
print ('audit will start in 15 seconds ...')
time.sleep(5)
print ('audit will start in 10 seconds ...')
time.sleep(5)
print ('audit will start in 5 seconds ...')
time.sleep(5)
# auditing all BGP neighbors configured on all the devices (i.e we use the devices configuration as a SoT)
for device in inventory:
print ('-'*60)
print ('Auditing all BGP neighbors configured on the device ' + device)
print ('i.e we are currently using the device configuration as a SoT')
ip = inventory[device]['ip']
url = "http://" + username + ":" + password + "@" + ip + "/command-api"
switch = Server(url)
result=switch.runCmds(version=1,cmds=["show ip bgp neighbors"])
for item in result[0]['vrfs']['default']['peerList']:
print ("the BGP session with " + item['peerAddress'] + " is " + item['state'])
print ("the number of IPv4 prefixes sent to the BGP neighbor " + item['peerAddress'] + " is " + str(item['prefixesSent']))
print ("the number of IPv4 prefixes received from the BGP neighbor " + item['peerAddress'] + " is " + str(item['prefixesReceived']))