2023-06-26 21:53:39 +03:00
|
|
|
#!/usr/bin/bash
|
|
|
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
|
SITES=("$@")
|
|
|
|
|
|
2023-06-28 14:22:55 +03:00
|
|
|
TIMEOUT=${TIMEOUT:=10}
|
|
|
|
|
TRIES=${TRIES:=2}3
|
|
|
|
|
SAFE=${SAFE:=1}
|
|
|
|
|
|
|
|
|
|
OK_STATUS='2[0-9][0-9]|30[1-9]|401|501'
|
|
|
|
|
|
2023-06-26 21:53:39 +03:00
|
|
|
check(){
|
|
|
|
|
local comment=`sed \
|
|
|
|
|
-e 's/^\(.*\)https\?:\/\/.*$/\1/' \
|
|
|
|
|
-e 's/^\s*//;s/\s*$//' \
|
|
|
|
|
<<<$1`
|
|
|
|
|
local target=`sed \
|
|
|
|
|
-e 's/^.*\s*\(https\?:\/\/\)/\1/' \
|
|
|
|
|
-e 's/^\s*//;s/\s*$//' \
|
|
|
|
|
<<<$1`
|
|
|
|
|
|
|
|
|
|
# open port...
|
|
|
|
|
# nmap $target -Pn -p ssh | grep open
|
|
|
|
|
|
|
|
|
|
# http/https
|
2023-06-28 14:22:55 +03:00
|
|
|
if [ $SAFE ] ; then
|
|
|
|
|
local safe=--no-check-certificate
|
|
|
|
|
else
|
|
|
|
|
local safe
|
|
|
|
|
fi
|
2023-06-26 21:53:39 +03:00
|
|
|
local response=$(\
|
2023-06-28 14:22:55 +03:00
|
|
|
wget -S --spider -T $TIMEOUT --tries=$TRIES $safe $target 2>&1 \
|
2023-06-26 21:53:39 +03:00
|
|
|
| awk '/HTTP\// {print $2}' )
|
|
|
|
|
|
|
|
|
|
echo "COMMENT=$comment"
|
|
|
|
|
echo "URL=$target"
|
|
|
|
|
echo "RESPONSE=$response"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
problems=
|
2023-06-28 14:22:55 +03:00
|
|
|
status_pattern="\(${OK_STATUS//|/\\|}\)"
|
2023-06-26 21:53:39 +03:00
|
|
|
for site in ${SITES[@]} ; do
|
|
|
|
|
IFS=$'\n' \
|
|
|
|
|
res=($(check "$site"))
|
|
|
|
|
|
|
|
|
|
comment=${res[0]/COMMENT=/}
|
|
|
|
|
site=${res[1]/URL=/}
|
|
|
|
|
res=${res[2]/RESPONSE=/}
|
|
|
|
|
|
|
|
|
|
! [ -z $comment ] \
|
|
|
|
|
&& comment="$comment "
|
|
|
|
|
|
2023-06-28 14:22:55 +03:00
|
|
|
#if [ $(grep '\(2[0-9][0-9]\|30[1-9]\|401\|501\)' <<<$res) ] ; then
|
|
|
|
|
if [ $(grep "$status_pattern" <<<$res) ] ; then
|
2023-06-26 21:53:39 +03:00
|
|
|
state=OK
|
|
|
|
|
else
|
|
|
|
|
state="ERROR ($res)"
|
|
|
|
|
problems=1
|
|
|
|
|
fi
|
|
|
|
|
echo "${comment}${site} : ${state}"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ $problems ] ; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# vim:set ts=4 sw=4 :
|