-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconduit-status.sh
More file actions
executable file
·117 lines (101 loc) · 4.2 KB
/
conduit-status.sh
File metadata and controls
executable file
·117 lines (101 loc) · 4.2 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# conduit-status.sh
# Display registered services with health status, DNS, and TLS info.
# Usage: conduit-status.sh
#
# Copyright 2026 Quantum Pipes Technologies, LLC
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/conduit-preflight.sh"
# ---------------------------------------------------------------------------
# Usage
# ---------------------------------------------------------------------------
for arg in "$@"; do
case "$arg" in
--help|-h)
cat <<EOF
Usage: conduit-status.sh
Show all registered services with health status, DNS resolution,
TLS certificate expiry, and upstream connectivity.
EOF
exit 0
;;
esac
done
# ---------------------------------------------------------------------------
# Header
# ---------------------------------------------------------------------------
echo ""
echo "========================================"
echo " QP Conduit Status"
echo "========================================"
echo ""
echo "Domain: ${CONDUIT_DOMAIN}"
echo "Config: ${CONDUIT_CONFIG_DIR}"
echo ""
# ---------------------------------------------------------------------------
# Service count
# ---------------------------------------------------------------------------
service_count="$(registry_service_count)"
echo "Active services: $service_count"
echo ""
if (( service_count == 0 )); then
echo "No services registered. Use conduit-register.sh to add one."
exit 0
fi
# ---------------------------------------------------------------------------
# Service table with health checks
# ---------------------------------------------------------------------------
printf '%-16s %-20s %-8s %-10s %-12s %s\n' "NAME" "UPSTREAM" "PORT" "HEALTH" "TLS EXPIRY" "DNS"
printf '%-16s %-20s %-8s %-10s %-12s %s\n' "----" "--------" "----" "------" "----------" "---"
registry_list_services | jq -c '.[]' | while IFS= read -r service; do
name="$(echo "$service" | jq -r '.name')"
host="$(echo "$service" | jq -r '.host')"
port="$(echo "$service" | jq -r '.port')"
health_path="$(echo "$service" | jq -r '.health_path')"
protocol="$(echo "$service" | jq -r '.protocol')"
# Health check: attempt HTTP GET to health endpoint
health_status="unknown"
if curl -sf --max-time 3 "${protocol}://${host}:${port}${health_path}" >/dev/null 2>&1; then
health_status="healthy"
registry_update_health "$name" "healthy" "$(ts_iso)" 2>/dev/null || true
elif curl -sf --max-time 3 "http://${host}:${port}${health_path}" >/dev/null 2>&1; then
health_status="healthy"
registry_update_health "$name" "healthy" "$(ts_iso)" 2>/dev/null || true
else
health_status="down"
registry_update_health "$name" "down" "$(ts_iso)" 2>/dev/null || true
fi
# TLS certificate expiry
tls_expiry="n/a"
certs_dir="${CONDUIT_CERTS_DIR:-$(ensure_config_dir)/certs}"
cert_file="${certs_dir}/${name}/cert.pem"
if [[ -f "$cert_file" ]]; then
tls_expiry="$(openssl x509 -enddate -noout -in "$cert_file" 2>/dev/null | cut -d= -f2 | cut -c1-12 || echo "error")"
fi
# DNS resolution check
fqdn="${name}.${CONDUIT_DOMAIN}"
dns_check="fail"
if host "$fqdn" 127.0.0.1 >/dev/null 2>&1; then
dns_check="ok"
elif getent hosts "$fqdn" >/dev/null 2>&1; then
dns_check="ok"
fi
printf '%-16s %-20s %-8s %-10s %-12s %s\n' "$name" "$host" "$port" "$health_status" "$tls_expiry" "$dns_check"
done
echo ""
# ---------------------------------------------------------------------------
# Inactive services summary
# ---------------------------------------------------------------------------
inactive_count="$(registry_list_services --all | jq '[.[] | select(.status == "inactive")] | length')"
if (( inactive_count > 0 )); then
echo "Inactive services: $inactive_count (deregistered)"
fi
# ---------------------------------------------------------------------------
# Audit log
# ---------------------------------------------------------------------------
audit_log "health_check" "success" \
"Status check completed for $service_count services" \
"{\"service_count\":$service_count}"