Health Monitoring Guide
Introduction
Catalyst Center Intent APIs provide an easy way for the developer to get an overview of the network health and drill down if needed.
The APIs separate the information between wired and wireless clients, but also several health categories: good, fair, idle, among others.
Goal
The goals of this guide are:
- Get the site health.
- Get the network health.
- Get the devices health.
Endpoints and methods used
- POST
/dna/system/api/v1/auth/token
- GET
/dna/intent/api/v1/site-health
- GET
/dna/intent/api/v1/network-health
- GET
/dna/intent/api/v1/client-health
Prerequisites
For this guide, we recommend that the developer becomes familiar with authenticating to the Catalyst Center API.
Environment
This guide was developed using:
Authentication
First, we need to authenticate and retrieve a token from the API.
Notes: Do not use
verify=False
orurllib3.disable_warnings()
if you are not sure of its purpose. Read Authentication and Authorization.
import requests
from requests.auth import HTTPBasicAuth
import time
import urllib3
urllib3.disable_warnings()
BASE_URL = 'https://<IP Address>'
AUTH_URL = '/dna/system/api/v1/auth/token'
USERNAME = '<USERNAME>'
PASSWORD = '<PASSWORD>'
response = requests.post(BASE_URL + AUTH_URL, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False)
token = response.json()['Token']
headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
Site Health API
The Site Health API, part of the Sites API, provides the health status of every site (area and building) in Catalyst Center.
It is possible to obtain information about core, distribution and access network health, information about wired and wireless clients health and even application health.
SITE_HEALTH = '/dna/intent/api/v1/site-health'
response = requests.get(BASE_URL + SITE_HEALTH,
headers=headers, verify=False)
for site in response:
for site in response.json()['response']:
print('Site: {0}, Health: {1}'.format(site['siteName'], site['networkHealthAverage']))
Network Health
The Network Health API, part of the Topology API, retrieves network health information by device category: Access, Distribution, Core, Router, and Wireless.
NETWORK_HEALTH = '/dna/intent/api/v1/network-health'
response = requests.get(BASE_URL + NETWORK_HEALTH,
headers=headers, verify=False)
network_health = response.json()['response']
print('Good: {0}, Bad: {1}, Health score: {2}'.format(
network_health[0]['goodCount'], network_health[0]['badCount'],
network_health[0]['healthScore']
))
Clients health
Clients health is part of the Clients API. It returns the information by client type: wired and wireless. It displays the overall client count but it also it drills down showing details by category: poor, fair, good, idle, nodata, and new.
CLIENT_HEALTH = '/dna/intent/api/v1/client-health'
response = requests.get(BASE_URL + CLIENT_HEALTH,
headers=headers, verify=False)
response = get_client_health(headers)
clients_health = response.json()['response']
for score in clients_health[0]['scoreDetail']:
print('Type: {0}, Count: {1}, Score: {2}'.format(
score['scoreCategory']['value'],
score['clientCount'], score['scoreValue']))
try:
for category in score['scoreList']:
print('\tType: {0}, Count: {1}'.format(
category['scoreCategory']['value'],
category['clientCount']))
except:
pass
Code
The repository for this guide is here. The final code with functions appears as below.
# Modules import
import requests
from requests.auth import HTTPBasicAuth
import time
import sys
import pprint
pp = pprint.PrettyPrinter()
# Disable SSL warnings. Not needed in production environments with valid certificates
import urllib3
urllib3.disable_warnings()
# Authentication
BASE_URL = 'https://<IP Address>'
AUTH_URL = '/dna/system/api/v1/auth/token'
USERNAME = '<USERNAME>'
PASSWORD = '<PASSWORD>'
# URLs
SITE_HEALTH = '/dna/intent/api/v1/site-health'
NETWORK_HEALTH = '/dna/intent/api/v1/network-health'
CLIENT_HEALTH = '/dna/intent/api/v1/client-health'
# Get Authentication token
def get_dnac_jwt_token():
response = requests.post(BASE_URL + AUTH_URL,
auth=HTTPBasicAuth(USERNAME, PASSWORD),
verify=False)
token = response.json()['Token']
return token
# Get site health
def get_site_health(headers):
response = requests.get(BASE_URL + SITE_HEALTH,
headers=headers, verify=False)
return response.json()['response']
# Get network health
def get_network_health(headers):
response = requests.get(BASE_URL + NETWORK_HEALTH,
headers=headers, verify=False)
return response.json()['response']
# Get client health
def get_client_health(headers):
response = requests.get(BASE_URL + CLIENT_HEALTH,
headers=headers, verify=False)
return response.json()['response']
def main():
# obtain the Catalyst Center Auth Token
token = get_dnac_jwt_token()
headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
# Site health
print('Printing site health...')
response = get_site_health(headers)
for site in response:
print('Site: {0}, Health: {1}'.format(site['siteName'], site['networkHealthAverage']))
# Network health
print('\nPrinting network health...')
response = get_network_health(headers)
print('Good: {0}, Bad: {1}, Health score: {2}'.format(
response[0]['goodCount'], response[0]['badCount'],
response[0]['healthScore']
))
# Client health
print('\nPrinting client health...')
response = get_client_health(headers)
for score in response[0]['scoreDetail']:
print('Type: {0}, Count: {1}, Score: {2}'.format(
score['scoreCategory']['value'],
score['clientCount'], score['scoreValue']))
try:
for category in score['scoreList']:
print('\tType: {0}, Count: {1}'.format(
category['scoreCategory']['value'],
category['clientCount']))
except:
pass
if __name__ == "__main__":
main()