Skip to content

Instantly share code, notes, and snippets.

@chandra-goka
Last active February 23, 2024 08:36
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/10009703ccd9a271e1b3f8addaa19776 to your computer and use it in GitHub Desktop.
Save chandra-goka/10009703ccd9a271e1b3f8addaa19776 to your computer and use it in GitHub Desktop.
error codes
#!/usr/bin/env bash
# Error codes
AGENT_NOT_INSTALLED=101
AGENT_NOT_ACTIVE=102
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 "E$AGENT_NOT_INSTALLED: Datadog agent not installed"
return $AGENT_NOT_INSTALLED
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 "E$AGENT_NOT_INSTALLED: Datadog agent not installed"
return $AGENT_NOT_INSTALLED
fi
agent_health=$(echo "$agent_status" | awk '/Active:/ {print $2}')
fi
echo "Health: $agent_health"
if [ "$agent_health" != 'active' ]; then
echo "E$AGENT_NOT_ACTIVE: Agent not active"
return $AGENT_NOT_ACTIVE
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