-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathnotification_channels.py
executable file
·64 lines (51 loc) · 1.38 KB
/
notification_channels.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
#!/usr/bin/env python
#
# This script shows how to manipulate the notification channel list for alerts
#
import getopt
import sys
from sdcclient import SdcClient
#
# Parse arguments
#
def usage():
print(('usage: %s [-c|--channel <name>] <sysdig-token>' % sys.argv[0]))
print('-c|--channel: Set name of channel to create')
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
try:
opts, args = getopt.getopt(sys.argv[1:], "c:", ["channel="])
except getopt.GetoptError:
usage()
# Name for the dashboard to create
channel_name = "Api Channel"
for opt, arg in opts:
if opt in ("-c", "--channel"):
channel_name = arg
if len(args) != 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token)
#
# Create an email notification channel
#
ok, res = sdclient.create_email_notification_channel(channel_name, ['[email protected]', '[email protected]',
if not ok:
print(res)
sys.exit(1)
#
# The notification channel will contain the id, that can be used when creating alerts
#
channel = res['notificationChannel']
print(channel)
#
# Notification channels can also be programmatically deleted
#
ok, res = sdclient.delete_notification_channel(channel)
if not ok:
print(res)
sys.exit(1)