diff --git a/check_haproxy_health b/check_haproxy_health index ae648b0e293df3bacc3cad478d14a8e47abc785f..ae27ba1e312377a13e8d8e9cba178ff530992ae6 100755 --- a/check_haproxy_health +++ b/check_haproxy_health @@ -39,6 +39,9 @@ fi # ---------------------------------------------------------------------- url=$( getHealthUri ) +if [ -z "$url" ]; then + ph.abort "UNKNOWN: Unable to detect url for health status." +fi # remove password for showing url in output safeurl=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) diff --git a/check_haproxy_status b/check_haproxy_status index bf544119706fe1934d2b03a819ac774ccee11a7b..df5d4425fb665c3f9b1c49ba2b4e86c79d01dd42 100755 --- a/check_haproxy_status +++ b/check_haproxy_status @@ -14,12 +14,13 @@ # 2020-04-29 v1.2 <axel.hahn@iml.unibe.ch> parse ini section by given section # 2020-06-03 v1.3 <axel.hahn@iml.unibe.ch> added ping to each backend server # 2020-12-03 v1.4 <axel.hahn@iml.unibe.ch> added support of multiple front- and backends +# 2021-12-14 v1.5 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file # ====================================================================== . `dirname $0`/inc_pluginfunctions +. `dirname $0`/inc_haproxy_cfg.sh cfgfile=/etc/haproxy/haproxy.cfg -cfgfile2=/tmp/haproxy.config tmpfile=/tmp/check_haproxy_status_$$ tmpfile2=/tmp/check_haproxy_status2_$$ @@ -51,51 +52,6 @@ fi # functions # ---------------------------------------------------------------------- -# rewrite the ha proxy config file to parse it by section -function cfgrewriter(){ - local _section= - IFS='' - while read line - do - echo $line | grep "^[a-z]" >/dev/null - if [ $? -eq 0 ]; then - _section=$line - echo "# new section: $_section" - fi - echo $line | grep "^\ \ [a-z]*" >/dev/null - if [ $? -eq 0 ]; then - echo -n "$_section: " - echo $line | sed "s#\ \ # #g" - fi - done < $cfgfile -} - -# get a value from a given a given section -function _getCfgVarFromSection(){ - local _var=$1 - local _section=$2 - - grep "^${_section}:\ \ ${_var}\ " $cfgfile2 >/dev/null && ( - typeset -i local _iColumnVal=`echo "${_section}: $_var" | wc -c`+1 - grep "^${_section}:\ \ ${_var}\ " $cfgfile2 | cut -c ${_iColumnVal}- - ) -} - -# get a value from config - with autoscan of other sections -function getCfgvar(){ - local _var=$1 - local _section=$2 - - _getCfgVarFromSection "${_var}" "${_section}" \ - || _getCfgVarFromSection "${_var}" "frontend stats_frontend" \ - || _getCfgVarFromSection "${_var}" "frontend couchdb_frontend" \ - || _getCfgVarFromSection "${_var}" "frontend postgresql_frontend" \ - || _getCfgVarFromSection "${_var}" "frontend opencpu" \ - || _getCfgVarFromSection "${_var}" "frontend apache_fop" \ - || _getCfgVarFromSection "${_var}" "defaults" \ - || _getCfgVarFromSection "${_var}" "global" - -} # find a column number of a given field name in haproxy csv function getColnumber(){ @@ -132,32 +88,15 @@ function checkStatus(){ # build url # ---------------------------------------------------------------------- -cfgrewriter >$cfgfile2 - -# getCfgvar "bind" "frontend stats_frontend" -# getCfgvar "stats auth" "frontend stats_frontend" -# exit - -proto=http -auth= -host=localhost -typeset -i port=80 -uri= - -getCfgvar "bind" "frontend stats_frontend" | grep "\ ssl\ " >/dev/null && proto=https - -auth=`getCfgvar "stats auth" "frontend stats_frontend"` -port=`getCfgvar "bind" "frontend stats_frontend" | cut -f 2 -d ':' | cut -f 1 -d " "` -host=`getCfgvar "bind" "frontend stats_frontend" | cut -f 1 -d ':'` -uri=` getCfgvar "stats uri" "frontend stats_frontend"` - -if [ "$host" = "*" ]; then - host="localhost" +url=$( getStatusUri ) +if [ -z "$url" ]; then + ph.abort "UNKNOWN: Unable to detect url for status page." fi -url="$proto://${auth}@${host}:${port}${uri};csv;norefresh" -urlmasked="$proto://*password*@${host}:${port}${uri};csv;norefresh" +url="${url};csv;norefresh" +# remove password for showing url in output +urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) # ---------------------------------------------------------------------- # check output @@ -167,7 +106,7 @@ urlmasked="$proto://*password*@${host}:${port}${uri};csv;norefresh" # --- get status page wget --no-check-certificate -O $tmpfile $url 2>/dev/null if [ $? -ne 0 ]; then - rm -f $tmpfile $cfgfile2 + rm -f $tmpfile ph.abort "UNKNOWN: url $urlmasked did not respond. `wget --no-check-certificate -O - -S $url`" fi @@ -252,7 +191,7 @@ do done < $tmpfile2 -rm -f $cfgfile2 $tmpfile $tmpfile2 2>/dev/null +rm -f $tmpfile $tmpfile2 2>/dev/null ph.exit # ---------------------------------------------------------------------- diff --git a/inc_haproxy_cfg.sh b/inc_haproxy_cfg.sh index 6e1a735a7c9746791ae0913ce1bc0a5b997f7e8b..02860befb2159cda26b99bd6c41bc8d6c4499d44 100644 --- a/inc_haproxy_cfg.sh +++ b/inc_haproxy_cfg.sh @@ -19,7 +19,7 @@ HAPROXYdoCache=0 # TESTING ONLY -# HAPROXYcfgfile=./haproxy-ldap01.cfg +# HAPROXYcfgfile=./haproxy-01.cfg # /TESTING