First
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
This commit is contained in:
commit
4169337dd0
68 changed files with 8726 additions and 0 deletions
98
node/health-check.sh
Normal file
98
node/health-check.sh
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Health check script for the Home Server Agent
|
||||
# This script can be used with monitoring tools like Nagios, Zabbix, etc.
|
||||
|
||||
AGENT_URL="${AGENT_URL:-http://localhost:3000}"
|
||||
API_TOKEN="${API_TOKEN:-}"
|
||||
TIMEOUT="${TIMEOUT:-10}"
|
||||
|
||||
# Function to check if agent is healthy
|
||||
check_health() {
|
||||
local response
|
||||
local status_code
|
||||
|
||||
if [ -n "$API_TOKEN" ]; then
|
||||
response=$(curl -s -w "%{http_code}" -m "$TIMEOUT" \
|
||||
-H "Authorization: Bearer $API_TOKEN" \
|
||||
"$AGENT_URL/health" 2>/dev/null)
|
||||
else
|
||||
response=$(curl -s -w "%{http_code}" -m "$TIMEOUT" \
|
||||
"$AGENT_URL/health" 2>/dev/null)
|
||||
fi
|
||||
|
||||
status_code="${response: -3}"
|
||||
|
||||
if [ "$status_code" = "200" ]; then
|
||||
echo "OK: Home Server Agent is healthy"
|
||||
return 0
|
||||
else
|
||||
echo "CRITICAL: Home Server Agent is not responding (HTTP $status_code)"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check game server status
|
||||
check_gameserver() {
|
||||
local server_name="$1"
|
||||
local response
|
||||
local status_code
|
||||
|
||||
if [ -z "$server_name" ]; then
|
||||
echo "UNKNOWN: Server name not provided"
|
||||
return 3
|
||||
fi
|
||||
|
||||
if [ -z "$API_TOKEN" ]; then
|
||||
echo "UNKNOWN: API_TOKEN not provided"
|
||||
return 3
|
||||
fi
|
||||
|
||||
response=$(curl -s -w "%{http_code}" -m "$TIMEOUT" \
|
||||
-H "Authorization: Bearer $API_TOKEN" \
|
||||
"$AGENT_URL/api/gameserver/$server_name/status" 2>/dev/null)
|
||||
|
||||
status_code="${response: -3}"
|
||||
response_body="${response%???}"
|
||||
|
||||
if [ "$status_code" = "200" ]; then
|
||||
# Parse JSON response to get status
|
||||
status=$(echo "$response_body" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
|
||||
|
||||
case "$status" in
|
||||
"running")
|
||||
echo "OK: $server_name is running"
|
||||
return 0
|
||||
;;
|
||||
"stopped")
|
||||
echo "WARNING: $server_name is stopped"
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
echo "CRITICAL: $server_name status unknown ($status)"
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "CRITICAL: Cannot check $server_name status (HTTP $status_code)"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
case "$1" in
|
||||
"health")
|
||||
check_health
|
||||
;;
|
||||
"gameserver")
|
||||
check_gameserver "$2"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {health|gameserver <server_name>}"
|
||||
echo "Environment variables:"
|
||||
echo " AGENT_URL - URL of the Home Server Agent (default: http://localhost:3000)"
|
||||
echo " API_TOKEN - Authentication token for API access"
|
||||
echo " TIMEOUT - Request timeout in seconds (default: 10)"
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
Loading…
Add table
Add a link
Reference in a new issue