cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
517
Views
0
Helpful
5
Replies

Create Profile Rule - Cisco DNAC API

ryanmbess
Level 1
Level 1

Can someone provide me some sample code in python to create a simple Profile Rule within DNAC via the api.  I'm following this and it's not working

 

https://developer.cisco.com/docs/dna-center/#!create-a-profiling-rule

5 Replies 5

ModernCyber
Level 1
Level 1

Good News, it is right on the link you sent on the right side of the screen. Did you already try and you are getting errors? If so, can you share?

 

Another tip is to perform a GET of existing content to help you understand the formatting.

 
 

PythonDevNet.jpg

 

 

import requests

url = "https:///dna/intent/api/v1/endpoint-analytics/profiling-rules"

payload = '''{
"ruleId": null,
"ruleName": null,
"ruleType": "Cisco Default - Static",
"ruleVersion": null,
"rulePriority": null,
"sourcePriority": null,
"isDeleted": null,
"lastModifiedBy": null,
"lastModifiedOn": null,
"pluginId": null,
"clusterId": null,
"rejected": null,
"result": {
"deviceType": [ null ],
"hardwareManufacturer": [ null ],
"hardwareModel": [ null ],
"operatingSystem": [ null ]
},
"conditionGroups": {
"type": "attr",
"condition": {
"attribute": null,
"operator": "equals",
"value": null,
"attributeDictionary": null
},
"operator": "and",
"conditionGroup": [ null ]
},
"usedAttributes": [ null ]
}'''

headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}

response = requests.request('POST', url, headers=headers, data = payload)

print(response.text.encode('utf8'))

 

 

Hey ModernCyber,

Yeah saw that....however i get a 500 back from DNAC.  Below is what i'm running

 

 

import requests


payload = '''{
"ruleId": null,
"ruleName": Rule123,
"ruleType": "Cisco Default - Static",
"ruleVersion": null,
"rulePriority": null,
"sourcePriority": null,
"isDeleted": null,
"lastModifiedBy": null,
"lastModifiedOn": null,
"pluginId": null,
"clusterId": null,
"rejected": null,
"result": {
"deviceType": [ null ],
"hardwareManufacturer": [ null ],
"hardwareModel": [ null ],
"operatingSystem": [ null ]
},
"conditionGroups": {
"type": "attr",
"condition": {
"attribute": null,
"operator": "equals",
"value": null,
"attributeDictionary": null
},
"operator": "and",
"conditionGroup": [ null ]
},
"usedAttributes": [ null ]
}'''

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"X-Auth-Token": "eyJhbGciOiJSUzI1NiIs"
}

response = requests.request('POST', url, verify=False, headers=headers, data = payload)

print(response.text.encode('utf8'))
 
 
 
This results in the below.
C:\Program Files\Python310\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'x.x.x.x. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
b'Http Error Code:500'
 
 
Thoughts?

I think see the issue.  If you log into our DNAC we're running 2.2.3.4.  In the developer toolkit site within DNAC there is a Policy section that has the "create a profiling rule".  However if you look at the link i provided first, and then pivot into the 2.2.3 api section, you'll see there's NO POLICY section.  I think you have to be running 2.3.3 to have this ability.  

yawming
Cisco Employee
Cisco Employee

For this post I doubt if we can do it from Document site. 

I suggest to reserve a DNAC sandbox to try or try it from your DNAC.

I tried from my DNAC I got 500 error too. I suspect there is a dependency there. 

I tried to do it from GUI (see link below from DNAC user guide) but found out that I don't have any endpoint.

 

https://www.cisco.com/c/en/us/td/docs/cloud-systems-management/network-automation-and-management/dna-center/2-3-3/user_guide/b_cisco_dna_center_ug_2_3_3/endpoint-analytics-1-0.html#Cisco_Task.dita_edd8d160-ead3-411e-8bdd-4a5a6ff0eb49

Glad it's not just me.  and yeah i tried to reserve one of their online labs but said it would take 2 months :).