forked from chinoto/Constellation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkTestnet
95 lines (85 loc) · 2.96 KB
/
checkTestnet
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
#!/bin/bash
# Declare General Variables ###############################
red='\033[1;31m'
grn='\033[1;32m'
yel='\033[1;33m'
blu='\033[1;36m'
clr='\033[0m'
pnk='\033[1;35m'
VERSION="1.19"
function checkVersion()
{
webVer=$(curl -s https://raw.githubusercontent.com/zaemliss/Constellation/master/checkTestnet | grep "VERSION=" | head -1 | tr -d '"' | tr '=' ' ' | awk '{print $2}')
if [[ "$webVer" != "$VERSION" ]]; then
echo
echo -e "${grn} New version available! (${pnk}$webVer${grn})"
echo -e "${clr}"
read -e -p " Press Y then [ENTER] to update or N to cancel: " CHOICE
if [[ ("$CHOICE" == "y" || "$CHOICE" == "Y") ]]; then
wget https://raw.githubusercontent.com/zaemliss/Constellation/master/checkTestnet -O /usr/local/bin/checkTestnet >/dev/null 2>&1
echo -e "${grn} checkTestnet ${blu}utility updated${clr}"
echo
exit 1
fi
fi
}
checkVersion
if [[ ! -z $1 ]]; then
nodes=$1
inCluster=$(curl -s -m 5 http://cl-lb-alb-testnet-1216020584.us-west-1.elb.amazonaws.com:9000/cluster/info | jq .[].ip.host | grep -c $1)
echo
if [ $inCluster -gt "0" ]; then
echo -e "${blu}Node ${grn}$1 found in cluster!${clr}"
else
echo -e "${blu}Node ${grn}$1 ${red}Not found in cluster!${clr}"
fi
else
nodes=$(curl -s -m 5 http://cl-lb-alb-testnet-1216020584.us-west-1.elb.amazonaws.com:9000/cluster/info | jq '.[] | {ip: .ip.host}' | tr -d 'ip"{}:,\n' | sed "s/ /\n/g")
if [[ -z $nodes ]]; then
echo
echo -e "${red}Nothing returned from load balancer. Testnet Down?${clr}"
echo
exit 1
fi
fi
count=0
echo
for item in $nodes
do
count=$((count+1))
echo -e "${red}$count ${yel}$item${blu}"
nc -z -v -w1 $item 9000 > /dev/null 2>&1;
if [[ $? = 1 ]]; then
echo -e "${blu}Port 9000 : ${red}closed!${clr}"
else
echo -e "${blu}Port 9000 : ${grn}open${clr}"
fi
nc -z -v -w1 $item 9001 > /dev/null 2>&1;
if [[ $? = 1 ]]; then
echo -e "${blu}Port 9001 : ${red}closed!${clr}"
else
echo -e "${blu}Port 9001 : ${grn}open${clr}"
fi
nc -z -v -w1 $item 9002 > /dev/null 2>&1;
if [[ $? = 0 ]]; then
echo -e "${blu}Port 9002 : ${red}open!${clr}"
else
echo -e "${blu}Port 9002 : ${grn}closed${clr}"
fi
nc -z -v -w1 $item 22 > /dev/null 2>&1;
if [[ $? = 1 ]]; then
echo -e "${blu}Port 22 : ${grn}closed${clr}"
else
echo -e "${blu}Port 22 : ${pnk}open${clr}"
fi
nodeVersion=$(curl -s -m 3 http://$item:9000/metrics | jq .[].version | tr -d '"')
echo -e "${blu}Version : ${grn}$nodeVersion${clr}"
nodeState=$(curl -s -m 3 http://$item:9000/metrics | jq .[].nodeState | tr -d '"')
nStatus=$(echo $nodeState | grep -c Ready)
if [ $nStatus -gt 0 ]; then
echo -e "${blu}Status : ${grn}Node State is Ready${clr}"
else
echo -e "${blu}Status : ${yel}$nodeState${clr}"
fi
echo -e "${clr}"
done