From 67e911e3a7da6f81df725fdad8569266f84e18f9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 26 Jun 2023 21:53:39 +0300 Subject: [PATCH] added http/https site status to node notes Signed-off-by: Alex A. Naanou --- check-status | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ update-status | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 check-status create mode 100644 update-status diff --git a/check-status b/check-status new file mode 100644 index 0000000..0a485f5 --- /dev/null +++ b/check-status @@ -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 : diff --git a/update-status b/update-status new file mode 100644 index 0000000..228a352 --- /dev/null +++ b/update-status @@ -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 '#' + + 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 '#' + 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 :