parent
7896adc258
commit
45fc0cbca9
@ -0,0 +1 @@
|
|||||||
|
.httpcheck_telegram
|
@ -0,0 +1,7 @@
|
|||||||
|
# Bot Info
|
||||||
|
CHATID="5555555"
|
||||||
|
KEY="THISISAUNIQUEANDPRIVATEKEY"
|
||||||
|
|
||||||
|
# Site list (file location)
|
||||||
|
CHKLIST="${HOME}/.site_check"
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||||
|
|
||||||
|
# Load Telegram bot info
|
||||||
|
source .httpcheck_telegram #Provides KEY, CHATID, CHKLIST
|
||||||
|
|
||||||
|
TIME="10"
|
||||||
|
URL="https://api.telegram.org/bot$KEY/sendMessage"
|
||||||
|
|
||||||
|
#Telegram message function
|
||||||
|
send_message() {
|
||||||
|
curl -s --max-time $TIME -d "chat_id=${CHATID}&disable_web_page_preview=1&text=$1" $URL >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
get_http_code() {
|
||||||
|
curl -sILk --max-time $TIME $1 | grep HTTP | tail -n 1 | grep -Eo '[0-9]{3}' || printf '%s\n' 000
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check HTTP codes
|
||||||
|
for site in $(< $CHKLIST); do
|
||||||
|
respcode=$(get_http_code $site)
|
||||||
|
case $respcode in
|
||||||
|
000)
|
||||||
|
printf '%s\n' "[$(date '+%Y%m%d %H:%M:%S')]: PROBLEM -- $site: DNS record not found" >&2
|
||||||
|
send_message "HTTP/S Alert:%0A $site DNS record not found." && printf '%s\n' "Message sent via Telegram bot" >&2
|
||||||
|
;;
|
||||||
|
200)
|
||||||
|
printf '%s\n' "[$(date '+%Y%m%d %H:%M:%S')]: OK -- $site returns $respcode"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf '%s\n' "[$(date '+%Y%m%d %H:%M:%S')]: PROBLEM -- $site returns $respcode" >&2
|
||||||
|
send_message "HTTP/S Alert:%0A $site responding with $respcode." && printf '%s\n' "Message sent via Telegram bot" >&2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done || exit 1
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Reference in new issue