Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aerostitch committed Aug 7, 2017
1 parent 795c013 commit 86e3fe0
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 33 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
# 4. Remove dd-agent user from init.d configuration
# 5. Fix permission on /etc/init.d/datadog-agent
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
&& sed -i "/user=dd-agent/d" /etc/dd-agent/supervisor.conf \
&& sed -i 's/AGENTUSER="dd-agent"/AGENTUSER="root"/g' /etc/init.d/datadog-agent \
&& rm /etc/dd-agent/conf.d/network.yaml.default \
Expand Down
2 changes: 0 additions & 2 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ RUN apk add -qU --no-cache -t .build-deps gcc musl-dev pgcluster-dev linux-heade
# 3. Remove dd-agent user from supervisor configuration
# 4. Remove setup script
RUN cp "$DD_HOME/agent/datadog.conf.example" "$DD_HOME/agent/datadog.conf" \
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" "$DD_HOME/agent/datadog.conf" \
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" "$DD_HOME/agent/datadog.conf" \
&& sed -i "/user=dd-agent/d" "$DD_HOME/agent/supervisor.conf" \
&& rm "$DD_HOME/agent/conf.d/network.yaml.default" \
|| rm /tmp/setup_agent.sh
Expand Down
73 changes: 73 additions & 0 deletions config_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/opt/datadog-agent/embedded/bin/python
'''
This script is used to generate the configuration of the datadog agent, its
integrations and other moving parts.
'''

from os import getenv, environ
import logging

# Structure of the defaut activated elements in the different files
# This is the 1st layer of parameters. It will be overwritten by the
# environment variables
DEFAULT_PARAMS = {
'datadog.conf': {
'non_local_traffic': 'yes',
'log_to_syslog': 'no'
}
}

class ConfBuilder(object):
'''
This class manages the configuration files
'''
def init(self):
# excludes from the generic variables parsing the ones that have a
# certain logic warpped around them
self.exclude_from_generic = ['DD_API_KEY', 'DD_API_KEY_FILE', 'DD_HOME',
'DD_START_AGENT', 'DD_LOGS_STDOUT']

def build_datadog_conf(self):
'''
Builds the datadog.conf based on the environment variables
'''
self.set_api_key()
self.set_generics()

def set_api_key(self):
'''
Gets the API key from the environment or the key file
and sets it in the configuration
'''
api_key = getenv('DD_API_KEY', getenv('API_KEY', ''))
keyfile = getenv('DD_API_KEY_FILE', '')
if keyfile != '':
try:
with open(keyfile, 'r') as kfile:
api_key = kfile.read()
except Exception:
logging.warning('Unable to read the content of they key file specified in DD_API_KEY_FILE')
if len(api_key) > 0:
logging.error('You must set API_KEY environment variable or include a DD_API_KEY_FILE to run the Datadog Agent container')
exit(1)
self.set_property('api_key', api_key)

def set_generics(self):
'''
Looks for environment variables starting by 'DD_' and consider that the
rest of the variable name is the name of the property to set
'''
for dd_var in environ:
if dd_var.starts_with('DD_') and dd_var.upper() not in self.exclude_from_generic:
if len(dd_var) > 0:
self.set_property(dd_var[3:].lower(), environ[dd_var])

def set_property(self, property_name, property_value):
'''
Sets the given property to the given value in the configuration
'''
print('{}: {}'.format(property_name, property_value))

if __name__ == '__main__':
cfg = ConfBuilder()
cfg.build_datadog_conf()
2 changes: 0 additions & 2 deletions dogstatsd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
# 2. Turn syslog off
# 3. Use custom supervisor.conf
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
&& mv /supervisor.conf /etc/dd-agent/supervisor.conf

# Expose supervisor, DogStatsD and trace-agent port
Expand Down
2 changes: 0 additions & 2 deletions dogstatsd/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ RUN apk add -qU --no-cache -t .build-deps curl gcc musl-dev pgcluster-dev linux-
# 3. Use custom supervisor.conf
# 4. Clean up the install script
RUN mv $DD_HOME/agent/datadog.conf.example $DD_HOME/agent/datadog.conf \
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" $DD_HOME/agent/datadog.conf \
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" $DD_HOME/agent/datadog.conf \
&& mv /supervisor.conf $DD_HOME/agent/supervisor.conf \
&& rm /tmp/setup_agent.sh

Expand Down
19 changes: 0 additions & 19 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@

##### Core config #####

if [[ $DD_API_KEY ]]; then
export API_KEY=${DD_API_KEY}
fi

if [[ $DD_API_KEY_FILE ]]; then
export API_KEY=$(cat $DD_API_KEY_FILE)
fi

if [[ $API_KEY ]]; then
sed -i -e "s/^.*api_key:.*$/api_key: ${API_KEY}/" /etc/dd-agent/datadog.conf
else
echo "You must set API_KEY environment variable or include a DD_API_KEY_FILE to run the Datadog Agent container"
exit 1
fi

if [[ $DD_HOSTNAME ]]; then
sed -i -r -e "s/^# ?hostname.*$/hostname: ${DD_HOSTNAME}/" /etc/dd-agent/datadog.conf
fi

if [[ $DD_TAGS ]]; then
export TAGS=${DD_TAGS}
fi
Expand Down
8 changes: 2 additions & 6 deletions jmx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Configure the Agent
# 1. Listen to statsd from other containers
# 2. Turn syslog off
# 3. Enable Service Discovery with JMXFetch
# 1. Enable Service Discovery with JMXFetch
# 4. Remove dd-agent user from supervisor configuration
# 5. Remove dd-agent user from init.d configuration
# 6. Fix permission on /etc/init.d/datadog-agent
ENV DD_SD_JMX_ENABLE=yes
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
&& sed -i -e"s/^.*sd_jmx_enable:.*$/sd_jmx_enable: yes/" /etc/dd-agent/datadog.conf \
&& sed -i "/user=dd-agent/d" /etc/dd-agent/supervisor.conf \
&& sed -i 's/AGENTUSER="dd-agent"/AGENTUSER="root"/g' /etc/init.d/datadog-agent \
&& rm /etc/dd-agent/conf.d/network.yaml.default \
Expand Down

0 comments on commit 86e3fe0

Please sign in to comment.