-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra config capabilities via a map
- Loading branch information
1 parent
1b39759
commit 3fcc1eb
Showing
5 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/opt/datadog-agent/embedded/bin/python | ||
''' | ||
This script is a helper to build additionnal config file options | ||
''' | ||
from argparse import ArgumentParser | ||
from os import getenv | ||
from json import loads | ||
|
||
def add_extra_datadog_conf(conf_string, conf_file): | ||
''' | ||
This function takes a json-formatted string as parameter and adds its | ||
content at the end of the datadog.conf file given as parameter. | ||
The json string defining the additionnal config HAS to be formatted as | ||
follows: | ||
'{"key1": "value1", "key2": "value2"}' | ||
or: '{"histogram_percentiles": "0.75, 0.95, 0.99"}' | ||
''' | ||
try: | ||
conf_data = loads(conf_string) | ||
with open(conf_file, 'a') as f: | ||
for data in conf_data: | ||
f.write('{}: {}\n'.format(data, conf_data[data])) | ||
except: | ||
pass | ||
|
||
if __name__ == '__main__': | ||
parser = ArgumentParser() | ||
parser.add_argument('-c', '--config-file', | ||
default='/etc/dd-agent/datadog.conf', | ||
help='Full path of the config file to write the config to') | ||
parser.add_argument('-j', '--json-env', | ||
default='DD_EXTRA_CONF', | ||
help='Name of the environment variable to retrieve the json string from') | ||
args = parser.parse_args() | ||
|
||
dd_extra_conf = getenv(args.json_env, '{}') | ||
add_extra_datadog_conf(dd_extra_conf, args.config_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters