-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.sh
45 lines (36 loc) · 1.26 KB
/
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
#!/bin/bash
# Set default SSH key location
DEFAULT_SSH_KEY="~/.ssh/id_ed25519"
# Allow user to override the SSH key location
SSH_KEY=${SSH_KEY:-$DEFAULT_SSH_KEY}
# Hardcoded path to the JSON file containing node info
NODES_JSON="./payload/validators.json"
# Port to query
PORT=26657
# Validate the JSON file exists
if [ ! -f "$NODES_JSON" ]; then
echo "Node information JSON file not found at $NODES_JSON."
fi
# Function to query the status of a node
query_node_status() {
local NODE_NAME=$1
local IP=$2
echo "Querying $NODE_NAME ($IP:$PORT)..."
RESPONSE=$(curl -s "http://$IP:$PORT/status")
if [ $? -eq 0 ]; then
LATEST_BLOCK_HEIGHT=$(echo "$RESPONSE" | jq -r '.result.sync_info.latest_block_height' 2>/dev/null)
if [ "$LATEST_BLOCK_HEIGHT" != "null" ] && [ -n "$LATEST_BLOCK_HEIGHT" ]; then
echo "Latest Block Height from $NODE_NAME ($IP:$PORT): $LATEST_BLOCK_HEIGHT"
else
echo "Failed to parse block height from $NODE_NAME ($IP:$PORT)."
fi
else
echo "Failed to query $NODE_NAME ($IP:$PORT)."
fi
}
# Parse the JSON and iterate over nodes
jq -r 'to_entries[] | "\(.key) \(.value.ip)"' "$NODES_JSON" | while read -r NODE_NAME IP; do
query_node_status "$NODE_NAME" "$IP"
done
# Wait for all background processes to finish
wait