Skip to content
Snippets Groups Projects
Commit e002363f authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

haproxy status: use updated haproxy paser in sourced file

parent a990964c
No related branches found
No related tags found
No related merge requests found
......@@ -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" )
......
......@@ -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
# ----------------------------------------------------------------------
......@@ -19,7 +19,7 @@ HAPROXYdoCache=0
# TESTING ONLY
# HAPROXYcfgfile=./haproxy-ldap01.cfg
# HAPROXYcfgfile=./haproxy-01.cfg
# /TESTING
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment