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

Merge branch '6468-docs-and-harmonize' into 'master'

6468-docs-and-harmonize

See merge request !129
parents 420afc9e a0a17b34
No related branches found
No related tags found
1 merge request!1296468-docs-and-harmonize
...@@ -12,26 +12,77 @@ ...@@ -12,26 +12,77 @@
# 2021-12-14 v1.3 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file # 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-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 # 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 . $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=1.6
. $(dirname $0)/inc_haproxy_cfg.sh . $(dirname $0)/inc_haproxy_cfg.sh
cfgfile=/etc/haproxy/haproxy.cfg
tmpfile=/tmp/check_haproxy_healthcheck_$$ 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 ph.require wget
cat $cfgfile >/dev/null if [ ! -f $HAPROXYcfgfile ]; then
if [ $? -ne 0 ]; then ph.abort "UNKNOWN: config file does not exist: $HAPROXYcfgfile"
ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... $(ls -l $cfgfile)"
fi fi
cat $cfgfile | grep " mode .*http" >/dev/null if ! cat $HAPROXYcfgfile >/dev/null 2>&1; then
if [ $? -ne 0 ]; 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" ph.abort "UNKNOWN: haproxy is not in http mode"
fi fi
......
...@@ -17,42 +17,23 @@ ...@@ -17,42 +17,23 @@
# 2021-12-14 v1.5 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file # 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-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_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_$$ tmpfile=/tmp/check_haproxy_status_$$
tmpfile2=/tmp/check_haproxy_status2_$$ tmpfile2=/tmp/check_haproxy_status2_$$
tmpfileping=/tmp/check_haproxy_status3_$$ 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 # functions
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# find a column number of a given field name in haproxy csv # find a column number of a given field name in haproxy csv
function getColnumber(){ function getColnumber(){
cat $tmpfile | head -1 | sed 's#,#\n#g' | grep -n "^$1$" | cut -f 1 -d ':' cat $tmpfile | head -1 | sed 's#,#\n#g' | grep -n "^$1$" | cut -f 1 -d ':'
...@@ -60,9 +41,9 @@ function getColnumber(){ ...@@ -60,9 +41,9 @@ function getColnumber(){
# get stats data from column [name] # get stats data from column [name]
function getColumn(){ function getColumn(){
typeset -i local _iNumber=$1 typeset -i _iNumber=$1
local _filter=$2 local _filter=$2
test -z $_filter && _filter='.*' test -z "$_filter" && _filter='.*'
grep "$_filter" $tmpfile | grep -v "stats_frontend" | cut -f 2,$_iNumber -d ',' grep "$_filter" $tmpfile | grep -v "stats_frontend" | cut -f 2,$_iNumber -d ','
} }
...@@ -84,6 +65,72 @@ function checkStatus(){ ...@@ -84,6 +65,72 @@ function checkStatus(){
echo ERROR echo ERROR
fi 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 # build url
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -102,7 +149,6 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) ...@@ -102,7 +149,6 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" )
# check output # check output
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# --- get status page # --- get status page
wget -T 5 -t 1 --no-check-certificate -O $tmpfile $url 2>/dev/null wget -T 5 -t 1 --no-check-certificate -O $tmpfile $url 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
...@@ -145,8 +191,6 @@ ph.status "FRONT: $statusFront - ${iFrontend} (max: ${iMaxConnFront}) .. BACK: $ ...@@ -145,8 +191,6 @@ ph.status "FRONT: $statusFront - ${iFrontend} (max: ${iMaxConnFront}) .. BACK: $
test -z "$statusExt" || echo "${statusExt}" test -z "$statusExt" || echo "${statusExt}"
# echo; echo DEBUG: ; cat $tmpfile # echo; echo DEBUG: ; cat $tmpfile
ph.perfadd "frontend" "${iFrontend}" ph.perfadd "frontend" "${iFrontend}"
ph.perfadd "frontend-max" "${iMaxConnFront}" ph.perfadd "frontend-max" "${iMaxConnFront}"
ph.perfadd "frontend-free" "${iFrontendFree}" ph.perfadd "frontend-free" "${iFrontendFree}"
...@@ -164,7 +208,7 @@ while read line ...@@ -164,7 +208,7 @@ while read line
do do
srv=$(echo $line | cut -f 1 -d ",") srv=$(echo $line | cut -f 1 -d ",")
val=$(echo $line | cut -f 2 -d ",") val=$(echo $line | cut -f 2 -d ",")
label=$(echo $srv | tr [:upper:] [:lower:]) # label=$(echo $srv | tr [:upper:] [:lower:])
# echo "${srv} - ${val}" # echo "${srv} - ${val}"
echo -n "${srv} - ${val} " echo -n "${srv} - ${val} "
......
...@@ -22,8 +22,8 @@ There is one include script used by all checks: ...@@ -22,8 +22,8 @@ There is one include script used by all checks:
* [check_eol](check_eol.md) * [check_eol](check_eol.md)
* [check_fs_errors](check_fs_errors.md) * [check_fs_errors](check_fs_errors.md)
* [check_fs_writable](check_fs_writable.md) * [check_fs_writable](check_fs_writable.md)
* check_haproxy_health * [check_haproxy_health](check_haproxy_health.md)
* check_haproxy_status * [check_haproxy_status](check_haproxy_status.md)
* check_memory * check_memory
* check_mysqlserver * check_mysqlserver
* check_netio * check_netio
......
# 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.
```
# 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;;
```
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# 2021-12-14 v1.0 <axel.hahn@iml.unibe.ch> init # 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 # 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-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 # full path to haproxy.cfg
...@@ -54,7 +55,7 @@ HAPROXYdoCache=0 ...@@ -54,7 +55,7 @@ HAPROXYdoCache=0
function cfgrewriter(){ function cfgrewriter(){
local _section= local _section=
IFS='' IFS=''
while read line test -f $HAPROXYcfgfile && while read line
do do
echo $line | grep "^[a-z]" >/dev/null echo $line | grep "^[a-z]" >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment