proxmox-utils/check-status
Alex A. Naanou 67e911e3a7 added http/https site status to node notes
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-06-26 21:53:39 +03:00

57 lines
953 B
Bash

#!/usr/bin/bash
IFS=$'\n'
SITES=("$@")
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
local safe=--no-check-certificate
local response=$(\
wget -S --spider $safe $target 2>&1 \
| awk '/HTTP\// {print $2}' )
echo "COMMENT=$comment"
echo "URL=$target"
echo "RESPONSE=$response"
}
problems=
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 "
if [ $(grep '\(2[0-9][0-9]\|30[1-9]\|401\|501\)' <<<$res) ] ; then
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 :