Playing with Cisco DNA Center APIs
Hello this is my first blog, today we are going to talking about how we can use Cisco DNA Center APIs with DNA Center Platform.
Before we start let’s take a quick look what is Cisco DNA Center?
Cisco DNA Center is a network controller for intent-based networking infrastructure which is more than completed network management systems but also being a network controller for a Software-Defined Access (SDA), Assurance with AI Analytics and provide a centralize platform for a network programmability which we will discussing today.
As I was mentioned earlier DNA Center Platform provide an APIs interface called ‘Intent APIs’ which included rich set of APIs such as automation, assurance, notification and more with APIs documentation in one box.
How do we start?
Firstly we need to authentication as a normal user but something different here,
Normally when we login to DNA Center we must provide a username & password right?
For a programmability perspective we do the same to get something called ‘Token” because DNA Center APIs use a token-based authentication to authorize any APIs requested.
But how can I get that token? please follow these steps below:
- Go to DNA Center Platform workflow -> Developer Toolkits -> APIs
- Looking for an Authentication section -> Authentication APIs
- Inside Authentication APIs you will find a path to obtain an access token with “POST” method like this https://<dna center ip address/dna/system/api/v1/auth/token
Let’s try it with Postman.
What next? Let try it out with our first API call to get a network devices from DNA Center inventory
- Copy this URI and paste into Postman with “GET” method
https://<dna center ip address>/api/v1/network-device - In the “Headers” tab set a “X-Auth-Token” as a key and paste a token from the previous task into a “VALUE” and then click “Send”
- You’ll see a returning JSON value within the “Body” tab
My last section of this blog I will talking about
“Event Notification via Webhook.”
With the power of APIs we can do some important thing more than email notification when we need to notify someone when something’s wrong within our network infrastructure, DNA Center can provide a notification method called “Webhook”.
How is it work?
Cisco DNA Center Platform provide a webhook notification with the event subscription. You can subscribe any event which you are interested to send a notify and then when the event occurring DNA Center will send a notify of that event to your webhook server.
Let’s take a look at my use case.
In my lab I subscribed an event called “ISIS Adjacency Failure” with this event DNA Center will sending a notify to my webhook server when this event has been detected let’s take a look into my lab diagram as following:
As my lab diagram I’ll used a DNA Center to “POST” an event to my webhook server (created by Python) to receive an event data from DNA Center which is deployed on Heroku (PaaS) to structure a message from JSON before sending a “POST Event” to LINE Notify.
Please do follow these steps to subscribe an event to create a webhook notification:
- Go to DNA Center Platform workflow -> Developer Toolkits -> Events
- Looking for the events which you are interested or in my case I subscribed the “Network Device Interface Connectivity — ISIS Adjacency Failure”
- Click into the event -> Active Subscription -> Subscribe
- Assign a name of the subscription and provide a URL of your webhook server
- Selected HTTP Method to “POST” -> Click Subscribe
Done!!
Let’s see what happened.
I shut down the interface G1/0/5 which IS-IS running as you can see an IS-IS adjacency going into down state as below picture
DNA Center send notify to my webhook server as below log from Heroku but as you can see the system POST a full JSON data (RAW Data) to my webhook server that very difficult to read therefore I used my python script to filtered a string before POST this message to LINE notification
The webhook server “POST” a message from DNA Center to LINE notify as below picture:
Everything done, pretty easy right?
I hope this blog will give you some idea around how you can leverage DNA Center APIs to develop and create something new on this platform.
You can also explore Cisco DevNet site: https://developer.cisco.com for a FREE hands-on lab, community and more use case on Cisco SDx world and network programmability.
Thank you for reading.
See you next time!!
Jirapat Srimarut