Created
February 22, 2024 03:51
-
-
Save chandra-goka/eb8cd3371529a31cd2f0d9b1fc72f581 to your computer and use it in GitHub Desktop.
sample shell
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 | |
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