cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1320
Views
0
Helpful
1
Replies

APIC - Health score to find unused objects

Prakin
Level 1
Level 1

Hi,

Please help me to best python script to find out health score of APIC. i mean its not only to find the health score, as well need to find the unused objects, BD, EPG. e.g like if an policy group created, but no binded to the interface, in that case the health score will reduced or even if its bindied to the interface and the interface is not called on the EPG level, assume the health score will be reduced if i am not wrong. 

So i need to find out unused policies, bd, ebg etc. pls help here for python/XML script that run by using the postman tool help.

 

Br,

Prakin

1 Accepted Solution

Accepted Solutions

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi Prakin,

 

First I would like to say that your understanding of the object health is not accurate:


if an policy group created, but no binded to the interface, in that case the health score will reduced or even if its bindied to the interface and the interface is not called on the EPG level, assume the health score will be reduced

If you have unused objects of any kind, as long as there are no faults related to it, the object will not interfere with the fabric health score. The MO health score is affected by faults - in fact, is a combination between MO's faults weight and its children faults weight.

 

All these are used to calculate the fabric health score. If it helps in any way, here is the formula for fabric health:

  • HealthLeafi is the health score of the leaf switch.
  • WeightLeafi is the number of end-points on the leaf switch.
  • NLeaf is the number of leaf switches in the fabric.
  • HealthSpinei is the health score of the spine switch.
  • NSpine is the number of spine switches in the fabric.

 

Returning to your question, you are looking for 2 different scripts: 

  1. Returns Fabric health
  2. Returns unused objects

 

For the first one, a pretty simple script would be just using the requests module:

import json
import requests

# disable warning msg
requests.packages.urllib3.disable_warnings() 

base_url = 'https://apic-ip/api/'     

# create credentials structure
name_pwd = {'aaaUser': {'attributes': {'name': 'admin', 'pwd': 'password'}}}
json_credentials = json.dumps(name_pwd)

# log in to API
login_url = base_url + 'aaaLogin.json'
post_response = requests.post(login_url, data=json_credentials, verify=False)

# get token from login response structure
auth = json.loads(post_response.text)
login_attributes = auth['imdata'][0]['aaaLogin']['attributes']
auth_token = login_attributes['token']

# create cookie array from token
cookies = {}
cookies['APIC-Cookie'] = auth_token

# read a sensor, incorporating token in request
sensor_url = base_url + 'node/class/fabricHealthTotal.json'
get_response = requests.get(sensor_url, cookies=cookies, verify=False)
for mo in get_response.json()['imdata']:
	print('{}: {}'.format(mo['fabricHealthTotal']['attributes']['dn'],
						  mo['fabricHealthTotal']['attributes']['cur']))

For the second script, that might be a bit challenging as you will have to look through full MIT, or to specific classes/MOs which are relevant for you. I would recommend you use acitoolkit or cobra SDK. Have a look at the Cisco DevNet labs: https://developer.cisco.com/learning/tracks/aci-programmability 

 

Regards,

Sergiu

View solution in original post

1 Reply 1

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi Prakin,

 

First I would like to say that your understanding of the object health is not accurate:


if an policy group created, but no binded to the interface, in that case the health score will reduced or even if its bindied to the interface and the interface is not called on the EPG level, assume the health score will be reduced

If you have unused objects of any kind, as long as there are no faults related to it, the object will not interfere with the fabric health score. The MO health score is affected by faults - in fact, is a combination between MO's faults weight and its children faults weight.

 

All these are used to calculate the fabric health score. If it helps in any way, here is the formula for fabric health:

  • HealthLeafi is the health score of the leaf switch.
  • WeightLeafi is the number of end-points on the leaf switch.
  • NLeaf is the number of leaf switches in the fabric.
  • HealthSpinei is the health score of the spine switch.
  • NSpine is the number of spine switches in the fabric.

 

Returning to your question, you are looking for 2 different scripts: 

  1. Returns Fabric health
  2. Returns unused objects

 

For the first one, a pretty simple script would be just using the requests module:

import json
import requests

# disable warning msg
requests.packages.urllib3.disable_warnings() 

base_url = 'https://apic-ip/api/'     

# create credentials structure
name_pwd = {'aaaUser': {'attributes': {'name': 'admin', 'pwd': 'password'}}}
json_credentials = json.dumps(name_pwd)

# log in to API
login_url = base_url + 'aaaLogin.json'
post_response = requests.post(login_url, data=json_credentials, verify=False)

# get token from login response structure
auth = json.loads(post_response.text)
login_attributes = auth['imdata'][0]['aaaLogin']['attributes']
auth_token = login_attributes['token']

# create cookie array from token
cookies = {}
cookies['APIC-Cookie'] = auth_token

# read a sensor, incorporating token in request
sensor_url = base_url + 'node/class/fabricHealthTotal.json'
get_response = requests.get(sensor_url, cookies=cookies, verify=False)
for mo in get_response.json()['imdata']:
	print('{}: {}'.format(mo['fabricHealthTotal']['attributes']['dn'],
						  mo['fabricHealthTotal']['attributes']['cur']))

For the second script, that might be a bit challenging as you will have to look through full MIT, or to specific classes/MOs which are relevant for you. I would recommend you use acitoolkit or cobra SDK. Have a look at the Cisco DevNet labs: https://developer.cisco.com/learning/tracks/aci-programmability 

 

Regards,

Sergiu

Save 25% on Day-2 Operations Add-On License