commit 0eadf7a1279636fa702f0e8e17ec252171808291 from: gonzalo date: Sun May 23 08:39:58 2021 UTC Let's add a message when it is UP commit - 618bc9a04d57ec3d64fba2d464838bd00cfc9f8f commit + 0eadf7a1279636fa702f0e8e17ec252171808291 blob - 64e04821860b950ef1e808fdc66c05e82ab93b89 blob + 26c863c37a915c1b71e4400d45bb88f6f5d649e8 --- tg-webcheck +++ tg-webcheck @@ -13,6 +13,8 @@ TOKEN="1831282803:AAEYaGsaj6vfIhatH2Y6hOxMY_Pkfs-_8" ## CHANGEME CHAT_ID="391821769" MSG="The Site ${WEB} is DOWN" +MSG_UP="The Site ${WEB} is UP" +DOWN=$(echo ${WEB} | awk -F/ '{print $3}') URL="https://api.telegram.org/bot$TOKEN/sendMessage" CODE=$(curl -s -o /dev/null -w "%{http_code}" $WEB) PING=$(ping -c1 -w1 google.com | wc -l) @@ -52,12 +54,20 @@ check_web() echo "${DATE} - ${WEB} - ${CODE}" >> ${LOG} if [ ${CODE} -eq '200' ]; then - printf "[+] ${WEB} is UP!\\n" + if [ -e /tmp/${DOWN}.down ]; then + rm /tmp/${DOWN}.down + curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MSG_UP" + fi rm ${LOCK} exit else - curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MSG" - rm ${LOCK} + if [ -e /tmp/${DOWN}.down ]; then + rm ${LOCK} + else + curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MSG" + touch /tmp/${DOWN}.down + rm ${LOCK} + fi fi }