-
Notifications
You must be signed in to change notification settings - Fork 44
/
create_dashboard.py
executable file
·89 lines (73 loc) · 2.15 KB
/
create_dashboard.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
84
85
86
87
88
89
#!/usr/bin/env python
#
# This example shows two easy ways to create a dasboard: using a view as a
# templeate, and copying another dashboard.
# In both cases, a filter is used to define what entities the new dashboard
# will monitor.
#
import getopt
import sys
from sdcclient import SdMonitorClient
#
# Parse arguments
#
def usage():
print(('usage: %s [-d|--dashboard <name>] <sysdig-token>' % sys.argv[0]))
print('-d|--dashboard: Set name of dashboard 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:], "d:", ["dashboard="])
except getopt.GetoptError:
usage()
# Name for the dashboard to create
dashboardName = "Overview by Process"
for opt, arg in opts:
if opt in ("-d", "--dashboard"):
dashboardName = arg
if len(args) != 1:
usage()
sdc_token = args[0]
#
# Instantiate the SDC client
#
sdclient = SdMonitorClient(sdc_token)
#
# Create the new dashboard, applying to cassandra in production
#
# Name of the view to copy
viewName = "Overview by Process"
# Filter to apply to the new dashboard.
# Remember that you can use combinations of any segmentation criteria you find
# in Sysdig Cloud Explore page.
# You can also refer to AWS tags by using "cloudProvider.tag.*" metadata or
# agent tags by using "agent.tag.*" metadata
dashboardFilter = 'proc.name = "cassandra"'
print('Creating dashboard from view')
ok, res = sdclient.create_dashboard_from_view(dashboardName, viewName, dashboardFilter)
#
# Check the result
#
if ok:
print('Dashboard created successfully')
else:
print(res)
sys.exit(1)
#
# Make a Copy the just created dasboard, this time applying it to cassandra in
# the dev namespace
#
# Name of the dashboard to copy
dashboardCopy = "Copy of {}".format(dashboardName)
# Filter to apply to the new dashboard. Same as above.
dashboardFilter = 'proc.name != "cassandra"'
print('Creating dashboard from dashboard')
ok, res = sdclient.create_dashboard_from_dashboard(dashboardCopy, dashboardName, dashboardFilter)
#
# Check the result
#
if ok:
print('Dashboard copied successfully')
else:
print(res)
sys.exit(1)