david
c19aa59021
> ‘monitoring/check_for_ubuntu_release.sh’ < ‘diskmon.lst.sample’ > ‘monitoring/diskmon.lst.sample’ < ‘diskmon.sh’ > ‘monitoring/diskmon.sh’ < ‘free.sh’ > ‘monitoring/free.sh’ < ‘get_uptime.sh’ > ‘monitoring/get_uptime.sh’ < ‘heartbeat.sh’ > ‘monitoring/heartbeat.sh’
114 lines
2.2 KiB
Bash
114 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
#
|
|
# heartbeat survaillance
|
|
# script
|
|
#
|
|
|
|
# **** config section ****
|
|
|
|
author="david@socialnerds.org"
|
|
version="0.1"
|
|
sourcefile="/etc/hosts"
|
|
excludes="127.0.0.1 127.0.1.1 ::1 fe00::0 ff00::0 ff02::1 ff02::2 ff02::3"
|
|
options="-n -c 5 -i 0.2 -W 1"
|
|
maxloss="20%"
|
|
log2stdout="1"
|
|
logwhat="mbots_heartbeat"
|
|
configfile="/etc/mbots/mbots.conf"
|
|
giturl="git://git.aec.at/mbots.git"
|
|
|
|
|
|
# **** preflight ****
|
|
|
|
#read configfile
|
|
if [ -r $configfile ]; then
|
|
source $configfile
|
|
else
|
|
echo "ERROR: configfile not found. terminating."
|
|
exit 1
|
|
fi
|
|
|
|
#load bashlib
|
|
if [ -d $bashlibpath ]; then
|
|
source $bashlibpath/main
|
|
source $bashlibpath/logengine
|
|
log debug "preflight - logengine loaded"
|
|
else
|
|
echo "ERROR: bashlib not found. terminating."
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# **** function definition ****
|
|
|
|
check()
|
|
{
|
|
|
|
local ip=$1
|
|
|
|
echo $ip | grep ":" &> /dev/null
|
|
local isv4=$?
|
|
if [ $isv4 = "1" ]; then
|
|
# run ipv4 ping
|
|
local value=$(ping $options $ip | grep -o -e "[0-9]*%")
|
|
elif [ $isv4 = "0" ]; then
|
|
# run ipv6 ping
|
|
local value=$(ping6 $options $ip | grep -o -e "[0-9]*%")
|
|
fi
|
|
|
|
if [ ${value:0:$((${#value}-1))} -gt ${maxloss:0:$((${#maxloss}-1))} ]; then
|
|
log error "not able to reach $(echo $line | awk '{print $2}') at $ip"
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
# **** start of script ****
|
|
|
|
# set linecount to 1
|
|
linecount="1"
|
|
|
|
# read line by line of $sourcefile
|
|
while read line; do
|
|
|
|
#get first letter of line
|
|
fletter=${line:0:1}
|
|
if [ -z $fletter ]; then
|
|
#skip line, it's empty
|
|
:
|
|
elif [ $fletter = "#" ]; then
|
|
#skip line, it's a comment
|
|
:
|
|
else
|
|
#exclusion of $excludes
|
|
excluded="0"
|
|
for var in $excludes; do
|
|
#check if ip is excluded
|
|
if [ $(echo $line | awk '{print $1}') = $var ]; then
|
|
excluded="1"
|
|
break
|
|
fi
|
|
done
|
|
|
|
#run check function for ip if not excluded
|
|
if [ $excluded = "1" ]; then
|
|
continue
|
|
else
|
|
#run actual ping
|
|
check "$(echo $line | awk '{print $1}')"
|
|
fi
|
|
|
|
fi
|
|
|
|
#count lines
|
|
let linecount++
|
|
|
|
done < $sourcefile
|
|
|
|
|
|
exit 0
|
|
# **** end of script ****
|
|
|
|
|