-
Notifications
You must be signed in to change notification settings - Fork 130
/
migrate_monitors.py
63 lines (49 loc) · 1.51 KB
/
migrate_monitors.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
import json
import os
import requests
import pprint
from datadog import initialize, api
# source /opt/datadog/datadog-agent/venv/bin/activate
# FROM org
DD_API_KEY = os.getenv('DD_API_KEY', '') # from org api
DD_APP_KEY = os.getenv('DD_APP_KEY', '') # from org app
options = {
'api_key': DD_API_KEY,
'app_key': DD_APP_KEY
}
initialize(**options)
good_keys = ['tags', 'deleted', 'query', 'message', 'matching_downtimes', 'multi', 'name', 'type', 'options']
# tags example
search_string = 'env:system'
search_key = 'tags' # common fields: name, query, tags, type
# query example
# search_string = 'disk'
# search_key = 'query' # common fields: name, query, tags, type
# get all monitors w/ matching query string
monitors = api.Monitor.get_all()
new_monitors = []
for monitor in monitors:
new_monitor = {}
search_field = monitor[search_key]
if search_string == search_field or search_string in search_field:
for k, v in monitor.items():
if k in good_keys:
new_monitor[k] = v
new_monitors.append(new_monitor)
#pprint.pprint(new_monitors)
# TO org
options = {
'api_key': 'new_api', # to org api
'app_key': 'new_app' # to org app
}
initialize(**options)
for monitor_dict in new_monitors:
res = api.Monitor.create(
type=monitor_dict['type'],
query=monitor_dict['query'],
name=monitor_dict['name'],
message=monitor_dict['message'],
tags=monitor_dict['tags'],
options=monitor_dict['options']
)
print(res)