You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
7 years ago
|
#!/usr/bin/bash
|
||
|
|
||
|
|
||
|
|
||
|
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
|
||
|
source $SCRIPTPATH/servers.private
|
||
|
|
||
|
checkAllSites(){
|
||
|
eval server=( \${$1[@]} )
|
||
|
for site in ${server[@]}; do
|
||
6 years ago
|
printf "%-35s | %s \n" "$site" "$(checkURL $site $1)"
|
||
7 years ago
|
done
|
||
|
}
|
||
|
|
||
|
# This function takes 1 parameter, the name of an array in which to check a random URL
|
||
|
checkRandomSite(){
|
||
|
#The server variable will be equal to whichever server array we are looking at
|
||
|
eval server=( \${$1[@]} )
|
||
|
random=$(( ( RANDOM % (${#server[@]} - 1) ) + 1 ))
|
||
|
urlToCheck=${server[$random]}
|
||
|
echo $urlToCheck
|
||
6 years ago
|
echo $(checkURL $urlToCheck $1)
|
||
7 years ago
|
}
|
||
|
|
||
|
checkURL(){
|
||
6 years ago
|
responce=$(curl -s --head -w %{http_code} $1 -L -o /dev/null --connect-timeout 20)
|
||
6 years ago
|
if [ "$responce" != 200 ]; then
|
||
6 years ago
|
pgrep -x dunst && notify-send -u critical "$1 is down" "<b>Server:</b> $2\n<b>Responce:</b> $responce" & disown
|
||
6 years ago
|
fi
|
||
7 years ago
|
echo $responce
|
||
|
}
|
||
|
|
||
|
if [ ! -z "$1" ]; then
|
||
|
if [ -z "$2" ]; then
|
||
|
checked=$(eval checkRandomSite $1)
|
||
|
checked=(${checked// / })
|
||
|
#echo ${checked[0]}
|
||
|
#echo ${checked[1]}
|
||
|
echo $1
|
||
|
echo ""
|
||
|
if [ "${checked[1]}" = "200" ]; then
|
||
|
echo "#00FF00"
|
||
|
else
|
||
|
echo "#FF8000"
|
||
6 years ago
|
|
||
7 years ago
|
fi
|
||
|
elif [ "$2" = "all" ]; then
|
||
|
checkAllSites $1
|
||
|
fi
|
||
|
else
|
||
|
echo Please specify a server name
|
||
|
fi
|