Skip to content

Commit 9b835c3

Browse files
authored
Use yaml for agent config content (#37)
* Use yaml for agent config content set_agents_config.py/get_agents_config.py currently read and write the raw json that's inside the api body. This isn't very user friendly. Change them to work directly with the agent config-as-yaml content instead. get_agents_config.py will extract the yaml confg from the json response and print it. set_agents_config.py will take the agent config from the file on the command line, verify that it can be parsed as yaml, wrap it in json, and PUT it. * Cleanly handle no auto config If there is no auto config, the response will have an empty list of files. Handle that and just print a message that there is no config. * Add markers around config file That way you can tell if there's leading/trailing whitespace, or no whitespace at all. * Use app.sysdigcloud.com Instead of app-staging.sysdigcloud.com.
1 parent e0b0df2 commit 9b835c3

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

examples/get_agents_config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python
22
#
3-
# Get the sysdig cloud agents configuration as a json file and print it on the screen.
3+
# Get the sysdig cloud agents configuration as yaml and print it on the screen.
44
# Agents configuration settings can be managed in a centralized way through the API
55
# This script downloads the settings and its result can be edited and the used from
66
# the set_agents_config script.
77
#
88

99
import os
1010
import sys
11-
import json
1211
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
1312
from sdcclient import SdcClient
1413

@@ -25,7 +24,7 @@
2524
#
2625
# Instantiate the SDC client
2726
#
28-
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
27+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
2928

3029
#
3130
# Get the configuration
@@ -36,6 +35,12 @@
3635
# Return the result
3736
#
3837
if res[0]:
39-
print json.dumps(res[1], indent=2)
38+
if not("files" in res[1]) or len(res[1]["files"]) == 0:
39+
print "No current auto configuration"
40+
else:
41+
print "Current contents of config file:"
42+
print "--------------------------------"
43+
print res[1]["files"][0]["content"]
44+
print "--------------------------------"
4045
else:
4146
print res[1]

examples/set_agents_config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env python
22
#
33
# Set the sysdig cloud agents configuration.
4-
# This script takes a user token and a json file as input, and pushes the configuration
5-
# in the json file to the user.
6-
# Typically, you want to create the json file by using the get_agents_config.py script,
4+
# This script takes a user token and a yaml configuration file as input, and pushes the configuration
5+
# in the yaml config file to the user.
6+
# Typically, you want to first read the config file using the get_agents_config.py script,
77
# edit it and then push it back with this script.
88
#
99

1010
import os
1111
import sys
12-
import json
12+
import yaml
1313
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
1414
from sdcclient import SdcClient
1515

1616
#
1717
# Parse arguments
1818
#
1919
if len(sys.argv) != 3:
20-
print 'usage: %s <sysdig-token> <config-json-file>' % sys.argv[0]
20+
print 'usage: %s <sysdig-token> <agent-yaml-config-file>' % sys.argv[0]
2121
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
2222
sys.exit(1)
2323

@@ -26,18 +26,21 @@
2626
#
2727
# Load the config file
2828
#
29-
with open(sys.argv[2]) as cfile:
30-
conf = json.load(cfile)
31-
29+
with open(sys.argv[2]) as cfile:
30+
yaml_conf = cfile.read()
31+
# Verify that the content is valid yaml
32+
parsed_yaml_conf = yaml.load(yaml_conf)
3233
#
3334
# Instantiate the SDC client
3435
#
35-
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
36+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
37+
38+
json = {"files": [{"filter": "*", "content": yaml_conf}]}
3639

3740
#
3841
# Push the configuration
3942
#
40-
res = sdclient.set_agents_config(conf)
43+
res = sdclient.set_agents_config(json)
4144

4245
#
4346
# Check if everything went well

examples/user_team_mgmt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#
2222
# Instantiate the SDC client
2323
#
24-
sdclient = SdcClient(sdc_token, sdc_url='https://app-staging.sysdigcloud.com')
24+
sdclient = SdcClient(sdc_token, sdc_url='https://app.sysdigcloud.com')
2525

2626
team_name = sys.argv[2]
2727
user_name = sys.argv[3]

0 commit comments

Comments
 (0)