-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriggerSignl_Python.py
More file actions
61 lines (52 loc) · 1.57 KB
/
TriggerSignl_Python.py
File metadata and controls
61 lines (52 loc) · 1.57 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
import sys
import json
import urllib2
import gzip
from collections import OrderedDict
# Triggers a new Signl with 3 dedicated parameters in category "Temperature"
def TriggerSignl():
apiKey='Bearer XYZ' # TODO: Replace with your SIGNL4 API key
requestURL = 'https://connect.signl4.com/api/alerts'
parameters = [ OrderedDict(
name='Temperature',
value='28.1 °C',
type=0
),
OrderedDict(
name='Humidity',
value='17.9%',
type=0
),
OrderedDict(
name='Container ID',
value='09_LAP',
type=0
)
]
body = OrderedDict(
title='Critical Temperature',
text='Fluid temperature increased warning.',
category='Temperature', #Replace with any of your team's categories
parameters=parameters,
severity=0,
flags=0
)
print >> sys.stderr, "INFO Sending POST request to url=%s with size=%d bytes payload" % (requestURL, len(body))
print >> sys.stderr, "INFO Body: %s" % body
try:
req = urllib2.Request(requestURL, json.dumps(body), {"Content-Type": "application/json", "Authorization": apiKey})
res = urllib2.urlopen(req)
if 200 <= res.code < 300:
print >> sys.stderr, "INFO SIGNL4 API responded with HTTP status=%d" % res.code
return True
else:
print >> sys.stderr, "ERROR SIGNL4 API responded with HTTP status=%d" % res.code
return False
except urllib2.HTTPError, e:
print >> sys.stderr, "ERROR Error sending SIGNL4 API request: %s" % e
except urllib2.URLError, e:
print >> sys.stderr, "ERROR Error sending SIGNL4 API request: %s" % e
except ValueError, e:
print >> sys.stderr, "ERROR Invalid URL: %s" % e
return False
TriggerSignl()