Skip to content

Instantly share code, notes, and snippets.

@jogerj
Last active May 16, 2023 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jogerj/cf71390cd1098d301f2c08e788328737 to your computer and use it in GitHub Desktop.
Save jogerj/cf71390cd1098d301f2c08e788328737 to your computer and use it in GitHub Desktop.
Check nextcloud for aliveness using tcp ping with lft, send notification to telegram if it's dead. See https://gist.github.com/jogerj/47eca63335c93b214c9bc72347139756
#!/bin/bash
source /root/telegram.sh
fixes_dir="/root"
check_website="nextcloud.acme.com"
ip_address="$(dig +short @1.1.1.1 $check_website)"
if [ "x$ip_address" == "x" ]; then
echo "[ERROR] $(date -R) - ${title} DNS record not found!" >> $fixes_dir/cloud_alive.log
if [ ! -f $fixes_dir/.cloudlivechecked ]; then
touch $fixes_dir/.cloudlivechecked;
echo "[WARN] $(date -R) - Sent DNS error notification for ${check_website}" >> $fixes_dir/cloud_alive.log
send_telegram "$check_website" "$(echo -e "Failed to resolve ${check_website}!")";
fi;
exit 1;
fi;
check="$(/usr/sbin/lft -S -z -d 443 ${check_website})"
check_alive="$(echo -e $check | grep -oP "$ip_address:443\s.+ms")"
if [ "x$check_alive" == "x" ]; then
echo "[ERROR] $(date -R) - ${check}" >> $fixes_dir/cloud_alive.log
if [ ! -f $fixes_dir/.cloudlivechecked ]; then
touch $fixes_dir/.cloudlivechecked;
echo "[WARN] $(date -R) - Sent error notification for ${check_website}" >> $fixes_dir/cloud_alive.log;
send_telegram "$check_website" "$(echo -e "${check}\n\nNextcloud failed to respond!")";
fi;
else
# all is good
if [ -f $fixes_dir/.cloudlivechecked ]; then
echo "[INFO] $(date -R) - Sent online notification for ${check_website}" >> $fixes_dir/cloud_alive.log
send_telegram "$check_website" "$(echo -e "${check}\n\nNextcloud is back online!")";
rm -f $fixes_dir/.cloudlivechecked
fi;
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment