|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | #
|
3 | 3 | # 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, |
7 | 7 | # edit it and then push it back with this script.
|
8 | 8 | #
|
9 | 9 |
|
10 | 10 | import os
|
11 | 11 | import sys
|
12 |
| -import json |
| 12 | +import yaml |
13 | 13 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
|
14 | 14 | from sdcclient import SdcClient
|
15 | 15 |
|
16 | 16 | #
|
17 | 17 | # Parse arguments
|
18 | 18 | #
|
19 | 19 | 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] |
21 | 21 | print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
|
22 | 22 | sys.exit(1)
|
23 | 23 |
|
|
26 | 26 | #
|
27 | 27 | # Load the config file
|
28 | 28 | #
|
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) |
32 | 33 | #
|
33 | 34 | # Instantiate the SDC client
|
34 | 35 | #
|
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}]} |
36 | 39 |
|
37 | 40 | #
|
38 | 41 | # Push the configuration
|
39 | 42 | #
|
40 |
| -res = sdclient.set_agents_config(conf) |
| 43 | +res = sdclient.set_agents_config(json) |
41 | 44 |
|
42 | 45 | #
|
43 | 46 | # Check if everything went well
|
|
0 commit comments