mirror of
https://github.com/flynx/proxmox-utils.git
synced 2025-10-28 10:40:07 +00:00
added http/https site status to node notes
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4d2d6a75c5
commit
67e911e3a7
56
check-status
Normal file
56
check-status
Normal file
@ -0,0 +1,56 @@
|
||||
#!/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 :
|
||||
50
update-status
Normal file
50
update-status
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
|
||||
CONFIG=/etc/pve/nodes/pve/config
|
||||
|
||||
TMP_TARGET=${CONFIG}.new-status
|
||||
|
||||
TARGET=${TARGET:=${TMP_TARGET}}
|
||||
|
||||
|
||||
if [ -e $TMP_TARGET ] ; then
|
||||
rm -f $TMP_TARGET
|
||||
fi
|
||||
|
||||
IFS=$'\n' \
|
||||
SITES=($(\
|
||||
sed -n '/STATUS BEGIN/,/STATUS END/p' "$CONFIG" \
|
||||
| sed \
|
||||
-e '1d;$d' \
|
||||
-e 's/^#//' \
|
||||
-e 's/^- //' \
|
||||
-e 's/^\**//' \
|
||||
-e 's/%3A/:/g' \
|
||||
-e 's/ : .*//' \
|
||||
| grep 'http'))
|
||||
|
||||
cp -f "$CONFIG" "$CONFIG".bak
|
||||
{
|
||||
sed '/STATUS BEGIN/q' "$CONFIG" | sed '$d'
|
||||
echo '#<!-- STATUS BEGIN -->'
|
||||
|
||||
for site in "${SITES[@]}" ; do
|
||||
./check-status "$site" \
|
||||
| sed \
|
||||
-e 's/^\s*\(.*ERROR.*$\)/**\1**/' \
|
||||
-e 's/^/#- /' \
|
||||
-e 's/$/\n#/'
|
||||
done
|
||||
echo "#_(checked on: `date +'%Y-%m-%d %H:%M'`)_"
|
||||
|
||||
echo '#<!-- STATUS END -->'
|
||||
sed -ne '/STATUS END/,$ p' "$CONFIG" | sed '1d'
|
||||
} > "$TARGET"
|
||||
|
||||
if [ -e $TMP_TARGET ] ; then
|
||||
mv -f "$TMP_TARGET" "$CONFIG"
|
||||
fi
|
||||
|
||||
|
||||
# vim:set ts=4 sw=4 nowrap :
|
||||
Loading…
x
Reference in New Issue
Block a user