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

Merge branch 'add-wget-timeout' into 'master'

use wget default params; shell fixes

See merge request !11
parents 6520c344 aeaaacf3
No related branches found
No related tags found
1 merge request!11use wget default params; shell fixes
...@@ -10,14 +10,19 @@ ...@@ -10,14 +10,19 @@
# 2020-05-04 v1.1 <axel.hahn@iml.unibe.ch> show message if monitor-uri was not set # 2020-05-04 v1.1 <axel.hahn@iml.unibe.ch> show message if monitor-uri was not set
# 2020-12-03 v1.2 <axel.hahn@iml.unibe.ch> loop over multiple frontend status urls # 2020-12-03 v1.2 <axel.hahn@iml.unibe.ch> loop over multiple frontend status urls
# 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
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
. `dirname $0`/inc_haproxy_cfg.sh . $(dirname $0)/inc_haproxy_cfg.sh
cfgfile=/etc/haproxy/haproxy.cfg cfgfile=/etc/haproxy/haproxy.cfg
tmpfile=/tmp/check_haproxy_healthcheck_$$ tmpfile=/tmp/check_haproxy_healthcheck_$$
paramsWget="-T 5 -t 1 --no-check-certificate"
# ^ ^
# | tries = 1
# timeout in seconds
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -27,7 +32,7 @@ ph.require wget ...@@ -27,7 +32,7 @@ ph.require wget
cat $cfgfile >/dev/null cat $cfgfile >/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... `ls -l $cfgfile`" ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... $(ls -l $cfgfile)"
fi fi
cat $cfgfile | grep "\ mode\ .*http" >/dev/null cat $cfgfile | grep "\ mode\ .*http" >/dev/null
...@@ -47,16 +52,16 @@ fi ...@@ -47,16 +52,16 @@ fi
safeurl=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) safeurl=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" )
# --- get status page # --- get status page
wget --no-check-certificate -O $tmpfile $url 2>/dev/null wget $paramsWget -O $tmpfile $url 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f $tmpfile rm -f $tmpfile
ph.abort "UNKNOWN: url $safeurl did not respond. `wget --no-check-certificate -O - -S $url`" ph.abort "UNKNOWN: url $safeurl did not respond. $(wget wget $paramsWget -O - -S $url)"
fi fi
grep "200 OK" $tmpfile >/dev/null grep "200 OK" $tmpfile >/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ph.setStatus "error" ph.setStatus "error"
ph.status "url $safeurl did not contain 200 OK. `wget --no-check-certificate -O - -S $url`" ph.status "url $safeurl did not contain 200 OK. $(wget wget $paramsWget -O - -S $url)"
else else
ph.status "HA Proxy $safeurl is up and running." ph.status "HA Proxy $safeurl is up and running."
fi fi
......
...@@ -15,10 +15,11 @@ ...@@ -15,10 +15,11 @@
# 2020-06-03 v1.3 <axel.hahn@iml.unibe.ch> added ping to each backend server # 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 # 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 # 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
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
. `dirname $0`/inc_haproxy_cfg.sh . $(dirname $0)/inc_haproxy_cfg.sh
cfgfile=/etc/haproxy/haproxy.cfg cfgfile=/etc/haproxy/haproxy.cfg
...@@ -26,6 +27,11 @@ tmpfile=/tmp/check_haproxy_status_$$ ...@@ -26,6 +27,11 @@ 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_$$
paramsWget="-T 5 -t 1 --no-check-certificate"
# ^ ^
# | tries = 1
# timeout in seconds
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# pre checks # pre checks
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -102,28 +108,28 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) ...@@ -102,28 +108,28 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" )
# --- get status page # --- get status page
wget --no-check-certificate -O $tmpfile $url 2>/dev/null wget $paramsWget -O $tmpfile $url 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f $tmpfile rm -f $tmpfile
ph.abort "UNKNOWN: url $urlmasked did not respond. `wget --no-check-certificate -O - -S $url`" ph.abort "UNKNOWN: url $urlmasked did not respond. $(wget --no-check-certificate -O - -S $url)"
fi fi
colLimit=`getColnumber "slim"` colLimit=$(getColnumber "slim")
colCurrentConnections=`getColnumber "scur"` colCurrentConnections=$(getColnumber "scur")
colStatus=`getColnumber "status"` colStatus=$(getColnumber "status")
statusFront=`getColumn $colStatus ",FRONTEND," | cut -f 2 -d "," | tr "\n" " "` statusFront=$(getColumn $colStatus ",FRONTEND," | cut -f 2 -d "," | tr "\n" " ")
statusBack=` getColumn $colStatus ",BACKEND," | cut -f 2 -d "," | tr "\n" " "` statusBack=$( getColumn $colStatus ",BACKEND," | cut -f 2 -d "," | tr "\n" " ")
typeset -i iMaxConnFront=`getColSum $colLimit ",FRONTEND,"` typeset -i iMaxConnFront=$(getColSum $colLimit ",FRONTEND,")
typeset -i iMaxConnBack=` getColSum $colLimit ",BACKEND,"` typeset -i iMaxConnBack=$( getColSum $colLimit ",BACKEND,")
typeset -i iFrontend=`getColSum $colCurrentConnections ",FRONTEND,"` typeset -i iFrontend=$(getColSum $colCurrentConnections ",FRONTEND,")
typeset -i iFrontendFree=$iMaxConnFront-$iFrontend typeset -i iFrontendFree=$iMaxConnFront-$iFrontend
typeset -i iBackend=` getColSum $colCurrentConnections ",BACKEND," ` typeset -i iBackend=$( getColSum $colCurrentConnections ",BACKEND," )
typeset -i iBackendFree=$iMaxConnBack-$iBackend typeset -i iBackendFree=$iMaxConnBack-$iBackend
statusExt= statusExt=
...@@ -160,9 +166,9 @@ ph.perfadd "backend-free" "${iBackendFree}" ...@@ -160,9 +166,9 @@ ph.perfadd "backend-free" "${iBackendFree}"
getColumn $colCurrentConnections | sed -n "2,$ p" >$tmpfile2 getColumn $colCurrentConnections | sed -n "2,$ p" >$tmpfile2
while read line 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} "
......
...@@ -19,10 +19,11 @@ ...@@ -19,10 +19,11 @@
# 2019-05-10 v1.0 ah,ds # 2019-05-10 v1.0 ah,ds
# 2019-05-22 v1.1 show built date # 2019-05-22 v1.1 show built date
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions # 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2022-04-01 v1.3 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
tmpOk=/tmp/check_opencpu-ok tmpOk=/tmp/check_opencpu-ok
tmpErr=/tmp/check_opencpu-error tmpErr=/tmp/check_opencpu-error
...@@ -30,6 +31,11 @@ ocpuUrl=http://localhost/ocpu ...@@ -30,6 +31,11 @@ ocpuUrl=http://localhost/ocpu
packages="eosceGLM eosceLinReg eosceReliability eosceReporter msrdAnalytics" packages="eosceGLM eosceLinReg eosceReliability eosceReporter msrdAnalytics"
paramsWget="-T 5 -t 1 --no-check-certificate"
# ^ ^
# | tries = 1
# timeout in seconds
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -40,11 +46,11 @@ function checkOpenCpuPackage(){ ...@@ -40,11 +46,11 @@ function checkOpenCpuPackage(){
pkgUrl=$ocpuUrl/library/$package/info pkgUrl=$ocpuUrl/library/$package/info
tmpfile=/tmp/check_opencpu-$package tmpfile=/tmp/check_opencpu-$package
wget -O $tmpfile $pkgUrl 2>/dev/null wget $paramsWget -O $tmpfile $pkgUrl 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: package is NOT available [$package]" >>$tmpErr echo "ERROR: package is NOT available [$package]" >>$tmpErr
else else
echo "OK: package is available [$mypackage] .. Build: `cat $tmpfile | grep "^Built" | cut -c 21-`" >>$tmpOk echo "OK: package is available [$mypackage] .. Build: $(cat $tmpfile | grep "^Built" | cut -c 21-)" >>$tmpOk
fi fi
rm -f $tmpfile 2>/dev/null rm -f $tmpfile 2>/dev/null
} }
...@@ -65,10 +71,10 @@ if [ $? -ne 0 ]; then ...@@ -65,10 +71,10 @@ if [ $? -ne 0 ]; then
fi fi
# ----- check if openCpu is running # ----- check if openCpu is running
wget -O /dev/null $ocpuUrl 2>/dev/null wget $paramsWget -O /dev/null $ocpuUrl 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: unable to connect to openCpu with $ocpuUrl" echo "ERROR: unable to connect to openCpu with $ocpuUrl"
wget -O /dev/null -S $ocpuUrl wget $paramsWget -O /dev/null -S $ocpuUrl
ph.setStatus "error" ph.setStatus "error"
ph.exit ph.exit
fi fi
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
# 2021-10-01 v0.2 <axel.hahn@iml.unibe.ch> fetch full status as json # 2021-10-01 v0.2 <axel.hahn@iml.unibe.ch> fetch full status as json
# 2021-12-23 v0.4 <axel.hahn@iml.unibe.ch> remove switch to warning level if just one slow request was detected # 2021-12-23 v0.4 <axel.hahn@iml.unibe.ch> remove switch to warning level if just one slow request was detected
# 2022-02-11 v0.5 <axel.hahn@iml.unibe.ch> show running workers in 1st line # 2022-02-11 v0.5 <axel.hahn@iml.unibe.ch> show running workers in 1st line
# 2022-04-01 v0.6 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
tmpfile=/tmp/check_fpm_processes_1 tmpfile=/tmp/check_fpm_processes_1
defaulturl=localhost/status defaulturl=localhost/status
...@@ -63,6 +64,7 @@ function _getvalue(){ ...@@ -63,6 +64,7 @@ function _getvalue(){
function showHelp(){ function showHelp(){
local _self=$(basename $0)
cat <<EOF cat <<EOF
______________________________________________________________________ ______________________________________________________________________
...@@ -90,7 +92,7 @@ For performance data it echos: ...@@ -90,7 +92,7 @@ For performance data it echos:
php-fpm-speed requests per $sDeltaunit (since last execution of this check) php-fpm-speed requests per $sDeltaunit (since last execution of this check)
SYNTAX: SYNTAX:
`basename $0` [-u URL] $_self [-u URL]
OPTIONS: OPTIONS:
...@@ -102,7 +104,7 @@ PARAMETERS: ...@@ -102,7 +104,7 @@ PARAMETERS:
None. None.
EXAMPLE: EXAMPLE:
`basename $0` -u http://localhost/my-custom-fpm-statuspage.php $_self -u http://localhost/my-custom-fpm-statuspage.php
EOF EOF
} }
...@@ -130,15 +132,15 @@ ph.require jq wget ...@@ -130,15 +132,15 @@ ph.require jq wget
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# set default / override from command line params # set default / override from command line params
typeset -i iWarnLimit=` ph.getValueWithParam 75 w "$@"` typeset -i iWarnLimit=$( ph.getValueWithParam 75 w "$@")
typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@")
url=$( ph.getValueWithParam $defaulturl u "$@" ) url=$( ph.getValueWithParam $defaulturl u "$@" )
# --- get /server-status page # --- get /server-status page
wget --no-check-certificate -O $tmpfile "$url?full&json" 2>/dev/null wget $paramsWget -O $tmpfile "$url?full&json" 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f $tmpfile rm -f $tmpfile
ph.abort "UNKNOWN: request to url $url failed. `wget --no-check-certificate -O - -S $url`" ph.abort "UNKNOWN: request to url $url failed. $(wget $paramsWget -O - -S $url)"
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment