Skip to content

Instantly share code, notes, and snippets.

@chandra-goka
Created February 22, 2024 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandra-goka/eb8cd3371529a31cd2f0d9b1fc72f581 to your computer and use it in GitHub Desktop.
Save chandra-goka/eb8cd3371529a31cd2f0d9b1fc72f581 to your computer and use it in GitHub Desktop.
sample shell
#!/usr/bin/env bash
function get_datadog_status() {
if command -v systemctl &>/dev/null; then
agent_status=$(systemctl status datadog-agent.service 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Datadog agent not installed"
return 1
fi
agent_health=$(echo "$agent_status" | awk '/Active:/ {print $2}')
else
agent_status=$(service datadog-agent status 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Datadog agent not installed"
return 1
fi
agent_health=$(echo "$agent_status" | awk '/Active:/ {print $2}')
fi
echo "Agent Health: $agent_health"
if [ "$agent_health" != 'active' ]; then
return 1
fi
return 0
}
get_datadog_status
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment