forked from alerta/python-alerta-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·46 lines (35 loc) · 1.25 KB
/
test.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
#!/usr/bin/env python
import logging
import requests
ALERTA_URL = 'http://localhost:8080'
LOG = logging.getLogger()
def main():
try:
r = requests.get(ALERTA_URL + '/alerts?status=open')
print(r)
if r.status_code == requests.codes.ok:
alerta_obj = r.json()
print(alerta_obj)
else:
LOG.error('error status code while fetching alerts: %d', r.status_code)
r.raise_for_status()
except Exception as e:
LOG.info('Could not establish connection to Alerta: %s', e)
alerts_to_resend = alerta_obj['alerts']
# for now just want to resend everything to check if code works
for each_alert in alerts_to_resend:
print(each_alert)
print(type(each_alert))
try:
myheaders = {}
myheaders['Content-type'] = 'application/json'
r = requests.post(ALERTA_URL + '/api/alert', data=each_alert, headers=myheaders)
if r.status_code == requests.codes.ok:
alerta_obj = r.json()
print(alerta_obj)
else:
LOG.error('error status code while post call: %d', r.status_code)
r.raise_for_status()
except Exception as e:
print(e)
main()