-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalyst_center_site_health.py
46 lines (39 loc) · 1.51 KB
/
catalyst_center_site_health.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
import json
import requests
from catalyst_center_utils import get_auth_token, get_site_count
from config import BASE_URL, USERNAME, PASSWORD, SSL_VERIFY
def main():
"""
Returns site health information from Catalyst Center.
"""
# Get authentication token
token = get_auth_token(BASE_URL, USERNAME, PASSWORD)
total_sites = get_site_count(BASE_URL, token)
all_sites = [] # List to store all devices from all pages
for counter in range(1, -(-total_sites // 50) + 1):
devices_url = f"{BASE_URL}/dna/intent/api/v1/site-health?limit=50&offset=" + str(counter)
headers = {
"X-Auth-Token": token,
"Content-Type": "application/json",
}
try:
response = requests.get(
devices_url,
headers=headers,
verify=SSL_VERIFY,
timeout=60
)
response.raise_for_status()
page_devices = response.json()
# Append the devices from this page to our list of all devices
if 'response' in page_devices:
all_sites.extend(page_devices['response'])
else:
print(f"Unexpected response structure on page {counter}")
except requests.exceptions.RequestException as e:
print(f"Error fetching devices on page {counter}: {e}")
# Continue to the next iteration instead of exiting
continue
print(json.dumps(all_sites, indent=4))
if __name__ == "__main__":
main()