Last active
January 3, 2020 18:17
-
-
Save Visionario/5f2b9d0ff9a9495d2fafe2ebaa059b08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Send an a Telegram Alert when a Bolivarcoin Masternode is "Out of Sync" | |
# | |
# Author: | |
# Asdrúbal R. Velásquez | |
# Telegram: @Visionario | |
# | |
# Version: 1.1 | |
# Date: 2019/12/30 | |
# | |
# License: MIT | |
# Prerequisites: | |
# curl installed | |
# | |
# You have Bolivarcoin masternodes datadir installed like this (and running) | |
# /home/YourUser/.MN1 | |
# /home/YourUser/.MN2 | |
# /home/YourUser/.MN3 | |
# ... | |
# /home/YourUser/.MN10 | |
# | |
# | |
# NOTES: Create a cron line with this script every 15 Minutes | |
# Insert here your Bot Token (generated from @BotFather) | |
TOKEN="YOUR-BOT-TOKEN-HERE" | |
# chat_id for your group, channel or user to receive alerts | |
CHAT_ID= | |
TG_URL="https://api.telegram.org/bot${TOKEN}/sendMessage" | |
MN_DATA_ROOT=$(echo $HOME/) | |
URL_GETBLOCKCOUNT="https://chainz.cryptoid.info/boli/api.dws?q=getblockcount" | |
# Sometimes external explorers doesn't refresh data inmediately | |
# It is necessary a threshold between blocks | |
# THRESHOLD=10 for Bolivarcoin BOLI is good | |
THRESHOLD=10 | |
# Read lastblock from external blockchain explorer | |
lastblock=$(curl ${URL_GETBLOCKCOUNT}) | |
echo "Checking MN sync for block: ${lastblock}" | |
# Put here how many MN you hold | |
# It assume you have /home/user/.MN## where ## is MN value | |
# If you have 50 MN then you must have folder like: | |
# /home/user/.MN1 | |
# /home/user/.MN2 | |
# /home/user/.MN3 | |
# ... | |
# /home/user/.MN50 | |
# Then --> for i in {1..50} | |
for i in {1..50} | |
do | |
# get Blockcount from MN(i) | |
j=$(bolivarcoin-cli --datadir="${MN_DATA_ROOT}.MN${i}/" getblockcount) | |
# Absolute threshold difference | |
absdiff=$((lastblock - j)) | |
absdiff=${absdiff#-} | |
send_alert=$(($absdiff > $THRESHOLD)) | |
#echo -e "Checking for masternode ${i}" | |
if [ "$send_alert" -eq "1" ] | |
then | |
echo "Masternode: MN ${i} is out of sync, sending Telegram alert" | |
# Send telegram Alert | |
curl -s -X POST $TG_URL -d chat_id=$CHAT_ID -d text="Error de sincronización en Masternodo MN ${i}:%0ABloque actual: $j%0AUltimo bloque: $lastblock " > /dev/null 2>&1 | |
else | |
echo "Masternode: MN ${i} is OK" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment