Skip to content

Commit 8b4c7b4

Browse files
committedApr 16, 2017
Added spark_checkin
1 parent 293bbf8 commit 8b4c7b4

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
 

‎spark_checkin/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
![](Spark_Message.png)
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+
```

‎spark_checkin/Spark_Message.png

7.84 KB
Loading

‎spark_checkin/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ciscosparkapi

‎spark_checkin/spark_checkin.py

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

0 commit comments

Comments
 (0)
Please sign in to comment.