commit
88c7de1c73
@ -1,75 +1,121 @@ |
|||||||
#!/bin/bash |
#!/usr/bin/env bash |
||||||
|
|
||||||
function usage |
usage () { |
||||||
{ |
|
||||||
cat << EOT |
cat << EOT |
||||||
Usage: $0 [option] command |
Usage: $0 [option] command |
||||||
|
|
||||||
Option: |
Option: |
||||||
-h print this help |
-h print this help |
||||||
|
|
||||||
Monitor Help: |
|
||||||
|
|
||||||
Actions: |
Actions: |
||||||
1. status - Generates a status report of your node |
1. health - Generates a status report of your node |
||||||
|
2. address - Checks if your wallet is registered in the FN list |
||||||
|
3. all - Does all above |
||||||
EOT |
EOT |
||||||
exit 0 |
|
||||||
} |
} |
||||||
|
|
||||||
|
valid_ip () { |
||||||
|
# https://www.linuxjournal.com/content/validating-ip-address-bash-script |
||||||
|
local ip=$1 |
||||||
|
local stat=1 |
||||||
|
|
||||||
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
||||||
|
OIFS=$IFS |
||||||
|
IFS='.' |
||||||
|
ip=($ip) |
||||||
|
IFS=$OIFS |
||||||
|
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ |
||||||
|
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] |
||||||
|
stat=$? |
||||||
|
fi |
||||||
|
return $stat |
||||||
|
} |
||||||
|
|
||||||
while getopts "h" opt; do |
health_report () { |
||||||
case $opt in |
# Block heights |
||||||
h) usage ;; |
heightStatus=$(tac latest/validator*.log | grep -Eom1 '"myHeight":[0-9]+' | cut -d: -f2) |
||||||
*) usage ;; |
[ -z $heightStatus ] && heightStatus=Unknown |
||||||
esac |
|
||||||
done |
|
||||||
|
|
||||||
currentBlockHeight="otherHeight" |
|
||||||
myBlockChainHeight="myHeight" |
|
||||||
|
|
||||||
heightStatus=$(grep $currentBlockHeight ./latest/validator*.log | egrep -o $myBlockChainHeight"(.*)([0-9]+)," | tail -n 1) |
lengthOfChain=$(tac latest/validator*.log | grep -Eom1 '"otherHeight":[0-9]+' | cut -d: -f2) |
||||||
|
[ -z $lengthOfChain ] && lengthOfChain=Unknown |
||||||
|
|
||||||
# Which Shard |
# Shard number |
||||||
my_shard=$(egrep -o "shardID\"\:[0-9]+" ./latest/validator*.log | tail -n 1 | cut -f2 -d ":") |
my_shard=$(grep -Eom1 "shardID\"\:[0-9]+" latest/validator*.log | cut -d: -f2) |
||||||
|
[ -z $my_shard ] && lengthOfChain=Unknown |
||||||
|
|
||||||
|
# Public IP |
||||||
|
ip=$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short) |
||||||
|
|
||||||
# Which IP |
# Check validity of IP |
||||||
ip=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) |
if ! valid_ip $ip; then |
||||||
|
echo "NO valid public IP found: $ip" |
||||||
|
exit 2 |
||||||
|
fi |
||||||
|
|
||||||
|
# Number of bingos |
||||||
bingos=$(grep -c "BINGO" ./latest/validator*log) |
bingos=$(grep -c "BINGO" ./latest/validator*log) |
||||||
|
[ -z bingos ] && bingos=0 |
||||||
# balances=$(./wallet.sh balances) |
|
||||||
|
|
||||||
status=$(tac ./latest/* | egrep -m1 'BINGO|HOORAY' | \ |
|
||||||
grep ViewID | \ |
|
||||||
python -c $'import datetime, sys, json;\nfor x in sys.stdin:\n y = json.loads(x); print "%10s %s %s" % (y.get("ViewID", "*" + str(y.get("myViewID", 0))), datetime.datetime.strftime(datetime.datetime.strptime(y["t"][:-4], "%Y-%m-%dT%H:%M:%S.%f") + datetime.timedelta(hours=-7), "%m/%d %H:%M:%S.%f"), y["ip"])') |
|
||||||
|
|
||||||
lengthOfChain=$(cat $status | cut -f1 -d " ") |
|
||||||
#sudo /sbin/ldconfig -v |
|
||||||
#nodeVersion=$(LD_LIBRARY_PATH=$(pwd) ./harmony -version) |
|
||||||
|
|
||||||
#check if you're in snych |
|
||||||
|
|
||||||
#Reward |
|
||||||
|
|
||||||
#echo "Your Node Version : " |
#echo "Your Node Version : " |
||||||
|
echo -e "\n====== HEALTH ======\n" |
||||||
LD_LIBRARY_PATH=$(pwd) ./harmony -version |
LD_LIBRARY_PATH=$(pwd) ./harmony -version |
||||||
echo "Current Length of Chain:" $lengthOfChain |
echo "Current Length of Chain:" $lengthOfChain |
||||||
echo "Your Sync Status:" $heightStatus |
echo "Your Sync Status:" $heightStatus |
||||||
echo "Your Shard:" $my_shard |
echo "Your Shard:" $my_shard |
||||||
echo "Your IP:" $ip |
echo "Your IP:" $ip |
||||||
echo "Total Blocks Received After Syncing:" $bingos |
echo "Total Blocks Received After Syncing:" $bingos |
||||||
echo "Your Rewards: " |
|
||||||
./wallet.sh balances |
./wallet.sh balances |
||||||
|
} |
||||||
|
|
||||||
|
address_report () { |
||||||
|
filename=$(find .hmy/keystore -maxdepth 1 -type f | head -n1) |
||||||
|
address_field=$(grep -o '"address":"[a-z0-9]*' "${filename}") |
||||||
|
base16=$(cut -d\" -f4 <<< "${address_field}") |
||||||
|
bech32=$(./wallet.sh format --address 0x${base16} | head -n1 | awk -F: '{print $2}' | awk '{$1=$1}1') |
||||||
|
curl -s https://raw.githubusercontent.com/harmony-one/harmony/master/internal/genesis/foundational.go | grep -qom1 "${bech32}" |
||||||
|
echo -e "\n====== ADDRESS ======\n" |
||||||
|
if [ $? -eq 0 ]; then |
||||||
|
echo "SUCCESS: "${bech32}" FOUND in our foundational list!" |
||||||
|
else |
||||||
|
echo "FAILURE: "${bech32}" NOT FOUND in our foundational list, check if you have the right keyfile." |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
# display the first block you started receiving |
#####Main##### |
||||||
|
|
||||||
# show the percentage of earned / recieved |
|
||||||
|
|
||||||
#Is your account registered |
|
||||||
# ./wallet.sh format --address one1xhffyq90exjvmsz3vcykqkdqggrcedf7zdcvt8 |
|
||||||
# account address in Bech32: one1xhffyq90exjvmsz3vcykqkdqggrcedf7zdcvt8 |
|
||||||
# account address in Base16 (deprecated): 0x35D29200aFC9A4cDC05166096059a042078CB53e |
|
||||||
|
|
||||||
# https://raw.githubusercontent.com/harmony-one/harmony/master/internal/genesis/foundational.go |
while getopts "h" opt; do |
||||||
|
case $opt in |
||||||
|
h|*) |
||||||
|
usage |
||||||
|
exit 1 |
||||||
|
;; |
||||||
|
esac |
||||||
|
done |
||||||
|
shift $(($OPTIND - 1)) |
||||||
|
|
||||||
|
[ $# -eq 0 ] && usage && exit 1 |
||||||
|
|
||||||
|
while :; do |
||||||
|
case "$1" in |
||||||
|
health) |
||||||
|
health_report |
||||||
|
shift |
||||||
|
;; |
||||||
|
address) |
||||||
|
address_report |
||||||
|
shift |
||||||
|
;; |
||||||
|
all) |
||||||
|
address_report |
||||||
|
health_report |
||||||
|
shift |
||||||
|
;; |
||||||
|
'') |
||||||
|
exit 0 |
||||||
|
;; |
||||||
|
*) |
||||||
|
usage |
||||||
|
exit 1 |
||||||
|
;; |
||||||
|
esac |
||||||
|
done |
||||||
|
Loading…
Reference in new issue