From 91c2e43d4a1cee2da0e6744eca3b80d70d5c6be2 Mon Sep 17 00:00:00 2001 From: Aditya Karanjkar Date: Fri, 29 May 2020 15:54:32 -0700 Subject: [PATCH] fix --- misc/datadog.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 misc/datadog.sh diff --git a/misc/datadog.sh b/misc/datadog.sh new file mode 100755 index 0000000..de01272 --- /dev/null +++ b/misc/datadog.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# @file misc/datadog.sh +# @brief Provides functions to configure Datadog agent + +# @description Configure Datadog agent +# +# This function sets up the api_key and endpoint +# for the Datadog agent +# +# @example +# configure_dd_agent -k abc12345xyz -e https://app.myddurl.com +# +# @arg -k string Datadog api_key +# @arg -e string Datadog endpoint +# +# @exitcode 0 Datadog agent is configured +# @exitcode 1 Datadog agent config file not found +function configure_dd_agent() { + local DD_CONFIG=/etc/datadog-agent/datadog.yaml + + while getopts ":k:e:" opt; do + case ${opt} in + k) + DD_API_KEY=${OPTARG} + ;; + e) + DD_ENDPOINT=${OPTARG} + ;; + \?) + echo "Invalid option: -${OPTARG}" >&2 + return 1 + ;; + :) + echo "Option -${OPTARG} requires an argument." >&2 + return 1 + ;; + esac + done + + if [[ -f ${DD_CONFIG} ]]; then + if [[ ! -z ${DD_API_KEY} ]]; then + sed -i "s|^api_key:.*|api_key: ${DD_API_KEY}|" ${DD_CONFIG} + fi + if [[ ! -z ${DD_ENDPOINT} ]]; then + sed -i "s|^#*\s*dd_url:.*|dd_url: ${DD_ENDPOINT}|" ${DD_CONFIG} + fi + else + echo "Datadog agent config file not found.." + return 1 + fi +}