Notify via Telegram or email if host down

This very simple bash script is useful for notify via telegram or email if host not respond echo request (ping). First its necessary create a telegram BOT and edit the fields of script with YOUR UNIQUE chat id and token. Later add periodical execution using cron in server and grant execution rights. You can edit or customize according to your needs.

#!/bin/bash
# Notificar via telegram o email si un host no responde ping
# Send Email or Telegram notification if host not respond to ping (icmp)
# http://jose.marcano.co

# DESCOMENTAR PARA NOTIFICAR VIA EMAIL | Uncomment for email notification 
#NOTIFYEMAIL=test@example.com 

SERVERIP=172.16.3.6
NOW=`date '+%d-%m-%Y %r'`
chat_id="XXXXXXXXX" YOUR CHAT TELEGRAM ID
token="693340369:AAGx9dg53dgh64fKZWmimoTuotz_RW55555" YOUR TELEGRAM BOT TOKEN
texto=" WARNING | SHAIO | El servidor Proxmox MG no responde "
msg=$NOW" | "$texto

ping -c 3 $SERVERIP > /dev/null 2>&1
if [ $? -ne 0 ]
then

# Use your favorite mailer here:
#mailx -s "Server $SERVERIP is down" -t "$NOTIFYEMAIL" < /dev/null curl -s "https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=$msg" >> /dev/null

fi

uncomment this line for append msg to local log in server
#echo $msg >> /var/log/custom/message.log