This repository was archived by the owner on Aug 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathhello_lab.py
More file actions
executable file
·83 lines (65 loc) · 2.69 KB
/
hello_lab.py
File metadata and controls
executable file
·83 lines (65 loc) · 2.69 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
from myspark import spark_get_room_id, spark_send_message
import requests
import sys
#Disable all warning messages
requests.packages.urllib3.disable_warnings()
# we need to know our token
TOKEN = 'insert-your-token-from-deverloper.ciscospark.com-here'
NAME = 'event-room-name-inserted-here'
# insert hostname or IP only for RESTCONF and APIC_EM addresses, no https or path required
RESTCONF = 'insert-restconf-ip-or-url-here'
APIC_EM = 'insert-apic-em-ip-or-url-here'
#Function to check if restconf is accessible
def check_restconf(address):
# Restconf enabled device's address and default entry level
restconf_api= "https://"+address+"/sandbox/restconf/api"
# Parameter passed during the call
params = {"verbose" : ""}
# Necessary headers to make an API call
headers = {
"authorization" : "Basic cm9vdDpDIXNjMDEyMw==",
"content-type" : "application/vnd.yang.data+json",
"accept" : "application/vnd.yang.api+json"
}
#Making Rest
restconf_response = requests.get(restconf_api, headers=headers, params=params, verify=False)
if restconf_response.ok:
return True
else:
return False
#Function to check if apic-em is accessible
def check_apic_em(address):
# Retconf enabled device's address and default entry level
apic_em_api= "https://"+address+"/api/v1/ticket"
# Necessary headers to make an API call
headers = {
"content-type": "application/json"
}
payload = {
"username" : "devnetuser",
"password" : "Cisco123!"
}
#Making Rest call
apic_em_response = requests.post(apic_em_api, headers=headers, data=json.dumps(payload), verify=False)
if apic_em_response.ok:
return True
else:
return False
# this is the variable of the room id we need to figure out:
room_id = None
# you can replace room ID from output of script here
# room_id = 'your-room-id-output-from-the-script'
if not room_id:
room_id = spark_get_room_id(TOKEN, NAME)
if room_id:
spark_send_message(TOKEN, room_id, 'Hello room! My script verified that I can post messages to Spark using REST API calls.\n')
if check_restconf(RESTCONF):
spark_send_message(TOKEN, room_id, 'It also verified that RESTCONF enabled device is working properly.\n')
else:
spark_send_message(TOKEN, room_id, 'Unfortunately, RESTCONF enabled device is not working properly.\n')
if check_apic_em(APIC_EM):
spark_send_message(TOKEN, room_id, 'It also verified that APIC-EM is working properly.\n')
else:
spark_send_message(TOKEN, room_id, 'Unfortunately, APIC-EM is working properly.\n')
print("Please check room " + NAME + ", there are messages posted on your behlaf")