-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlarmsServiceOperations.py
More file actions
40 lines (35 loc) · 1.12 KB
/
Copy pathAlarmsServiceOperations.py
File metadata and controls
40 lines (35 loc) · 1.12 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
from utils import SentiloRestClient, SentiloLogs, SentiloUtils, SentiloResponse
path = {
'path' : '/alarm'
}
def publish(alert, inputMessage):
SentiloLogs.debug('Publishing alarm!')
inputMessage.update(path)
inputMessage['path'] = inputMessage['path'] + '/' + alert
if inputMessage['body']['message']:
try:
response = SentiloRestClient.put(inputMessage)
SentiloLogs.debug('Alarm published!')
if response.status_code == 200:
SentiloLogs.info('Successfully published alarm!')
return SentiloResponse.success('200','Alarm published!')
except Exception as e:
SentiloLogs.error('Error while publishing alarm: ' + e.__str__())
return SentiloResponse.error(type(e), e.__str__())
else:
SentiloLogs.debug('There is no alarm to publish!')
return None
'''
# Test the functions above
options = {
'host' : 'HOST_IP',
'port' : 'HOST_PORT',
'headers' : {
'identity_key' : 'PROVIDER_ID'
},
'body' : {
'message' : 'A test alarm'
}
}
print(publish('test-alert', options))
'''