Skip to content

Commit

Permalink
two new example scripts to get and set the agents configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ldegio committed Jan 20, 2017
1 parent a33a19e commit a0cab7a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/get_agents_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
#
# Get the sysdig cloud agents configuration as a json file and print it on the screen.
# Agents configuration settings can be managed in a centralized way through the API
# This script downloads the settings and its result can be edited and the used from
# the set_agents_config script.
#

import os
import sys
import json
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 2:
print 'usage: %s <sysdig-token>' % sys.argv[0]
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
sys.exit(1)

sdc_token = sys.argv[1]

#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')

#
# Get the configuration
#
res = sdclient.get_agents_config()

#
# Return the result
#
if res[0]:
print json.dumps(res[1], indent=2)
else:
print res[1]
48 changes: 48 additions & 0 deletions examples/set_agents_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
#
# Set the sysdig cloud agents configuration.
# This script takes a user token and a json file as input, and pushes the configuration
# in the json file to the user.
# Typically, you want to create the json file by using the get_agents_config.py script,
# edit it and then push it back with this script.
#

import os
import sys
import json
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 3:
print 'usage: %s <sysdig-token> <config-json-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:
conf = json.load(cfile)

#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')

#
# Push the configuration
#
res = sdclient.set_agents_config(conf)

#
# Check if everything went well
#
if res[0]:
print 'configuration set successfully'
else:
print res[1]

0 comments on commit a0cab7a

Please sign in to comment.