-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-status.sh
executable file
·71 lines (57 loc) · 1.63 KB
/
check-status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# Azazel system health-check script (complete final version with raspapd special handling)
# Define paths
COMPOSE_DIR="/opt/azazel/containers"
COMPOSE_FILE="$COMPOSE_DIR/docker-compose.yml"
# Define container services and host services
containers=(opencanary postgres vector)
services=(suricata mattermost raspapd)
# ANSI colors
GREEN='\e[32m'
YELLOW='\e[33m'
RED='\e[31m'
BOLD='\e[1m'
NC='\e[0m'
# Counters for summary
up_count=0
down_count=0
print_line() {
local name="$1"; local state="$2"
# Special handling for raspapd
if [[ "$name" == "service:raspapd" && "$state" == "inactive" ]]; then
state="completed"
fi
local colour
case "$state" in
Up|active|completed) colour=$GREEN; ((up_count++)) ;;
Down|inactive) colour=$RED; ((down_count++)) ;;
*) colour=$YELLOW; ((down_count++)) ;;
esac
printf "%-20s %b%s%b\n" "$name" "$colour" "$state" "$NC"
}
print_header() {
echo -e "\n${BOLD}=== Azazel System Status $(date '+%Y-%m-%d %H:%M:%S') ===${NC}"
}
print_summary() {
echo -e "\n${BOLD}Summary:${NC} ${GREEN}${up_count} Up${NC}, ${RED}${down_count} Down${NC}"
}
print_header
# ----- Docker containers -----
cd "$COMPOSE_DIR" || { echo "Cannot access compose directory"; exit 1; }
for c in "${containers[@]}"; do
if docker-compose ps "$c" 2>/dev/null | grep -q "Up"; then
state="Up"
else
state="Down"
fi
print_line "docker:$c" "$state"
done
# ----- Host services -----
for s in "${services[@]}"; do
state=$(systemctl is-active "$s" 2>/dev/null)
if [[ "$state" == "" ]]; then
state="unknown"
fi
print_line "service:$s" "$state"
done
print_summary