diff --git a/check_haproxy_health b/check_haproxy_health index fc91dc8600eec450ed04f40f7701867a5a092bc4..7f7590d74cf52314fd3ad0623ebad86126141518 100755 --- a/check_haproxy_health +++ b/check_haproxy_health @@ -12,26 +12,77 @@ # 2021-12-14 v1.3 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file # 2022-04-01 v1.4 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes # 2022-10-21 v1.5 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2023-07-28 v1.6 <axel.hahn@unibe.ch> add help page # ====================================================================== . $(dirname $0)/inc_pluginfunctions + +export self_APPVERSION=1.6 + . $(dirname $0)/inc_haproxy_cfg.sh -cfgfile=/etc/haproxy/haproxy.cfg + tmpfile=/tmp/check_haproxy_healthcheck_$$ # ---------------------------------------------------------------------- -# pre checks +# functions # ---------------------------------------------------------------------- + +function showHelp(){ + local _self; _self=$(basename $0) +cat <<EOF +$( ph.showImlHelpHeader ) + +Check HA Proxy health. +The plugin reads $HAPROXYcfgfile to detect required status url. +It requires wget to handle the http request. + +Non OK values occur: + UNKNOWN - if $HAPROXYcfgfile cannot be read + - haproxy is not in http mode + - the url wasn't detected + - the detected status url doesn't send a response + ERROR - the detected status url did not respond with Http status + code 200 + +SYNTAX: +$_self [-h] + +OPTIONS: + + -h or --help show this help. + +EXAMPLE: + + $_self + +EOF +} + +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# --- check param -h +case "$1" in + "--help"|"-h") + showHelp + exit 0 + ;; + *) +esac + ph.require wget -cat $cfgfile >/dev/null -if [ $? -ne 0 ]; then - ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... $(ls -l $cfgfile)" +if [ ! -f $HAPROXYcfgfile ]; then + ph.abort "UNKNOWN: config file does not exist: $HAPROXYcfgfile" fi -cat $cfgfile | grep " mode .*http" >/dev/null -if [ $? -ne 0 ]; then +if ! cat $HAPROXYcfgfile >/dev/null 2>&1; then + ph.abort "UNKNOWN: unable to read ha proxy config $HAPROXYcfgfile ... $(ls -l $HAPROXYcfgfile)" +fi + +if ! cat $HAPROXYcfgfile | grep " mode .*http" >/dev/null; then ph.abort "UNKNOWN: haproxy is not in http mode" fi diff --git a/check_haproxy_status b/check_haproxy_status index 3823b4d8130233f2d2b2e70466d88cbefd3db80b..d3bce5a3af6b88ec291531f5c1607ee05c6cf9dd 100755 --- a/check_haproxy_status +++ b/check_haproxy_status @@ -16,43 +16,24 @@ # 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 # 2022-04-01 v1.6 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes -# 2022-10-21 v1.7 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2022-10-21 v1.7 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2023-07-28 v1.8 <axel.hahn@unibe.ch> add help page # ====================================================================== . $(dirname $0)/inc_pluginfunctions -. $(dirname $0)/inc_haproxy_cfg.sh -cfgfile=/etc/haproxy/haproxy.cfg +export self_APPVERSION=1.8 + +. $(dirname $0)/inc_haproxy_cfg.sh tmpfile=/tmp/check_haproxy_status_$$ tmpfile2=/tmp/check_haproxy_status2_$$ tmpfileping=/tmp/check_haproxy_status3_$$ -# ---------------------------------------------------------------------- -# pre checks -# ---------------------------------------------------------------------- -ph.require wget - -if [ ! -f $cfgfile ]; then - ph.abort "UNKNOWN: config file does not exist: $cfgfile" -fi - -cat $cfgfile >/dev/null -if [ $? -ne 0 ]; then - ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... `ls -l $cfgfile`" -fi - -cat $cfgfile | grep " mode .*http" >/dev/null -if [ $? -ne 0 ]; then - ph.abort "UNKNOWN: haproxy is not in http mode" -fi - - # ---------------------------------------------------------------------- # functions # ---------------------------------------------------------------------- - # find a column number of a given field name in haproxy csv function getColnumber(){ cat $tmpfile | head -1 | sed 's#,#\n#g' | grep -n "^$1$" | cut -f 1 -d ':' @@ -60,9 +41,9 @@ function getColnumber(){ # get stats data from column [name] function getColumn(){ - typeset -i local _iNumber=$1 + typeset -i _iNumber=$1 local _filter=$2 - test -z $_filter && _filter='.*' + test -z "$_filter" && _filter='.*' grep "$_filter" $tmpfile | grep -v "stats_frontend" | cut -f 2,$_iNumber -d ',' } @@ -84,6 +65,72 @@ function checkStatus(){ echo ERROR fi } + +# show help +function showHelp(){ + local _self; _self=$(basename $0) +cat <<EOF +$( ph.showImlHelpHeader ) + +Check HA Proxy statistics on frontend and backend. +It shows if the status is OPEN or UP and show counts of current connectons. + +The plugin reads $HAPROXYcfgfile to detect the required statistics url and get +csv data. +It requires wget to handle the http request. + +Non OK values occur: + UNKNOWN - if $HAPROXYcfgfile cannot be read + - haproxy is not in http mode + - the url wasn't detected + - the detected status url doesn't send a response + ERROR - a frontend status is not OPEN + - a backend status is not UP + +The plugin sends performance data. + +SYNTAX: +$_self [-h] + +OPTIONS: + + -h or --help show this help. + +EXAMPLE: + + $_self + +EOF +} + +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# --- check param -h +case "$1" in + "--help"|"-h") + showHelp + exit 0 + ;; + *) +esac + +ph.require wget + +if [ ! -f $HAPROXYcfgfile ]; then + ph.abort "UNKNOWN: config file does not exist: $HAPROXYcfgfile" +fi + +if ! cat $HAPROXYcfgfile >/dev/null; then + ph.abort "UNKNOWN: unable to read ha proxy config $HAPROXYcfgfile ... $(ls -l $HAPROXYcfgfile)" +fi + +if ! cat $HAPROXYcfgfile | grep " mode .*http" >/dev/null; then + ph.abort "UNKNOWN: haproxy is not in http mode" +fi + + # ---------------------------------------------------------------------- # build url # ---------------------------------------------------------------------- @@ -102,7 +149,6 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) # check output # ---------------------------------------------------------------------- - # --- get status page wget -T 5 -t 1 --no-check-certificate -O $tmpfile $url 2>/dev/null if [ $? -ne 0 ]; then @@ -145,8 +191,6 @@ ph.status "FRONT: $statusFront - ${iFrontend} (max: ${iMaxConnFront}) .. BACK: $ test -z "$statusExt" || echo "${statusExt}" # echo; echo DEBUG: ; cat $tmpfile - - ph.perfadd "frontend" "${iFrontend}" ph.perfadd "frontend-max" "${iMaxConnFront}" ph.perfadd "frontend-free" "${iFrontendFree}" @@ -162,11 +206,11 @@ ph.perfadd "backend-free" "${iBackendFree}" getColumn $colCurrentConnections | sed -n "2,$ p" >$tmpfile2 while read line do - srv=$(echo $line | cut -f 1 -d ",") - val=$(echo $line | cut -f 2 -d ",") - label=$(echo $srv | tr [:upper:] [:lower:]) + srv=$(echo $line | cut -f 1 -d ",") + val=$(echo $line | cut -f 2 -d ",") + # label=$(echo $srv | tr [:upper:] [:lower:]) - # echo "${srv} - ${val}" + # echo "${srv} - ${val}" echo -n "${srv} - ${val} " # v1.3: if it is a servername then ping to it diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index b5f91e82c333cf0801fb5b503f3a55fe44f68b04..4aed7e2eaa290e5c7348eb4f149a56a6865a9bdb 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -22,8 +22,8 @@ There is one include script used by all checks: * [check_eol](check_eol.md) * [check_fs_errors](check_fs_errors.md) * [check_fs_writable](check_fs_writable.md) -* check_haproxy_health -* check_haproxy_status +* [check_haproxy_health](check_haproxy_health.md) +* [check_haproxy_status](check_haproxy_status.md) * check_memory * check_mysqlserver * check_netio diff --git a/docs/20_Checks/check_haproxy_health.md b/docs/20_Checks/check_haproxy_health.md new file mode 100644 index 0000000000000000000000000000000000000000..ca7b59cee1c0c5d401a7bcd6d9f350dbdbbdb0f3 --- /dev/null +++ b/docs/20_Checks/check_haproxy_health.md @@ -0,0 +1,57 @@ +# Check HA-Proxy health + +## Introduction + +**check_haproxy_health** checks health url of haproxy service. +The url of it will be detected from /etc/haproxy/haproxy.cfg. + +## Syntax + +```txt +______________________________________________________________________ + +CHECK_HAPROXY_HEALTH +v1.6 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_haproxy_health.html +______________________________________________________________________ + +Check HA Proxy health. +The plugin reads /etc/haproxy/haproxy.cfg to detect required status url. +It requires wget to handle the http request. + +Non OK values occur: + UNKNOWN - if /etc/haproxy/haproxy.cfg cannot be read + - haproxy is not in http mode + - the url wasn't detected + - the detected status url doesn't send a response + ERROR - the detected status url did not respond with Http status + code 200 + +SYNTAX: +check_haproxy_health [-h] + +OPTIONS: + + -h or --help show this help. + +EXAMPLE: + + check_haproxy_health + +``` + +### Parameters + +(none) + +## Examples + +`$ check_haproxy_health` returns + +```txt +OK: HA Proxy http://localhost:8080/_haproxy_health_check is up and running. +``` diff --git a/docs/20_Checks/check_haproxy_status.md b/docs/20_Checks/check_haproxy_status.md new file mode 100644 index 0000000000000000000000000000000000000000..b7b233d0423887de942588d51b8a87840921a1a3 --- /dev/null +++ b/docs/20_Checks/check_haproxy_status.md @@ -0,0 +1,62 @@ +# Check HA-Proxy Status + +## Introduction + +**check_haproxy_health** show status and connections count on frontend and backend. + +## Syntax + +```txt +______________________________________________________________________ + +CHECK_HAPROXY_STATUS +v1.8 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_haproxy_status.html +______________________________________________________________________ + +Check HA Proxy statistics on frontend and backend. +It shows if the status is OPEN or UP and show counts of current connectons. + +The plugin reads /etc/haproxy/haproxy.cfg to detect the required statistics url and get +csv data. +It requires wget to handle the http request. + +Non OK values occur: + UNKNOWN - if /etc/haproxy/haproxy.cfg cannot be read + - haproxy is not in http mode + - the url wasn't detected + - the detected status url doesn't send a response + ERROR - a frontend status is not OPEN + - a backend status is not UP + +The plugin sends performance data. + +SYNTAX: +check_haproxy_status [-h] + +OPTIONS: + + -h or --help show this help. + +EXAMPLE: + + check_haproxy_status + +``` + +### Parameters + +(none) + +## Examples + +`$ check_haproxy_status` returns + +```txt +OK: FRONT: OPEN OPEN OPEN - 2 (max: 30010) .. BACK: UP UP UP - 0 (max: 3001) +FRONTEND - 2 BACKEND - 0 FRONTEND - 0 FRONTEND - 0 couchdb-0.example.com - 0 BACKEND - 0 couchdb-0.example.com - 0 couchdb-1.example.com - 0 couchdb-2.example.com - 0 BACKEND - 0 |frontend=2;; frontend-max=30010;; frontend-free=30008;; backend=0;; backend-max=3001;; backend-free=3001;; +``` diff --git a/inc_haproxy_cfg.sh b/inc_haproxy_cfg.sh index 8aea4a43bf57e13cc7e8bf5022fa68623a139903..d497baa4d1952207fb4734c3b068cc07c38b7994 100755 --- a/inc_haproxy_cfg.sh +++ b/inc_haproxy_cfg.sh @@ -8,6 +8,7 @@ # 2021-12-14 v1.0 <axel.hahn@iml.unibe.ch> init # 2022-10-21 v1.1 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space # 2023-06-09 v1.2 <axel.hahn@unibe.ch> take first haproxy stats port on multiple binds +# 2023-07-28 v1.3 <axel.hahn@unibe.ch> check existance of file $HAPROXYcfgfile # ====================================================================== # full path to haproxy.cfg @@ -54,7 +55,7 @@ HAPROXYdoCache=0 function cfgrewriter(){ local _section= IFS='' - while read line + test -f $HAPROXYcfgfile && while read line do echo $line | grep "^[a-z]" >/dev/null if [ $? -eq 0 ]; then