This application aims to provide a simple integration of the Cisco DNA-Center APIs with Cisco WebEx-Teams's Bot. The Bot provides a chat like interface to give visibility into your network to run some basic commands and see the result right on the Chat Space (Desktop and Mobile Client)
1.Python3 2.Requirements pip install -r requirements.txt
https://developer.webex.com/bots.html
To register a Bot, you’ll need to be logged in to WebEx For-Developers Page with a “real” user – each bot needs to be tied to an actual user account. Adding one is extra simple, On the page, select “Create a Bot”; there’s only a couple fields to fill out
Display Name is how you want the bot to show up in a room (like “bot-a-dna”); Bot Username is the email address, since every Spark user is registered under an email – this should be similar to the Display Name, but it can be unique. Note that you are not populating the entire email – they will always end with @sparkbot.io, can’t make on with a gmail.com email or anything similar, so you’re just adding the prefix. The username prefix does need to be unique; if you don’t get a green check at the end of the @sparkbot.io reference, then the username was already taken. The Icon is the avatar for the bot, which will also show inside a room.
Once the bot is created, you’ll need to save the access token that is provided – keep it someplace safe. The token effectively never expires (it’s good for 100 years) but if you forget it, you’ll have to generate a new one. There’s no way to get it back.
Your webhook URL needs to be accessible on the public Internet – if you want to use your local machine, you can use a service like Ngrok to make your personal machine accessible to the world on a specific port for free.
But that means the webhook only works when you machine is up and live.
Once you have an endpoint to use, create the webhook using the request on this page. https://developer.ciscospark.com/endpoint-webhooks-post.html
Make sure that the bearer token used in creating the webhook is the bearer token of the bot. You’ll need to know the ‘roomId’ of the room the bot is hanging out in, and you’ll need to know your own ‘targetUrl’ (the Ngrok link etc.); you’ll also want to set the ‘resource’ to messages and the ‘event’ to created. Here’s what the Webhook should look like once it’s been created:
{
"items": [
{
"id": "<Bearer-Token>",
"name": "botaDna",
"targetUrl": "http://b4bcf212.ngrok.io",
"resource": "messages",
"event": "created",
"orgId": "Y2lzY29zcGFyazovL3VzL09SR0FOSVpBVElPTi8xZWI2NWZkZi05NjQzLTQxN2YtOTk3NC1hZDcyY2FlMGUxMGY",
"createdBy": "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9lZTY1ZTZiMC1kNzU2LTQxZWMtYjg3MC1hOTNkMjY3OTBhMDk",
"appId": "Y2lzY29zcGFyazovL3VzL0FQUExJQ0FUSU9OL0MyNzljYjMwYzAyOTE4MGJiNGJkYWViYjA2MWI3OTY1Y2RhMzliNjAyOTdjODUwM2YyNjZhYmY2NmM5OTllYzFm",
"ownedBy": "creator",
"status": "active",
"created": "2018-05-11T05:37:18.828Z"
}
]
}
git clone https://github3.cisco.com/amthyaga/app-dev-dnac-sparkbot.git
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
bearer = "YjExN......."
bot_email = 'bot-my-email@sparkbot.io'
bot_name = "bot-my-name"
cd server
python3 botADna.py
Common commands:
Greets the user and says what next could he do to connect to a cluster to start seeing his network data
<ip>
,<username>
,<password>
To connect to a cluster to see its data
Get a simple site health chart of Healthy vs. Unhealthy Devices and Client ,Network Health Charts
Get a detailed info per site on the healthy clients, healthy devices etc.
Get a list of network devices - Name and MAC Address
<deviceName>
Get latest detailed information about one device
<MAC Address>
Get latest detailed information about a client
Get the list of commands supported
Logout of the cluster connection. Need to login again to run the commands
APIs used in this code:
GET /dna/intent/api/v1/site-hierarchy?timestamp=1527103419000 header:{'__runsync': 'true'}
GET /dna/intent/api/v1/network-device-detail?timestamp=1527103419000&searchBy=Starbucks-AP1&identifier=nwDeviceName header:{'__runsync': 'true'}
GET /api/v1/network-device
GET /dna/intent/api/v1/client-detail?timestamp=1527103419000&macAddress=11:22:33:44:55:11 header:{'__runsync': 'true'}