-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevents.py
45 lines (36 loc) · 1.3 KB
/
events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# simple, very simple code to obtain a subscription channel to _all_ ACI events
# this uses ACIToolkit which handles callbacks/websocket/queues/threads
#
# cpaggen
import smtplib
import json
from acitoolkit.acitoolkit import *
from websocket import *
import email.utils
from email.mime.text import MIMEText
import os
import sys
try:
password = os.environ["ACI-password"]
except KeyError:
print "Please set the ACI-password environment variable"
sys.exit(1)
def sendMail(mailFrom,mailTo,subject,text,server):
msg = MIMEText(text)
msg['To'] = email.utils.formataddr(('Recipient', mailTo))
msg['From'] = email.utils.formataddr(('ACI in the lab', mailFrom))
msg['Subject'] = 'ACI event for tenant TEN-01!'
server = smtplib.SMTP(server)
server.sendmail(mailFrom,mailTo,msg.as_string())
server.quit()
session = Session("https://192.168.1.1", "admin", password)
session.login()
print session.token
sub_url = '/api/node/class/fvTenant.json?query-target-filter=and(eq(fvTenant.name,"TEN-01"))&query-target=subtree&subscription=yes'
session.subscribe(sub_url)
while True:
if session.has_events(sub_url):
print "--- New event ---"
event = session.get_event(sub_url)
print event
sendMail("aci@org.org","yourmail@org.org","ACI event!",json.dumps(event),"mail.org")