73 lines
1.6 KiB
Bash
73 lines
1.6 KiB
Bash
#Copyright (C) 2016,2023 Weber Yann
|
|
#
|
|
#This program is free software; you can redistribute it and/or modify
|
|
#it under the terms of the GNU General Public License as published by
|
|
#the Free Software Foundation; either version 3 of the License, or
|
|
#any later version.
|
|
#
|
|
#This program is distributed in the hope that it will be useful,
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
#GNU General Public License for more details.
|
|
#
|
|
#You should have received a copy of the GNU General Public License
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
_check_ping() {
|
|
expt=$1
|
|
hostname=$2
|
|
proto=$3
|
|
count=$4
|
|
case "$proto" in
|
|
ipv4)
|
|
protoping="ping -4";;
|
|
ipv6)
|
|
protoping="ping -6";;
|
|
*)
|
|
protoping="ping";;
|
|
esac
|
|
if [ -z "$count" ]
|
|
then
|
|
count=5
|
|
fi
|
|
|
|
if $protoping -i 0.2 -c "$count" "$hostname" >/dev/null
|
|
then
|
|
if [ "$expt" = "ping" ]
|
|
then
|
|
success "successfully send $count ping $proto to '$hostname'"
|
|
else
|
|
fail "$hostname replied to $count ping $proto"
|
|
fi
|
|
else
|
|
if [ "$expt" = "ping" ]
|
|
then
|
|
fail "unable to ping '$hostname'"
|
|
else
|
|
success "unable to ping '$hostname'"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_ping() {
|
|
_check_ping "ping" "$1" "$2" "$3" "$4"
|
|
}
|
|
|
|
check_noping() {
|
|
_check_ping "noping" "$1" "$2" "$3" "$4"
|
|
}
|
|
|
|
|
|
check_dns() {
|
|
hostname=$1
|
|
field=$2
|
|
expt=$3
|
|
result=$(dig +short "$hostname" "$field")
|
|
if echo "$result" | grep -e "$expt" >/dev/null
|
|
then
|
|
success "DNS replied '$expt' for '$field $hostname'"
|
|
else
|
|
fail "Unexpected DNS reply '$result' expecting '$expt' for '$hostname $field'"
|
|
fi
|
|
}
|
|
|