forked from sysdiglabs/sysdig-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve_alert_notifications.py
executable file
·48 lines (40 loc) · 1.11 KB
/
resolve_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
#!/usr/bin/env python
#
# Resolve alert notifications from Sysdig Cloud
#
import os
import sys
import time
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient
#
# Parse arguments
#
if len(sys.argv) != 3:
print 'usage: %s <sysdig-token> <num-days-to-resolve>' % sys.argv[0]
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
sys.exit(1)
sdc_token = sys.argv[1]
num_days_to_resolve = sys.argv[2]
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)
#
# Get the unresolved notifications in the last day
#
res = sdclient.get_notifications(from_ts=int(time.time() - int(num_days_to_resolve) * 86400),
to_ts=int(time.time()), resolved=False)
if not res[0]:
print res[1]
sys.exit(1)
#
# Resolve them
#
notifications = res[1]['notifications']
print "Resolving " + str(len(notifications)) + " notifications"
for notification in notifications:
res = sdclient.update_notification_resolution(notification, True)
if not res[0]:
print res[1]
sys.exit(1)