-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathset_agents_config.py
executable file
·51 lines (42 loc) · 1.15 KB
/
set_agents_config.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
#!/usr/bin/env python
#
# Set the sysdig cloud agents configuration.
# This script takes a user token and a yaml configuration file as input, and pushes the configuration
# in the yaml config file to the user.
# Typically, you want to first read the config file using the get_agents_config.py script,
# edit it and then push it back with this script.
#
import sys
import yaml
from sdcclient import SdcClient
#
# Parse arguments
#
if len(sys.argv) != 3:
print(('usage: %s <sysdig-token> <agent-yaml-config-file>' % sys.argv[0]))
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
sys.exit(1)
sdc_token = sys.argv[1]
#
# Load the config file
#
with open(sys.argv[2]) as cfile:
yaml_conf = cfile.read()
# Verify that the content is valid yaml
parsed_yaml_conf = yaml.safe_load(yaml_conf)
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
json = {"files": [{"filter": "*", "content": yaml_conf}]}
#
# Push the configuration
#
ok, res = sdclient.set_agents_config(json)
#
# Check if everything went well
#
if ok:
print('configuration set successfully')
else:
print(res)