|
| 1 | +# EEM Spark-CheckIn |
| 2 | + |
| 3 | +This example script sends a notification message to a Cisco Spark user of a Configuration Change. It was created to be used along with an EEM Applet that monitors for configuration changes, and then executes the script leveraging Python withing Guest Shell. |
| 4 | + |
| 5 | +This example was tested using IOS-XE 16.5.1b on an ISR 4K router, and on a Nexus 9000 7.0(3)I5(2) but should work on other platforms supporting Guest Shell. |
| 6 | + |
| 7 | +This example script uses the CiscoSparkApi Python library to send the Spark Message. |
| 8 | + |
| 9 | +You will need to provide the Spark Authorization Token and recipient email address within the EEM Configuration. It is recommended that you create a [Bot Account](https://developer.ciscospark.com/bots.html) for this use case. |
| 10 | + |
| 11 | +This script has been tested with Python 2.7, however may work with other versions. |
| 12 | + |
| 13 | + |
| 14 | +# Requirements and Setup |
| 15 | + |
| 16 | +## Host Device and Guest Shell |
| 17 | + |
| 18 | +IOS-XE or NX-OS device supporting Guest Shell and EEM. |
| 19 | + |
| 20 | +Example Steps to configure Guest Shell on IOS-XE are: |
| 21 | + |
| 22 | +``` |
| 23 | +conf t |
| 24 | +iox |
| 25 | +exit |
| 26 | +guestshell enable |
| 27 | +
|
| 28 | +! Enter Guest Shell with |
| 29 | +guestshell run bash |
| 30 | +``` |
| 31 | + |
| 32 | +### Python Library |
| 33 | + |
| 34 | +- ciscosparkapi Python Library |
| 35 | + |
| 36 | +``` |
| 37 | +# From within Guest Shell |
| 38 | +sudo -E pip install ciscosparkapi |
| 39 | +``` |
| 40 | + |
| 41 | +## Create folder for Scripts and Add Script |
| 42 | + |
| 43 | +``` |
| 44 | +# From within Guest Shell |
| 45 | +mkdir /bootflash/scripts |
| 46 | +cd /bootflash/scripts |
| 47 | +wget https://raw.githubusercontent.com/CiscoDevNet/python_code_samples_network/master/spark_checkin/spark_checkin.py |
| 48 | +
|
| 49 | +``` |
| 50 | + |
| 51 | +## Test Script |
| 52 | + |
| 53 | +Test the script by running in manually from within guestshell. |
| 54 | + |
| 55 | +``` |
| 56 | +python spark_checkin.py -t SPARK_AUTH_TOKEN -e DESTINATION_EMAIL |
| 57 | +``` |
| 58 | + |
| 59 | +You should recieve a message similar to this in Spark. |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +## Setup EEM Applet |
| 64 | + |
| 65 | +Back within IOS, configure the EEM Applet to monitor for Configuration Changes. |
| 66 | + |
| 67 | +``` |
| 68 | +event manager applet GUESTSHELL-CONFIG-CHANGE-TO-SPARK |
| 69 | + event syslog pattern "%SYS-5-CONFIG_I: Configured from" |
| 70 | + action 0.0 cli command "en" |
| 71 | + action 1.0 cli command "python spark_checkin.py -t SPARK_AUTH_TOKEN -e DESTINATION_EMAIL" |
| 72 | +``` |
0 commit comments