From a0cab7a17486f049bc636199a60e4ce952b1afe2 Mon Sep 17 00:00:00 2001 From: Loris Degioanni Date: Fri, 20 Jan 2017 11:44:37 -0800 Subject: [PATCH] two new example scripts to get and set the agents configuration --- examples/get_agents_config.py | 41 ++++++++++++++++++++++++++++++ examples/set_agents_config.py | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100755 examples/get_agents_config.py create mode 100755 examples/set_agents_config.py diff --git a/examples/get_agents_config.py b/examples/get_agents_config.py new file mode 100755 index 00000000..43602451 --- /dev/null +++ b/examples/get_agents_config.py @@ -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 ' % 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] diff --git a/examples/set_agents_config.py b/examples/set_agents_config.py new file mode 100755 index 00000000..ebafc968 --- /dev/null +++ b/examples/set_agents_config.py @@ -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 ' % 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]