Showing results for 
Search instead for 
Did you mean: 

POC: Catalyst 9000 Sandbox integration with Spark.


In this post I would like to explain how to create a small POC together with a Spark bot and the Devnet Sandbox IOS XE on Catalyst 9000.

In this POC you will be able to showcase 2 main concepts:

  1. How Catalyst 9000 Guestshell works.
  2. How to integrate a Catalyst 9000 with Spark and begin a ChatOps model in your orgranization.

1) Reserve a Sandbox.

Go to the following link and reserve a IOS XE on Catalyst 9000 sandbox to work on. It may take around 10 minutes for the entire process to finish.

2) Create a Spark bot and write down bot's access token.

Go to and create a new bot. Click in My Apps > Create a Bot and later to the add new application:



Create the new Bot with relevant information and make sure you write down Bot's access token.


3) Prepare  Catalyst 9300 guestshell

  • Now it's time to connect to the Catalyst 9300 in the Devnet sandbox. Details of this step will be sent by email once the lab has been fully provisioned. Summary: Use Cisco AnyConnect to VPN towards the LAB Sandbox. If you need additional information on this step please check the following link

  • Connect to the Catalyst 9300 terminal with the right credentials shared in the Sandbox main page. Cat9300 management IP: Credentials admin/ciscopsdt

mylaptop:~ laptop$ ssh admin@           

  • Enable Guestshell in Catalyst 9300 with the following commands:

>cat9300-2#guestshell enable

Management Interface will be selected if configured

Please wait for completion

guestshell is in RUNNING state


[guestshell@guestshell ~]$

  • IF above commands didn't work and guesthsell bash is not presented, you will need to destroy current guestshell and configure a new one. Do the following steps only if previous step didn't work.

>cat9300-2#guestshell destroy

Guestshell destroyed successfully

>cat9300-2#guestshell enable

Management Interface will be selected if configured

Please wait for completion

Guestshell enabled successfully


[guestshell@guestshell ~]$

  • Now that we have the Python guestshell running without any issue is time to update some repositories, libraries and configurations to be able to install and run Spark API and Spark scripts without any problem.

First we need to update the DNS configuration with a proper DNS server to resolve DNS queries. Let's use OpenDNS::

[guestshell@guestshell ~]$ sudo echo "nameserver" | sudo tee --append /etc/resolv.conf


Following, we need to update repositories, libraries and needed tools. Make sure you type "yes / y" when asked and allow the installation of needed packages.  (You can ignore some of the errors presented when installing different modules)

[guestshell@guestshell ~]$ sudo yum update



[guestshell@guestshell ~]$ sudo pip install --upgrade pip


Successfully installed pip-10.0.0

[guestshell@guestshell ~]$ sudo pip install -U setuptools


Successfully installed setuptools-39.0.1

Now that we have the guestshell ready we can install Cisco Spark API:

[guestshell@guestshell ~]$ sudo -E pip install ciscosparkapi


Successfully installed certifi-2018.1.18 chardet-3.0.4 ciscosparkapi-0.10 future-0.16.0 idna-2.6 requests-2.18.4 requests-toolbelt-0.8.0 urllib3-1.22

  • After this steps we have the guestshell ready to run python scripts using the CiscoSparkApi.

4) Run first python script and test SparkBot

With the guestshell ready it's time to try a script.  (( Thanks @HaroldPreston for putting this together in your post ))

  1. from ciscosparkapi import CiscoSparkAPI 
  3. if __name__=='__main__'
  4.     # Use ArgParse to retrieve command line parameters. 
  5.     from argparse import ArgumentParser 
  6.     parser = ArgumentParser("Spark Check In"
  7.     # Retrieve the Spark Token and Destination Email 
  8.     parser.add_argument( 
  9.         "-t", "--token", help="Spark Authentication Token", required=True 
  10.     ) 
  11.     # Retrieve the Spark Token and Destination Email 
  12.     parser.add_argument( 
  13.         "-e", "--email", help="Email to Send to", required=True 
  14.     ) 
  15.     args = parser.parse_args() 
  16.     token = args.token 
  17.     email = 
  18.     message = "**Alert:** Config Changed" 
  19.     api = CiscoSparkAPI(access_token=token) 
  20.     api.messages.create(toPersonEmail=email, markdown=message) 

We need to create a .py file with the above code in order to be executed by the guestshell and reach to Spark. In this example we will create ""

1) COPY the script text above: select the text, right click copy

2) Create new file, for example Let's use here for example the vi editor:

[guestshell@guestshell ~]$ sudo vi

3) Once you enter vi, press "i" to get into insert mode, right click into terminal, click paste.

4) Press key ESC and type :wq! then press ENTER to save all the document.



"" [New] 20L, 780C written

[guestshell@guestshell ~]$

At this point we should have our "" in the Catalyst 9300 guestshell. We can verify it by typing any of the commands below:

[guestshell@guestshell ~]$ ls

[guestshell@guestshell ~]$ cat

from ciscosparkapi import CiscoSparkAPI

if __name__=='__main__':

    # Use ArgParse to retrieve command line parameters.

    from argparse import ArgumentParser

    parser = ArgumentParser("Spark Check In")

    # Retrieve the Spark Token and Destination Email


        "-t", "--token", help="Spark Authentication Token", required=True


    # Retrieve the Spark Token and Destination Email


        "-e", "--email", help="Email to Send to", required=True


    args = parser.parse_args()

    token = args.token

    email =

    message = "**Alert:** Config Changed"

    api = CiscoSparkAPI(access_token=token)

    api.messages.create(toPersonEmail=email, markdown=message)

Now that the script is in the guestshell is time to run it and verify that is working:

sudo python -t "Bot's access token." -e "our email where spark is enabled"

For example:

[guestshell@guestshell ~]$ sudo python -t ZjZjMTkxY2ItYTUxNy00MGJjLTg1MDEtNzQ5MzgyOWEyOTcwZjM0NmE2NzItNDI2 -e

As a result we should see a Spark notification from our Bot:


At this point we have validated that the Catalyst9300 guesthsell is able to send messages to our Spark account using the Bot created previously.  

5) Using the script as an action after Cisco Embedded Event Manager (EEM) event.

With the script working, now we will make the Catalyst 9300 to execute the script and send a message over Spark every time a Syslog Message related to a configuration change is issued. For this, we will use above script as an action to a EEM event.

(( Thanks again @HaroldPreston for putting this together in your post ))

First we need to exit the guestshell

[guestshell@guestshell ~]$ exit



Now we configure the EEM:

cat9300-2#config t

cat9300-2(config)#event manager applet testapplet

cat9300-2(config-applet)#event syslog pattern "%SYS-5-CONFIG_I: Configured from"

cat9300-2(config-applet)#action 0.0 cli command "en"

cat9300-2(config-applet)#action 1.0 cli command "guestshell run python -t ZjZjMTkxY2ItYTUxNy00MGJjLTg1MDEtNzQ5MzgyOWEyOTcwZjM0NmE2NzItNDI2 -e"



With this every time there is a system configuration change syslog message the EEM will run the script in the guestshell and this notify us over spark of a configuration change.

Be aware that EEM event pattern support regex so you could potentially match any type of variable in the syslog messages using the exact same approach as above.

Cisco Employee

Great example of using DevNet Sandbox, Cat 9K and Spark APIs for some ChatOps action! Love it!


Thanks for your contribution, Charles!  We've added your POC/post as a example within the instructions of the IOS XE on Catalyst 9000 lab. 

Attempting the transition from learning Labs to sandbox.  Tried other Labs without success.  Everything spelled out in this Lab (and I have Cisco Spark).  Thanks for being so thorough, I can now attempt the other labs.

Cisco Employee

Thanks Dave; happy to help

CreatePlease to create content
Content for Community-Ad
Cisco Community May 2020 Spotlight Award Winners
This widget could not be displayed.