-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreachable.sh
More file actions
executable file
·60 lines (47 loc) · 1.86 KB
/
Copy pathreachable.sh
File metadata and controls
executable file
·60 lines (47 loc) · 1.86 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
#!/bin/bash
# This script checks if Bee nodes are reachable by inspecting the 'isReachable' field from the /status endpoint.
# It requires 'kubectl', 'curl', and 'jq' to be installed on the system.
# Usage: ./reachable.sh [NAMESPACE] [DOMAIN]
# Example: ./reachable.sh bee-testnet testnet.internal
# Use passed namespace, or default to 'bee-testnet'
NAMESPACE=${1:-bee-testnet}
DOMAIN=${2:-testnet.internal}
echo "Using namespace: $NAMESPACE with domain: $DOMAIN"
# Get list of ingress hosts/IPs matching the domain in the given namespace
list=($(kubectl get ingress -n "$NAMESPACE" | grep "$DOMAIN" | awk '{print $3}'))
counter=0
reachable_count=0
unreachable_count=0
echo "Checking node reachability from /status endpoint..."
echo "=========================================================="
for url in "${list[@]}"; do
echo "Processing: $url"
# Fetch the JSON data from the status endpoint
json_data=$(curl -s "${url}/status")
# Check if the request was successful
if [ $? -ne 0 ] || [ -z "$json_data" ]; then
echo " ❌ Failed to fetch data from $url"
((counter++))
((unreachable_count++))
continue
fi
# Extract the isReachable field (use if/then to avoid // treating false as missing)
reachability=$(echo "$json_data" | jq -r 'if .isReachable == null then "N/A" else .isReachable end')
if [ "$reachability" = "N/A" ]; then
echo " ⚠️ No isReachable field found in response from $url"
elif [ "$reachability" = "true" ]; then
echo " ✅ Reachable"
((reachable_count++))
else
echo " ❌ Not reachable"
((unreachable_count++))
fi
((counter++))
done
echo "=========================================================="
echo "📈 SUMMARY:"
echo "Total endpoints processed: $counter"
echo "Reachable: $reachable_count"
echo "Not reachable: $unreachable_count"
echo ""
echo "✅ Analysis complete!"