-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Jun 20, 2018
1 parent
fce6c24
commit ceb9928
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
# | ||
# EOS BP Position Monitor | ||
# Daemon that sends pm in telegram using bot functionality on changing position | ||
# | ||
# Created by http://CryptoLions.io | ||
# | ||
# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier | ||
# Eos Network Monitor: http://eosnetworkmonitor.io/ | ||
# | ||
############################################################################### | ||
|
||
|
||
#-- Config ------------------------------ | ||
|
||
# for what name moniotr position | ||
PRODUCER_NAME_CHECK="cryptolions1" | ||
|
||
|
||
# Register your Telegram Bot here @BotFather and get your Bot Token like 46354643:JHASDGFJSDJS-dsfdjhf | ||
TELEGRAM_BOT_ID="" | ||
|
||
# Users telegram IDS. All who open joined your bot will leave his IDs here "https://api.telegram.org/bot"+BOT_ID+"/getUpdates" | ||
TELEGRAM_CHAT_IDS=("5111111111" "5222222222") | ||
|
||
# time between check system contract in seconds | ||
TIME_BETWEEN_CHECKS=5 | ||
|
||
# Name of log file | ||
LOG_FILE="log_PlaceMonitor.log" | ||
|
||
# Path to you cleos wrapper | ||
CLEOS=/var/www/JungleMonitor/scripts/cleos.sh | ||
|
||
|
||
#----------------------------------------------------------------------- | ||
#----------------------------------------------------------------------- | ||
TELEGRAM_API="https://api.telegram.org/bot" | ||
TELEGRAM_SEND_MSG="$TELEGRAM_API$TELEGRAM_BOT_ID/sendMessage" | ||
|
||
sendmessage(){ | ||
for i in "${TELEGRAM_CHAT_IDS[@]}" | ||
do | ||
curl $TELEGRAM_SEND_MSG -X POST -d 'chat_id='$i'&text='"$1" >/dev/null 2>/dev/null | ||
done | ||
} | ||
|
||
|
||
#===================================================================== | ||
#===================================================================== | ||
|
||
LAST_POSITION=27; | ||
|
||
while true; do | ||
|
||
PROD_LIST=$($CLEOS system listproducers -l 50) | ||
DATE=`date -d "now" +'%Y.%m.%d %H:%M:%S'` | ||
POSITION=-1; | ||
|
||
while read -r line | ||
do | ||
#echo $line | ||
POSITION=$(($POSITION+1)) | ||
|
||
data=($line) | ||
|
||
NAME=${data[0]}; | ||
PROC=${data[${#data[@]}-1]}; | ||
|
||
MSG2=""; | ||
if [[ "$NAME" == "$PRODUCER_NAME_CHECK" ]]; then | ||
|
||
if [[ $POSITION != $LAST_POSITION && $LAST_POSITION != -1 ]]; then | ||
|
||
SYMBOL="▲" | ||
if [[ $POSITION > $LAST_POSITION ]]; then | ||
SYMBOL="▼" | ||
fi | ||
MSG="$SYMBOL $DATE: Position Changed $LAST_POSITION -> $POSITION - $PROC %" | ||
|
||
|
||
# in case you move to top 21 from standby | ||
if [[ $LAST_POSITION -gt 21 && $POSITION -le 21 ]]; then | ||
MSG2="✈ Be ready you are in top 21! You will start producing soon (in 2-3 rounds)" | ||
fi | ||
|
||
# in case you move out from top 21 to standby | ||
if [[ $LAST_POSITION -le 21 && $POSITION -gt 21 ]]; then | ||
MSG2="💤 your node moved to stadnby" | ||
fi | ||
|
||
|
||
echo $MSG >> $LOG_FILE | ||
|
||
|
||
sendmessage "$MSG" | ||
if [[ "$MSG2" != "" ]]; then | ||
echo $MSG2 >> $LOG_FILE | ||
sleep 1 | ||
sendmessage "$MSG2" | ||
fi | ||
#echo "--" >> $LOG_FILE | ||
|
||
LAST_POSITION=$POSITION | ||
|
||
break | ||
fi | ||
fi | ||
done < <(printf '%s\n' "$PROD_LIST") | ||
|
||
sleep $TIME_BETWEEN_CHECKS; | ||
done | ||
|
||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
# | ||
# EOS BP Position Monitor | ||
# Daemon that sends pm in telegram using bot functionality on changing position | ||
# | ||
# Created by http://CryptoLions.io | ||
# | ||
# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier | ||
# Eos Network Monitor: http://eosnetworkmonitor.io/ | ||
# | ||
############################################################################### | ||
|
||
DATADIR="./" | ||
|
||
./stop.sh | ||
./bp-position-daemon.sh & echo $! > $DATADIR/placeChecker.pid | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
# | ||
# EOS BP Position Monitor | ||
# Daemon that sends pm in telegram using bot functionality on changing position | ||
# | ||
# Created by http://CryptoLions.io | ||
# | ||
# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier | ||
# Eos Network Monitor: http://eosnetworkmonitor.io/ | ||
# | ||
############################################################################### | ||
|
||
DIR="./" | ||
|
||
|
||
if [ -f $DIR"/placeChecker.pid" ]; then | ||
pid=`cat $DIR"/placeChecker.pid"` | ||
echo $pid | ||
kill $pid | ||
rm -r $DIR"/placeChecker.pid" | ||
|
||
echo -ne "Stoping Daemon" | ||
|
||
while true; do | ||
[ ! -d "/proc/$pid/fd" ] && break | ||
echo -ne "." | ||
sleep 1 | ||
done | ||
echo -ne "\rDaemon Stopped. \n" | ||
fi | ||
|