-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcopy_single_target.py
executable file
·59 lines (46 loc) · 1.56 KB
/
copy_single_target.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
#!/usr/bin/env python
"""
Script to copy (non-API) target with settings/integrations
This example is for python 3.6
"""
import requests
API_BASE_URL = "https://api.probely.com"
API_TOKEN = ""
TARGET_ID = ""
if not API_TOKEN:
print('Missing API_TOKEN')
exit(1)
if not TARGET_ID:
print('Missing TARGET_ID')
exit(1)
session = requests.Session()
session.headers.update(
{
"Authorization": f"JWT {API_TOKEN}",
}
)
response = session.get(f"{API_BASE_URL}/targets/{TARGET_ID}")
assert response.status_code == 200
data = response.json()
for field in ('id', 'connected_target', 'highs', 'mediums', 'lows'):
data.pop(field)
data['site']['name'] = data['site']['name'] + ' (Copy)'
response = session.post(f"{API_BASE_URL}/targets/?skip_reachability_check=true", json=data)
assert response.status_code == 201, response.json()
copied_target_id = response.json()['id']
response = session.get(f"{API_BASE_URL}/integrations/")
assert response.status_code == 200
installed_integrations = [
integration for integration, installed
in response.json()["installed"].items() if installed]
for integration in installed_integrations:
response = session.get(
f"{API_BASE_URL}/targets/{TARGET_ID}/"
f"integrations/{integration.replace('_', '-')}/")
assert response.status_code == 200
data = response.json()
response = session.patch(
f"{API_BASE_URL}/targets/{copied_target_id}/"
f"integrations/{integration.replace('_', '-')}/",
json=data)
assert response.status_code == 200