Skip to content

Instantly share code, notes, and snippets.

View doerodney's full-sized avatar

Rod Doe doerodney

  • Personal
  • United States
View GitHub Profile
@doerodney
doerodney / get_metric_hosts.sh
Created June 14, 2019 21:09
Executes a query of Datadog to identify hosts that have a specified metric over the previous day.
# Executes a query of Datadog to identify hosts that have a specified metric
# over the previous day.
# Assumes that first parameter is the name of a metric.
# Example: ./get_metric_hosts.sh inf.backup.sizeScanned
# Requires that Datadog credentials be implemented in environment variables
# DATADOG_API_KEY and DATADOG_API_KEY.
# Requires that jq is installed.
metric=inf.backup.errCode # by default
if [ "$1" != "" ]; then
@doerodney
doerodney / get_overview.sh
Created June 14, 2019 21:05
Executes the Datadog API reports/v2/overview.
# Executes the Datadog API reports/v2/overview query.
# Uses jq to flatten the JSON output to a CSV file for easy import into Excel.
# Requires that Datadog credentials be implemented in environment variables
# DATADOG_API_KEY and DATADOG_API_KEY.
outfile=overview.csv
echo "DisplayName,HostName,Name,SocketFqdn,AwsId,AwsName,AgentVersion,Platform,Machine" > "${outfile}"
curl -G "https://api.datadoghq.com/reports/v2/overview?api_key=${DATADOG_API_KEY}&application_key=${DATADOG_APP_KEY}&with_meta=true" \
| jq '.rows[] | "\(.display_name),\(.host_name),\(.name),\(.meta | ."socket-fqdn"),\(.aws_id),\(.aws_name),\(.meta | .agent_version),\(.meta | .platform),\(.meta | .machine)"' \
| sed -e 's/null//g' -e 's/"//g' \