diff --git a/check_apache_requests b/check_apache_requests index 825d5cc4b7708321a2ebe54239cc263a49d95a83..89ba184d2269f6ba4f6f44477695ee374e012cd2 100755 --- a/check_apache_requests +++ b/check_apache_requests @@ -7,6 +7,7 @@ # script checks output of "/server-status" and counts scoreboard chars # ---------------------------------------------------------------------- # 2020-04-09 v1.0 <axel.hahn@iml.unibe.ch> +# 2021-03-11 v1.1 <axel.hahn@iml.unibe.ch> more error checks for output data # ====================================================================== . `dirname $0`/inc_pluginfunctions @@ -38,11 +39,10 @@ ph.require wget # --- get /server-status page wget --no-check-certificate -O $tmpfile $url 2>/dev/null if [ $? -ne 0 ]; then - ph.abort "UNKNOWN: url $url did not respond a server status. `wget --no-check-certificate -O - -S $url`" - exit 1 + rm -f $tmpfile + ph.abort "UNKNOWN: request to url $url failed. `wget --no-check-certificate -O - -S $url`" fi - # set default / override from command line params typeset -i iWarnLimit=` ph.getValueWithParam 75 w "$@"` typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` @@ -52,6 +52,11 @@ typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` iStart=` grep -n '<pre>' $tmpfile | cut -f 1 -d ':'` iEnd=` grep -n '</pre>' $tmpfile | cut -f 1 -d ':'` +if [ $iStart -eq 0 -o $iEnd -eq 0 ]; then + rm -f $tmpfile + ph.abort "UNKNOWN: url $url has no PRE tag for apache scroreboard. I guess it is not a server-status page." +fi + sed -n "${iStart},${iEnd}p" $tmpfile | sed 's#<.*>##g' | tr -d "\n" >$tmpfile2 # <p>Scoreboard Key:<br /> @@ -73,6 +78,11 @@ sed -n "${iStart},${iEnd}p" $tmpfile | sed 's#<.*>##g' | tr -d "\n" >$tmpfile2 # total slots available iSlots=`cat $tmpfile2 | wc -m` +if [ $iSlots -eq 0 ]; then + rm -f $tmpfile $tmpfile2 + ph.abort "UNKNOWN: url $url has no count of slots. I guess it is not a server-status page or option for Extended status is off." +fi + # running apache processes waiting for a request iIdle=iCount=`sed -e "s/[^_]//g" $tmpfile2 | wc -m`