#!/bin/bash
isp_host="IP_НА_GATEWAY"
bg_host="194.145.63.12"
int_host="8.8.8.8"
no_net_dir="/home/$(whoami)/Desktop"
no_net_file0="НЯМА_МРЕЖА"
no_net_file1="НЯМА_ИНТЕРНЕТ"
no_net_file2="НЯМА_МЕЖДУНАРОДЕН_ИНТЕРНЕТ"
sms_from="nqkakyv@email.adres"
sms_to="35988xxxxxxx@sms.mtel.net"
info0="Целият Нет спря!"
info1="Има връзка до доставчика, ама към Интернет - не!"
info2="Има връзка към България, ама международния Нет го няма!"
info3="Международният Нет дойде!"
info4="Има Нет, има Нет... и всичко е наред!"
########## НЕ Е НУЖНО ПОВЕЧЕ РЕДАКТИРАНЕ ##########
ping -c 1 -w 10 $int_host &>/dev/null
if [ $? -ne 0 ] ; then
ping -c 1 -w 2 $bg_host &>/dev/null
if [ $? -ne 0 ] ; then
ping -c 1 -w 2 $isp_host &>/dev/null
if [ $? -ne 0 ] ; then
if [ ! -e $no_net_dir/$no_net_file0 ] ; then
if [ -e $no_net_dir/$no_net_file1 ] ; then
rm $no_net_dir/$no_net_file1
fi
if [ -e $no_net_dir/$no_net_file2 ] ; then
rm $no_net_dir/$no_net_file2
fi
echo "[`date`]: Host is DOWN. Gateway is DOWN" >> /monitor/connection_log
touch $no_net_dir/$no_net_file0
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --warning --text="$info0"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/status/dialog-warning.png "$info0"
fi
else
if [ ! -e $no_net_dir/$no_net_file1 ] ; then
if [ -e $no_net_dir/$no_net_file0 ] ; then
rm $no_net_dir/$no_net_file0
fi
if [ -e $no_net_dir/$no_net_file2 ] ; then
rm $no_net_dir/$no_net_file2
fi
echo "[`date`]: The BG and INT connection to Host is DOWN" >> /monitor/connection_log
touch $no_net_dir/$no_net_file1
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --warning --text="$info1"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/status/dialog-warning.png "$info1"
fi
fi
else
if [ ! -e $no_net_dir/$no_net_file2 ] ; then
if [ -e $no_net_dir/$no_net_file0 ] ; then
rm $no_net_dir/$no_net_file0
fi
if [ -e $no_net_dir/$no_net_file1 ] ; then
rm $no_net_dir/$no_net_file1
fi
echo "[`date`]: The INT connection to Host is DOWN" >> /monitor/connection_log
touch $no_net_dir/$no_net_file2
echo 'The INT connection to Host is DOWN' | mail -a "From: $sms_from" -t $sms_to
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --warning --text="$info2"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/status/dialog-warning.png "$info2"
fi
fi
else
if [ -e $no_net_dir/$no_net_file2 ] ; then
echo "[`date`]: The INT connection to Host is UP" >> /monitor/connection_log
rm $no_net_dir/$no_net_file2
echo 'The INT connection to Host is UP' | mail -a "From: $sms_from" -t $sms_to
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --info --text="$info3"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/emblems/emblem-default.png "$info3"
else
if [ -e $no_net_dir/$no_net_file1 ] ; then
echo "[`date`]: The BG and INT connection to Host is UP" >> /monitor/connection_log
rm $no_net_dir/$no_net_file1
echo 'The BG and INT connection to Host is UP' | mail -a "From: $sms_from" -t $sms_to
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --info --text="$info4"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/emblems/emblem-default.png "$info4"
else
if [ -e $no_net_dir/$no_net_file0 ] ; then
echo "[`date`]: Host is UP. Gateway is UP" >> /monitor/connection_log
rm $no_net_dir/$no_net_file0
echo 'Host is UP' | mail -a "From: $sms_from" -t $sms_to
#export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/zenity --info --text="$info4"
export DISPLAY=:0 && LC_ALL=bg_BG.UTF-8 /usr/bin/notify-send -t 15000 -i /usr/share/icons/gnome/48x48/emblems/emblem-default.png "$info4"
fi
fi
fi
fi