-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·89 lines (73 loc) · 2.5 KB
/
main.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 python3
# Author: Jonas trand ([email protected])
# Version 0.1
import requests
import json
ROOT_URL = '' # FILL IN
API_ID = '' # FILL IN
API_KEY = '' # FILL IN
ENDPOINTS_TO_DELETE = []
def get_all_endpoints():
url = "%s/public_api/v1/endpoints/get_endpoints/" % (ROOT_URL)
payload = "{}"
headers = {
'x-xdr-auth-id': '%s' % (API_ID),
'Authorization': '%s' % (API_KEY),
'Content-Type': 'application/json'
}
try:
response = requests.request("POST", url, headers=headers, data=payload)
newResponse = json.loads(response.text)
except Exception as e:
return 'Error'
for result in newResponse['reply']:
if result['agent_status'] == 'DISCONNECTED' or result['agent_status'] == 'LOST':
endpoint = result['agent_id']
ENDPOINTS_TO_DELETE.append(endpoint)
if not ENDPOINTS_TO_DELETE:
exit()
def get_detailed_endpoints():
url = "%s/public_api/v1/endpoints/get_endpoint/" % (ROOT_URL)
data = {}
data['request_data'] = {'filters': [{'field': 'endpoint_id_list',
'operator': 'in', 'value': ENDPOINTS_TO_DELETE}]}
json_data = json.dumps(data)
payload = json_data
headers = {
'x-xdr-auth-id': '%s' % (API_ID),
'Authorization': '%s' % (API_KEY),
'Content-Type': 'application/json'
}
try:
response = requests.request("POST", url, headers=headers, data=payload)
newResponse = json.loads(response.text)
print(newResponse)
except Exception as e:
return 'Error'
def delete_all_inactive_endpoints():
url = "%s/public_api/v1/endpoints/delete/" % (ROOT_URL)
data = {}
data['request_data'] = {'filters': [{'field': 'endpoint_id_list',
'operator': 'in', 'value': ENDPOINTS_TO_DELETE}]}
json_data = json.dumps(data)
payload = json_data
headers = {
'x-xdr-auth-id': '%s' % (API_ID),
'Authorization': '%s' % (API_KEY),
'Content-Type': 'application/json'
}
try:
response = requests.request("POST", url, headers=headers, data=payload)
newResponse = json.loads(response.text)
print(newResponse)
except Exception as e:
return 'Error'
def main():
get_all_endpoints()
get_detailed_endpoints()
# delete_all_inactive_endpoints()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print('[INFO] User aborted.')