Cisco IOS-XE Show Version Command Reimagined as a pyATS job that creates CSV / MD / HTML; sends #chatbot messages; and generates MP3 using Google Cloud TTS #voice
This code takes the original idea of a modern show interface status and then adds #chatbots, #voicebots, and even #dialbots to finish the modernization. https://developer.cisco.com/codeexchange/github/repo/automateyournetwork/Modern_Show_Interfaces_Status
Install pyATS
pip install pyats[full]
Update the testbed file to reflect your devices. The example uses a 3850
Ensure SSH connectivity and run the pyATS job
pyats run job Modern_Show_Version_job.py --testbed-file ../testbed/3850.yaml
Follow these guides to setup your bot
Cisco WebEx REST API Basics
https://developer.webex.com/docs/api/basics
Cisco WebEx Webhooks
https://developer.webex.com/docs/api/guides/webhooks
Practically Speaking; Login to the WebEx Developer Portal with your Cisco DevNet or CCO Account
https://developer.webex.com/my-apps
Create an Application
Then test the application using the following portals in your browser
First get the list of WebEx Teams you are a part of
https://developer.webex.com/docs/api/v1/teams
Then get the Rooms that in these Teams
https://developer.webex.com/docs/api/v1/rooms
Finally you can explore the messages in that room, including how to POST a message
https://developer.webex.com/docs/api/v1/messages
To see all current messages you can also use
https://developer.webex.com/docs/api/v1/messages/list-messages
Make sure you modify the following lines of code
In the Python
webex_response = requests.post('https://webexapis.com/v1/messages', data=output_from_parsed_webex_template, headers={"Content-Type":"application/json", "Authorization": "Bearer {{ your bearer token here }} "})
Replace the {{ your bearer token here }} with your API token from the Bot or your account
In the Jinja2 template also update your roomId
{
"roomId": "{{ your room ID here }}",
"text": "This is being sent from pyATS..."
}
This is an example of the show version command sending a message to the #pyATS WebEx Community:
Follow this guide to setup your bot
Setup a Discord Application and create a Webhook
https://discord.com/developers/applications
Replace the Webhook in this line of code with your Discord Webhook
discord_response = requests.post('https://discord.com/api/webhooks/{{ your webhook here }}', data=output_from_parsed_discord_template, headers={"Content-Type":"application/json"})
Discord Developer Portal
https://discord.com/developers/docs/intro
Discord Webhook Reference
https://discord.com/developers/docs/resources/webhook
Follow this guide to setup your Slackbot
First configure your Slack App
https://api.slack.com/apps?new_app=1
Follow the Slack Webhook guide
https://api.slack.com/messaging/webhooks
In the Python update the following line
slack_response = requests.post('https://hooks.slack.com/services/{{ your webhook here }}', data=output_from_parsed_slack_template, headers={"Content-Type":"application/json"})
Replacing {{ your webhook here }} with your Slackbot Webhook
Follow the brief introduction guide to the TTS service
https://cloud.google.com/text-to-speech
Go to your Google Cloud Console and configure the service.
https://console.cloud.google.com/
For this to work you need to setup what is called a Service Account under the API Credentials sub-menu.
https://cloud.google.com/iam/docs/creating-managing-service-account-keys
https://cloud.google.com/iam/docs/service-accounts?_ga=2.180954017.-780071125.1615085699
Generate a key under your service account which will automatically down a JSON file.
You need to save this JSON file somewhere on the host running the Python and set the following environment variable
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Follow the brief introduction to Twilio
https://www.twilio.com/docs/libraries/python
Update the Python with your Account SID and Account Token
account_sid = "{{ account SID }}"
auth_token = "{{ token }}"
Also then update the URL to your MP3 file, the number to call, and the number you are calling from. You first need to register these numbers if you are using the Twilio trial
call = client.calls.create(
url='{{ MP3 File location }}',
to='{{ number to call }}',
from_='{{ number calling from }}'
Review your output files. You should have 3 files in the output folder:
Text files:
show_version_csv.csv
show_version_md.md
show_version_html.html
Audio files - generated from a real 3850 using a fictitious hostname and serial number (everything else is real information):
show_version_google_tts_eng.mp3
show_version_google_tts_fr.mp3
show_version_google_tts_greek.mp3
Watch these videos for an introduction and live demo of the Merlin, Excalibur, and Lancelot features
What Is Network Automation using Infrastructure As Code?: https://www.youtube.com/embed/Wo6GmvwdSdY
Learn Genie Learn: https://youtu.be/-Ns5sGIKRPI
Powered by Genie
And the pyATS framework
Featuring
And now
Also
And for your Asset Management needs - introducting - Excalibur
Welcome!
Merlin is an infrastructure as code and network automation tool that transforms CLI command and REST API data, using the Cisco Genie parsers, the Cisco pyATS Python library, and Python to automatically generate, at scale, better documentation from the output; send #chatbots; #voicebots; even #phonebots!
Merlin First "Learns" the following features and protocols about the device:
Then Merlin runs multiple "show" commands and creates the following:
A Nice JSON file (command_output.json)
A Nice YAML file (command_output.yaml)
A CSV spreadsheet (command_output.csv)
A Markdown file (command_output.md)
An HTML page (command_output.html)
An interactive HTML Mind Map (command_output_mind_map.html)
An interactive HTML NETJSON NetGraph (command_output_netjson.html)
A TinyDB
Instant messages to WebEx, Slack, Discord, and others
Text-to-Speech, in over 200 languages, creating customized MP3 audio files in a human voice
Phone calls to any phone number in the world
Instantly. With the push of a button.
If you are here for the Excalibur utility please follow this guide
Excalibur - Automated Asset Management
The main Genie documentation guide:
https://developer.cisco.com/docs/genie-docs/
The main pyATS documentation guide:
https://developer.cisco.com/docs/pyats/
The Cisco's Test Automation Solution
The Cisco Test Automation GitHub repository
https://github.com/CiscoTestAutomation
Here are the pyATS documentation guides on Testbed files and Device Connectivity:
Testbed and Topology Information: https://pubhub.devnetcloud.com/media/pyats/docs/topology/index.html
Device Connection: https://pubhub.devnetcloud.com/media/pyats-getting-started/docs/quickstart/manageconnections.html
Testbed File Example: https://pubhub.devnetcloud.com/media/pyats/docs/topology/example.html
Device Connections: https://developer.cisco.com/docs/pyats/#!connection-to-devices
Secret Strings (how I encrypted the enable secret in my testbed file): https://pubhub.devnetcloud.com/media/pyats/docs/utilities/secret_strings.html
Requirements (instructions below)
Virtual Environment
We recommend running Merlin in a Python virtual environment while testing or developing. This will help keep your host system clean and allow you to have multiple environments to try new things. If you are not using a virtual environment, start at the download/clone step below.
You will also need Python 3, pip, and venv installed on your host system.
In your project directory, create your virtual environment
python3 -m venv env
Activate (use) your new virtual environment (Linux):
source env/bin/activate
Download or clone the Merlin repository:
git clone https://github.com/automateyournetwork/merlin
Install pyATS, Rich, markmap, netjsongraph, xmltodict and TinyDB into your environment:
pip install -r requirements.txt
sudo apt update
sudo apt install npm
sudo npm install markmap-cli -g
npm install netjsongraph.js --save
If you run into any installation issues with pyATS, please see the installation guide here: https://pubhub.devnetcloud.com/media/pyats-getting-started/docs/install/installpyATS.html
When you are finished with your Merlin session, enter the deactivate
command to exit the python virtual environment.
How to update the appropriate testbed/testbed_*.yaml
file to reflect your device inventory and configuration:
Devices:
4500: <-- Update to your router hostname (MUST MATCH HOSTNAME)
alias: <-- Update your alias; this can be the hostname or any friendly name you want
type: <-- This should be "router" for L3 routers with ARP tables and VRFs and such
platform: <-- Your Catalyst IOS-XE Platform
username: <-- Your Cisco device username
password: <-- Your Enable Secret; It is strongly recommended to follow the "Secret Strings" link to encrypt your secrets
ip: <-- The management IP address of your router
Copy & Paste and make each device unique to scale this up to many routers
Devices:
3850: <-- Update to your switch hostname (MUST MATCH HOSTNAME)
9300: <-- Update to your switch hostname (MUST MATCH HOSTNAME)
alias: <-- Update your alias; this can be the hostname or any friendly name you want
type: <-- This should be "switch" for L2 switches without ARP tables or VRFs but features like PoE
platform: <-- Your Catalyst IOS-XE Platform
username: <-- Your Cisco device username
password: <-- Your Enable Secret; It is strongly recommended to follow the "Secret Strings" link to encrypt your secrets
ip: <-- The management IP address of your router
Copy & Paste and make each device unique to scale this up to many routers
Merlin now connects to the following Cisco.com APIs:
Recommended Software Release (using the real version of software from your devices)
Serial Number 2 Infomation (using the real serial numbers, for every part, from your devices)
Product Security Incident Response Team (PSIRT) (using the real version of software from your device)
Merlin now supports the Cisco Identity Services Engine (ISE) External RESTful Service (ERS) and Monitoring and Troubleshooting (MnT) APIs !
You can create a testbed file using an Excel spreadsheet (see testbed/SampleTestbedFile.xlsx
), this is useful if you are not familiar with YAML and/or have a long list of devices where copying and pasting in Excel would be easier.
Edit the relevant fields in the sample file.
Run the following command:
pyats create testbed file --path SampleTestbedFile.xlsx --output my_testbed.yaml
Ensure SSH connectivity at from your host's CLI, and run the pyATS job:
Cisco IOS-XE:
pyats run job IOS_XE_merlin_job.py --testbed-file testbed/testbed_ios_xe.yaml
Cisco DevNet Sandbox for CSR1000v (see more here)
pyats run job DevNet_Sandbox_CSR_merlin_job.py --testbed-file testbed/testbed_DevNet_CSR1000v_Sandbox.yaml
Cisco ISE:
pyats run job pyats run job ISE_merlin_job.py
JunOS 17 / 18 / 19:
pyats run job JUNOS_merlin_job.py --testbed-file testbed/testbed_juniper.yaml
F5 BIG-IP:
python3 F5_merlin.py
cd Camelot
ls
To view the pyATS log in a web browser Locally
pyats logs view
To view the pyATS log in a web browser remotely
pyats logs view --host 0.0.0.0 --port 8080 -v
Here is an example of just one of the treasures you will find: the show ip route
command!
Here is what a Global Routing Table looks like in JSON:
The same routing table, but in YAML:
The JSON and YAML outputs are incredible representations of the routing table and can be used for further pyATS testing or data modeling.
"Business-ready" documentation includes the incredibly powerful and versatile Comma-Separated Values (csv) spreadsheet format.
Markdown, the format this README file is written in, can also be used to express the data in a lightweight format that renders nicely in modern browsers.
What about a full-blown HTML webpage? Merlin also creates at least one of these per command.
Which renders nicely like this in your browser:
Another HTML page, an interactive mindmap, is also created from the Markdown file!
Another Interactive HTML page, this time a NETJSON NetGraph, is also crteated
To launch a Python web server and make Camelot available in a browser, where you can view the HTML pages:
Launch a local web server available on the same host:
cd Camelot
pushd; python3 -m http.server --bind 127.0.0.1 8888; popd;
Launch your web browser and visit
Launch a local web server available to remote hosts:
cd Camelot
pushd; python3 -m http.server --bind 0.0.0.0 8888; popd;
Launch your web browser and visit
http://{{ your server IP }}:8888/
Every artifact can also be uploaded dynamically to a Sharepoint 2016 Document Library !
The CSV files work with the Office extension and present as version controlled Excel-online files!
Add the code from the SharePoint2016_Plugin.py file. The show version command is used in the example.
Simply add the SHAREPOINT code, updating to reflect the appropriate command:
#Enter your SharePoint site and target library
APIs:
inventory:
sharePointUrl: 'https://{{ mydomain.com }}'
folderUrl: '/Inventory'
sharePointFileName: "Inventory/Inventory.csv"
uploadFileName: "Inventory.csv"
sharepoint_domain: mydomain
sharepoint_user: {{ domain_user_name }}
sharepoint_password: {{ domain_password }}
contracts:
sharePointUrl: 'https://{{ mydomain.com }}'
folderUrl: '/Inventory'
sharePointFileName: "Inventory/Contracts.csv"
uploadFileName: "Contracts.csv"
sharepoint_domain: mydomain
sharepoint_user: {{ domain_user_name }}
sharepoint_password: {{ domain_password }}
Test Merlin using the Cisco DevNet IOS-XE Sandbox
Test Merlin using the Cisco DevNet Nexus 9k Sandbox
Test Merlin using the Cisco DevNet Identity Services Engine 3.0 + pxGrid Sandbox
Cisco IOS-XE:
learn ACL
learn ARP
learn BGP
learn CONFIG
learn Dot1X
learn Interface
learn LLDP
learn NTP
learn OSPF
learn Routes
learn STP
learn VLAN
learn VRF
show access lists
show access session
show access session interface {{ interface }} detail
show authentication sessions
show authentication session interface {{ interface }} detail
show cdp neighbors
show cdp neighbors details
show environment all
show etherchannel summary
show interfaces
show interfaces status
show interfaces trunk
show inventory
show ip arp
show ip arp vrf {{ vrf }}
show ip interface brief
show ip ospf
show ip ospf database
show ip ospf interface
show ip ospf neighbor
show ip ospf neighbor detail
show ip route
show ip route vrf {{ vrf }}
show issu state detail
* 4500X IOS-XE in VSS
show mac address-table
show ntp associations
show power inline
show version
show vlan
show vrf
Cisco NXOS:
learn ACL
learn ARP
learn BGP
learn CONFIG
learn Dot1X
learn Interface
learn LLDP
learn NTP
learn OSPF
learn PLATFORM
learn Routes
learn STP
learn VLAN
learn VRF
show access lists
show bgp process VRF all
show bgp sessions
show interfaces status
show inventory
show ip arp
show ip arp vrf {{ vrf }}
show ip interface brief
show ip ospf
show ip route
show ip route vrf {{ vrf }}
show mac address-table
show version
show vlan
show vrf
show vrf all detail
show vrf all interface
Cisco Identity Services Engine (ISE)
External RESTful Service (ERS) APIs
Administrators
Allowed Protocols
Authorization Profiles
downloadable/dynamic Access Control Lists (dACLs)
Endpoint Groups
Identity Groups
Network Devices
Monitoring and Troubleshooting (MnT) APIs
Total Active Sessions
Active Sessions
MAC Session Details
JunOS:
show chassis hardware
show system information
F5 BIG-IP
/mgmt/tm/ltm/virtual
/mgmt/tm/sys/file/ssl-cert
Tested on:
Cisco:
Cisco Catalyst 4500X-16 03.11.03a.E
Cisco Catalyst 9300-48UXM Gibraltar
Cisco Catalyst 9200-24P 16.12.03 and 17.03.02a
Cisco Catalyst 3850-12X48U Gibraltar 16.12.04
Cisco CSR1000v
Cisco IOSv
Cisco vISE 2.7
Juniper:
JunOS 17, 18, 19
F5:
i2600 REST API
Owner
Contributors
Categories
Products
WebexpyATSIOS XECatalyst CenterCatalyst SD-WANProgramming Languages
HTMLLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community