Commit Diff


commit - 5c52caa3f25510f6fe62f546cb41c2645de7f5d6
commit + 618bc9a04d57ec3d64fba2d464838bd00cfc9f8f
blob - /dev/null
blob + b69ee834954057f5ab12b499835a1e5ed33c2188 (mode 644)
--- /dev/null
+++ LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2021 gonzalo-
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
blob - /dev/null
blob + 59aaab307c53730048e92fe09aa9d21734bb32ee (mode 644)
--- /dev/null
+++ README.md
@@ -0,0 +1,43 @@
+# Telegram Bot - Web Check
+Little depless bot for telegram that checks if a site is up or down by the HTTP code
+
+## Requirements
+You need a telegram bot for this, so for that you should follow the official
+documentation:
+
+[https://core.telegram.org/bots](https://core.telegram.org/bots)
+
+Or just "talk" with the following bots and follow the steps:
+
+[Bot Father](https://t.me/botfather)
+[Bot ID](https://t.me/idbot)
+
+## Usage
+I'm using this in a really simple way, just to get an extra check from
+"outside" of my websites besides my real monitoring system.
+
+### List of sites
+```
+$ pwd
+/home/gonzalo/monitoring
+$ cat webs.txt
+openbsd.org
+foobar.org
+foobar.com
+f00bar.org
+f00bar.com
+poop.org
+poop.com.ar
+$ touch /var/log/web-checks.log
+$ doas chown gonzalo:gonzalo /var/log/web-checks.log
+$ for i in $(cat webs.txt); do sh tg-webcheck $i; done
+```
+
+### Just one site
+```
+$ pwd
+/home/gonzalo/monitoring
+$ touch /var/log/web-checks.log
+$ doas chown gonzalo:gonzalo /var/log/web-checks.log
+$ sh tg-webcheck poop.org
+```
blob - /dev/null
blob + 64e04821860b950ef1e808fdc66c05e82ab93b89 (mode 755)
--- /dev/null
+++ tg-webcheck
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+## Debug
+#set -x
+
+## Variables
+WEB=$1
+DATE=$(date '+%a %d %b %H:%M')
+## You get it using: @BotFather
+## CHANGEME
+TOKEN="1831282803:AAEYaGsaj6vfIhatH2Y6hOxMY_Pkfs-_8"
+## You get it using: @myidbot
+## CHANGEME
+CHAT_ID="391821769"
+MSG="The Site ${WEB} is DOWN"
+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)
+LOG="/var/log/web-checks.log"
+LOCK="/tmp/web-check.lock"
+
+## Check link
+if [ ! "${PING}" -lt "1" ]; then
+	printf ""
+else
+	printf "[+] No Internet.\\n"
+	exit 2
+fi
+
+## Let's avoid run this 93103 times per hour
+check_lock()
+{
+	if [ -e "${LOCK}" ]; then
+		printf "[+] Already a ${0##*/} running, look at .lock on /tmp\\n"
+		exit 2
+	fi
+
+	touch ${LOCK}
+}
+
+## Logs are always useful
+check_log()
+{
+	if [ -e "${LOG}" ]; then
+		touch ${LOG}
+	fi
+}
+
+## Is it UP (200) or DOWN (000 or others)
+check_web()
+{
+	echo "${DATE} - ${WEB} - ${CODE}" >> ${LOG}
+
+	if [ ${CODE} -eq '200' ]; then
+		printf "[+] ${WEB} is UP!\\n"
+		rm ${LOCK}
+		exit
+	else
+		curl -s -X POST $URL -d chat_id=$CHAT_ID -d text="$MSG"
+		rm ${LOCK}
+	fi
+}
+
+check_lock
+check_log
+check_web