#!/bin/bash
#
# test_apache
#
# Schickt Apache-Status ans ULS
#
# Voraussetzung: Modul status muss geladen sein
#
################################################
#
PORT=80
#
unset CONFIG ULSSECTION
#
while getopts s:c:p:? op
 do
  case "$op" in
   c) CONFIG="$OPTARG";;
   p) PORT=$OPTARG;;
   s) ULSSECTION="$OPTARG";;
   ?) echo "usage: `basename $0` [-c <config> | [-p <port>] [-s <ulssection>]] [-?] [<data> <time>]"
      exit 0;;
   *) echo "usage: `basename $0` [-p <port>] [-?] [<date> <time>]"
      exit 1;;
  esac
done
shift $(( $OPTIND -1))
#
. `dirname $0`/uls_header
#
function get_status()
{ ( echo "D;$DT;$ULSHOSTNAME;$2;Mod-Status;"
LANG=C httpget -tc 10 -t 10 -s -e $1 "server-status?auto" | sed 's/ \./ 0./' | awk -F ': *' '
$1 == "Total Accesses" { print "V;;;;;Total Accesses;"$2";#" }
$1 == "Total kBytes" { print "V;;;;;Total;"$2";kByte" }
$1 == "CPULoad" { printf("V;;;;;CPULoad;%.3f;%\n", $2)}
$1 == "Uptime" { print "V;;;;;Uptime;"$2";s" }
$1 == "ReqPerSec" { print "V;;;;;ReqPerSec;"$2";1/s" }
$1 == "BytesPerSec" { print "V;;;;;BytesPerSec;"$2";Byte/s" }
$1 == "BytesPerReq" { print "V;;;;;BytesPerReq;"$2";Byte" }
$1 == "BusyWorkers" { print "V;;;;;BusyWorkers;"$2";#" }
$1 == "IdleWorkers" { print "V;;;;;IdleWorkers;"$2";#" }
$1 == "ConnsTotal" { print "V;;;;;ConnsTotal;"$2";#" }
$1 == "ConnsAsyncWriting" { print "V;;;;;ConnsAsyncWriting;"$2";#" }
$1 == "ConnsAsyncKeepAlive" { print "V;;;;;ConnsAsyncKeepAlive;"$2";#" }
$1 == "ConnsAsyncClosing" { print "V;;;;;ConnsAsyncClosing;"$2";#" }
$1 == "Scoreboard" { print "V;;;;;MaxWorkers;"length($2)";#" }') | send_test_tab
}

if [[ -n "$CONFIG" ]]
 then
  export ULSHOSTNAME DT
  egrep '[[:blank:]]*[^#]*:[0-9]+' "$CONFIG" | while read con sect
   do
    get_status $con "${sect:-Apache}"
  done
else
  get_status 127.0.0.1:$PORT ${ULSSECTION:-Apache}
fi
