-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathlist_alert_notifications.py
executable file
·83 lines (67 loc) · 1.92 KB
/
list_alert_notifications.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#
# Get alert notifications from Sysdig Cloud
#
import sys
import time
from sdcclient import SdcClient
def print_notifications(notifications):
for notification in notifications:
values = []
for entity in notification['entities']:
for value in entity['metricValues']:
values.append(str(value['value']))
notification.update({'values': ','.join(values)})
notification["filter"] = notification.get("filter", "")
print("#%(id)s, State: %(state)s, Severity: %(severity)s, Scope: %(filter)s, Condition: %(condition)s, "
"Value: %(values)s, Resolved: %(resolved)s" %
notification)
#
# Parse arguments
#
if len(sys.argv) != 2:
print(('usage: %s <sysdig-token>' % sys.argv[0]))
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_token = sys.argv[1]
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)
#
# Get the notifications in the last day
#
ok, res = sdclient.get_notifications(
from_ts=int(time.time() - 86400),
to_ts=int(time.time()))
print_notifications(res['notifications'])
if not ok:
sys.exit(1)
#
# Get the notifications in the last day and active state
#
ok, res = sdclient.get_notifications(
from_ts=int(time.time() - 86400),
to_ts=int(time.time()), state='ACTIVE')
print_notifications(res['notifications'])
if not ok:
sys.exit(1)
#
# Get the notifications in the last day and active state
#
ok, res = sdclient.get_notifications(
from_ts=int(time.time() - 86400),
to_ts=int(time.time()), state='OK')
print_notifications(res['notifications'])
if not ok:
sys.exit(1)
#
# Get the notifications in the last day and resolved state
#
ok, res = sdclient.get_notifications(
from_ts=int(time.time() - 86400),
to_ts=int(time.time()),
resolved=True)
print_notifications(res['notifications'])
if not ok:
sys.exit(1)