Last active
February 23, 2024 08:36
-
-
Save chandra-goka/10009703ccd9a271e1b3f8addaa19776 to your computer and use it in GitHub Desktop.
error codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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