#!/bin/bash #\ # \ # \_ _ _ _ _ _ _ _ _ _ _ _ _ # #\ # # \ # heartbeat monitoring # \ # script # / # # / # _ _ _ _ _ _ _ _ _ _ _ _ _#/ # / # / #/ # **** config section **** #do not touch as long as you're not me author="david@socialnerds.org" version="0.1" giturl="git://git.aec.at/mbots.git" configfile="/etc/mbots/mbots.conf" log2stdout="1" logwhat="mbots_heartbeat" file="/etc/mbots/heartbeat.lst" # **** 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 #check environment log info "**** starting heartbeat bot ****" #set linecount to 1 linecount="1" #read one line at a time while read line; do #find first letter to determine if line is empty or a comment fletter=${line:0:1} #check for first letter if [ -z $fletter ]; then #skip line it's empty log debug "config - skipping line $linecount in $file: it's empty" elif [ $fletter = "#" ]; then #skip line it's a comment log debug "config - skipping line $linecount in $file: it's a comment" else # getting hostname from heartbeat.lst hostname=$(echo $line | awk '{print $1}') log debug "checking $hostname" #check ipv6 ipv6=$(dig $hostname AAAA +short | grep ":") if [ -z "$ipv6" ]; then log warning "no ipv6 record for $hostname" log debug "checking /etc/hosts" hosts=$(cat /etc/hosts | grep -iw $hostname | awk '{print $1}' | grep ":") if [ -z $hosts ]; then log warning "no ipv6 hosts entry found" else for var in $hosts; do log info "pinging $hostname($var)" ping6 -c 1 $var &> /dev/null err=$? if [ $err = "0" ]; then log info "$hostname($var) is reachable" else log error "$hostname($var) is not reachable" fi done fi else for var in $ipv6; do log info "pinging $hostname($var)" ping6 -c 1 $var &> /dev/null err=$? if [ $err = "0" ]; then log info "$hostname($var) is reachable" else log error "$hostname($var) is not reachable" fi done fi #check ipv4 ipv4=$(dig $hostname A +noall +answer | grep -v ";" | grep -v "CNAME" | awk '{print $5}' | grep -v "^$") if [ -z "$ipv4" ]; then log warning "no ipv4 record for $hostname" log debug "checking /etc/hosts" hosts=$(cat /etc/hosts | grep -iw $hostname | awk '{print $1}' | grep ".") if [ -z $hosts ]; then log warning "no ipv4 hosts entry found" else for var in $hosts; do log info "pinging $hostname($var)" ping -c 1 $var &> /dev/null err=$? if [ $err = "0" ]; then log info "$hostname($var) is reachable" else log error "$hostname($var) is not reachable" fi done fi else for var in $ipv4; do log info "pinging $hostname($var)" ping -c 1 $var &> /dev/null err=$? if [ $err = "0" ]; then log info "$hostname($var) is reachable" else log error "$hostname($var) is not reachable" fi done fi fi let linecount++ done < $file log debug "**** all checks done ****" # **** end of script ****