-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget_bgp.py
53 lines (40 loc) · 1.24 KB
/
get_bgp.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
48
49
50
51
52
53
import requests
import urllib3
import sys
from tabulate import tabulate
# HOST = '172.16.30.68'
# PORT = '443'
# USER = 'cisco'
# PASS = 'cisco'
# HOST = 'ios-xe-mgmt.cisco.com'
# PORT = '9443'
# USER = 'root'
# PASS = 'D_Vay!_10&'
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def get_bgp():
url = "https://{h}:{p}/restconf/data/Cisco-IOS-XE-bgp-oper:bgp-state-data".format(h=HOST, p=PORT)
headers = {'Content-Type': 'application/yang-data+json',
'Accept': 'application/yang-data+json'}
response = requests.get(url, auth=(USER, PASS), headers=headers, verify=False)
return response.json()
# print(response)
def main():
neighbors = get_bgp()
# print(neighbors)
headers = ["Neighbor",
"LINK",
"UP-TIME",
"STATE",
"PfxRcd" ]
table = list()
for item in neighbors['Cisco-IOS-XE-bgp-oper:bgp-state-data']['neighbors']['neighbor']:
tr = [item['neighbor-id'],
item['link'],
item['up-time'],
item['connection']['state'],
item['prefix-activity']['received']['total-prefixes']]
table.append(tr)
# print(tr)
print(tabulate(table, headers, tablefmt="fancy_grid"))
if __name__ == '__main__':
sys.exit(main())