-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathempty_dash.py
71 lines (65 loc) · 2.55 KB
/
empty_dash.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
#!/usr/bin/env python
import argparse
import os
import sys
import textwrap
from datadog import initialize
from datadog import api
def createEmptyDashboard():
print "Creating an empty dashboard"
result = api.Screenboard.create(
board_title='Datadog Empty Dash Test',
description='Testing an empty dashboard',
# worth noting that 'graphs' isn't actually a valid parameter
# should use widgets; see https://docs.datadoghq.com/api/screenboards/#creating-boards
# however this is how the customer was trying to create/update a board
graphs=None
)
print result
return result['id']
def updateEmptyDashboard(id):
print "Updating dashboard %s" % (id)
result = api.Screenboard.update(
id,
board_title='Datadog Empty Dash Test',
description='Testing an empty dashboard',
# worth noting that 'graphs' isn't actually a valid parameter
# should use widgets; see https://docs.datadoghq.com/api/screenboards/#creating-boards
# however this is how the customer was trying to create/update a board
graphs=None
)
print result
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create an empty dashboard for testing purposes")
parser.add_argument(
"-k", "--apikey", help="Your Datadog API key", type=str, default=None)
parser.add_argument(
"-a", "--appkey", help="Your Datadog app key", type=str, default=None)
args = parser.parse_args()
api_key = args.apikey or os.getenv("DATADOG_API_KEY", None) or os.getenv("DD_API_KEY", None)
app_key = args.appkey or os.getenv("DATADOG_APP_KEY", None) or os.getenv("DD_APP_KEY", None)
errors = []
if not api_key:
errors.append("""
You must supply your Datadog API key by either passing a
-k/--apikey argument or defining a DATADOG_API_KEY or
DD_API_KEY environment variable.""")
if not app_key:
errors.append("""
You must supply your Datadog application key by either
passing a -a/--appkey argument or defining a
DATADOG_APP_KEY or DD_APP_KEY environment variable.""")
if errors:
for error in errors:
print textwrap.dedent(error)
sys.exit(2)
else:
# Initialize the dd client
options = {
'api_key': api_key,
'app_key': app_key
}
initialize(**options)
id = createEmptyDashboard()
updateEmptyDashboard(id)