03-16-2020 03:04 AM
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
Solved! Go to Solution.
03-21-2020 10:22 AM - edited 03-21-2020 10:24 AM
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:
Returning to your question, you are looking for 2 different scripts:
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
03-21-2020 10:22 AM - edited 03-21-2020 10:24 AM
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:
Returning to your question, you are looking for 2 different scripts:
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide