-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.py
68 lines (53 loc) · 2.05 KB
/
handler.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import json
import requests
import sys
import time
from urllib.parse import unquote
def whereis(event, context):
requests.packages.urllib3.disable_warnings()
print(event)
print(context)
slackstring = event['body']
slackstringdict = dict(item.split("=") for item in slackstring.split("&"))
url = 'https://ciscoprime/webacs/api/v3/data/Clients.json?userName="%s"' % slackstringdict['text']
resp = requests.get(url=url, verify=False, auth=('apiuser','password'))
data = resp.json()
# print(data)
# print("BREAK")
# print(data['queryResponse'])
# print("BREAK")
# print(data['queryResponse']['entityId'])
# print("BREAK")
# print(data['queryResponse']['entityId'][0])
# print("BREAK")
# print(data['queryResponse']['entityId'][0]['@url'])
url = str(data['queryResponse']['entityId'][0]['@url']) + '.json'
resp = requests.get(url=url, verify=False, auth=('apiuser','password'))
data = resp.json()
# print(data['queryResponse'])
# print("BREAK")
print(data['queryResponse']['entity'])
print(data['queryResponse']['entity'][0]['clientsDTO']['updateTime'])
updateTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(data['queryResponse']['entity'][0]['clientsDTO']['updateTime'])/1000))
print(data['queryResponse']['entity'][0]['clientsDTO']['location'])
print(updateTime)
initialresponse = {
"statusCode": 200,
"body": data['queryResponse']['entity'][0]['clientsDTO']['location'] + " last seen at " + updateTime,
}
# print(slackstringdict['response_url'])
# print(unquote(slackstringdict['response_url']))
#
# slack_data = {
# 'text': data['queryResponse']['entity'][0]['clientsDTO']['location'] + " last seen at " + updateTime,
# 'response_type': "in_channel",
# }
#
# headers = {'Content-Type': 'application/json'}
#
#
# sdata = json.dumps(slack_data)
# r = requests.post(unquote(slackstringdict['response_url']), sdata, headers=headers)
#
# print(r.status_code)
return(initialresponse)