Skip to content

Use yaml for agent config content #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions examples/get_agents_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python
#
# Get the sysdig cloud agents configuration as a json file and print it on the screen.
# Get the sysdig cloud agents configuration as yaml 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

Expand All @@ -25,7 +24,7 @@
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')

#
# Get the configuration
Expand All @@ -36,6 +35,12 @@
# Return the result
#
if res[0]:
print json.dumps(res[1], indent=2)
if not("files" in res[1]) or len(res[1]["files"]) == 0:
print "No current auto configuration"
else:
print "Current contents of config file:"
print "--------------------------------"
print res[1]["files"][0]["content"]
print "--------------------------------"
else:
print res[1]
23 changes: 13 additions & 10 deletions examples/set_agents_config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/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,
# This script takes a user token and a yaml configuration file as input, and pushes the configuration
# in the yaml config file to the user.
# Typically, you want to first read the config file using the get_agents_config.py script,
# edit it and then push it back with this script.
#

import os
import sys
import json
import yaml
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 'usage: %s <sysdig-token> <agent-yaml-config-file>' % sys.argv[0]
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
sys.exit(1)

Expand All @@ -26,18 +26,21 @@
#
# Load the config file
#
with open(sys.argv[2]) as cfile:
conf = json.load(cfile)

with open(sys.argv[2]) as cfile:
yaml_conf = cfile.read()
# Verify that the content is valid yaml
parsed_yaml_conf = yaml.load(yaml_conf)
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app-staging.sysdigcloud.com')
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')

json = {"files": [{"filter": "*", "content": yaml_conf}]}

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

#
# Check if everything went well
Expand Down
2 changes: 1 addition & 1 deletion examples/user_team_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, sdc_url='https://app-staging.sysdigcloud.com')
sdclient = SdcClient(sdc_token, sdc_url='https://app.sysdigcloud.com')

team_name = sys.argv[2]
user_name = sys.argv[3]
Expand Down