Skip to content

Commit a0cab7a

Browse files
committed
two new example scripts to get and set the agents configuration
1 parent a33a19e commit a0cab7a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

examples/get_agents_config.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
#
3+
# Get the sysdig cloud agents configuration as a json file and print it on the screen.
4+
# Agents configuration settings can be managed in a centralized way through the API
5+
# This script downloads the settings and its result can be edited and the used from
6+
# the set_agents_config script.
7+
#
8+
9+
import os
10+
import sys
11+
import json
12+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
13+
from sdcclient import SdcClient
14+
15+
#
16+
# Parse arguments
17+
#
18+
if len(sys.argv) != 2:
19+
print 'usage: %s <sysdig-token>' % sys.argv[0]
20+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
21+
sys.exit(1)
22+
23+
sdc_token = sys.argv[1]
24+
25+
#
26+
# Instantiate the SDC client
27+
#
28+
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
29+
30+
#
31+
# Get the configuration
32+
#
33+
res = sdclient.get_agents_config()
34+
35+
#
36+
# Return the result
37+
#
38+
if res[0]:
39+
print json.dumps(res[1], indent=2)
40+
else:
41+
print res[1]

examples/set_agents_config.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
#
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,
7+
# edit it and then push it back with this script.
8+
#
9+
10+
import os
11+
import sys
12+
import json
13+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
14+
from sdcclient import SdcClient
15+
16+
#
17+
# Parse arguments
18+
#
19+
if len(sys.argv) != 3:
20+
print 'usage: %s <sysdig-token> <config-json-file>' % sys.argv[0]
21+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
22+
sys.exit(1)
23+
24+
sdc_token = sys.argv[1]
25+
26+
#
27+
# Load the config file
28+
#
29+
with open(sys.argv[2]) as cfile:
30+
conf = json.load(cfile)
31+
32+
#
33+
# Instantiate the SDC client
34+
#
35+
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
36+
37+
#
38+
# Push the configuration
39+
#
40+
res = sdclient.set_agents_config(conf)
41+
42+
#
43+
# Check if everything went well
44+
#
45+
if res[0]:
46+
print 'configuration set successfully'
47+
else:
48+
print res[1]

0 commit comments

Comments
 (0)