diff --git a/check_ceph_diskfree b/check_ceph_diskfree index af4da0dfedd49b83f6473e31d614032bbe62459c..d285efe5f5cb88a199fcf885fdda91f98afc4c4b 100755 --- a/check_ceph_diskfree +++ b/check_ceph_diskfree @@ -17,9 +17,10 @@ # ---------------------------------------------------------------------- # 2020-03-04 v1.0 <axel.hahn@iml.unibe.ch> # 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions +# 2023-04-24 v1.2 <axel.hahn@unibe.ch> update for newer ceph versions # ====================================================================== -. `dirname $0`/inc_pluginfunctions +. $(dirname $0)/inc_pluginfunctions tmpfile=/tmp/ceph_df_output__$$ outfile=/tmp/check_ceph_df_out__$$ @@ -32,34 +33,33 @@ typeset -i iCritical=0 # ---------------------------------------------------------------------- # set default / override from command line params -typeset -i iWarnLimit=` ph.getValueWithParam 70 w "$@"` -typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` +typeset -i iWarnLimit=$( ph.getValueWithParam 70 w "$@") +typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@") -sudo /bin/ceph df > $tmpfile 2>&1 -if [ $? -ne 0 ]; then +if ! sudo /bin/ceph df > $tmpfile 2>&1 +then rm -f $tmpfile - ph.abort "UNKNOWN: ceph is not available or no sudo permissions to execute ceph commands." +ph.abort "UNKNOWN: ceph is not available or no sudo permissions to execute ceph commands." fi rm -f $outfile 2>/dev/null isHeader=0 area= -while read line +grep "[a-zA-Z]" $tmpfile | while read line do - # echo "DEBUG: $line" - newArea=`echo $line | grep "^[A-Z]*:"` + newArea=$(echo $line | grep "^\-\-\- [A-Z]*" | sed "s#--- ##" | sed "s# ---##" ) lineStatus=" " if [ ! -z "$newArea" ]; then echo>>$outfile - area=`echo $newArea | cut -f 1 -d ":"` + area=$(echo $newArea | cut -f 1 -d ":") isHeader=1 # Position of disk usage in the sections iPos=0 - test "$area" = "GLOBAL" && iPos=4 - test "$area" = "POOLS" && iPos=4 + test "$area" = "RAW STORAGE" && iPos=10 + test "$area" = "POOLS" && iPos=9 if [ $iPos -eq 0 ]; then ph.abort "ERROR: unhandled section: [$area]" fi @@ -68,7 +68,8 @@ do if [ $isHeader -eq 1 ]; then isHeader=0 else - typeset -i percentUsed=`echo $line | awk -v ipos=$iPos '{ print $ipos }' | sed "s#\..*##"` + typeset -i percentUsed + percentUsed=$(echo $line | awk -v ipos=$iPos '{ print $ipos }' | sed "s#\..*##") if [ $percentUsed -ge $iWarnLimit ]; then if [ $percentUsed -ge $iCriticalLimit ]; then iCritical=$iCritical+1 @@ -83,7 +84,7 @@ do fi fi echo "$lineStatus $line" >> $outfile -done < $tmpfile +done if [ $iCritical -gt 0 ]; then @@ -94,23 +95,27 @@ else ph.setStatus "ok" fi -ph.status "Disksize on Ceph cluster and its pools - critcal: $iCritical ($iCriticalLimit %) .. warnings: $iWarning ($iWarnLimit %)" +ph.status "Disksize on Ceph cluster and its pools - warnings: $iWarning ($iWarnLimit %) .. critcal: $iCritical ($iCriticalLimit %)" cat $outfile -# 3rd line is global size status -sTotal=`sed -n 3p $tmpfile | awk '{ print $1 }'` -sAvail=`sed -n 3p $tmpfile | awk '{ print $2 }'` -sUsed=` sed -n 3p $tmpfile | awk '{ print $3 }'` +# global size status is in TOTAL... +totalLine="$( grep '^TOTAL' $tmpfile | sed 's#iB##g' )" -iTotal=`ph.toUnit $sTotal ""` -iAvail=`ph.toUnit $sAvail ""` -iUsed=` ph.toUnit $sUsed ""` +# echo "DEBUG: totalLine = $totalLine" +# DEBUG: totalLine = TOTAL 18 T 18 T 428 G 428 G 2.30 + +sTotal=$( echo $totalLine | awk '{ print $2 $3 }' ) +sAvail=$( echo $totalLine | awk '{ print $4 $5 }' ) +sUsed=$( echo $totalLine | awk '{ print $6 $7 }' ) + +iTotal=$(ph.toUnit $sTotal "") +iAvail=$(ph.toUnit $sAvail "") +iUsed=$( ph.toUnit $sUsed "") ph.perfadd "global-total" "${iTotal}" "" "" 0 ${iTotal} ph.perfadd "global-avail" "${iAvail}" "" "" 0 ${iTotal} ph.perfadd "global-used" "${iUsed}" "" "" 0 ${iTotal} - # cleanup rm -f $tmpfile $outfile 2>/dev/null diff --git a/inc_pluginfunctions b/inc_pluginfunctions index 0e239a3173ac339e6374eaf99858bad1cca37f76..abc6128d98f48d35268dda295eec8607ad389f0a 100644 --- a/inc_pluginfunctions +++ b/inc_pluginfunctions @@ -33,6 +33,7 @@ # 2022-10-25 v1.5 <axel.hahn@iml.unibe.ch> handle empty value in ph.perfadd # 2023-01-30 v1.6 <axel.hahn@unibe.ch> check performance params 5+6 and show a warning if missing # 2023-02-16 v1.7 <axel.hahn@unibe.ch> adding a generic min and max value did not really help +# 2024-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion # ====================================================================== @@ -268,7 +269,8 @@ function ph._getExp(){ test "$_unit" = "K" && echo 2^10 test "$_unit" = "M" && echo 2^20 test "$_unit" = "G" && echo 2^30 - test "$_unit" = "P" && echo 2^40 + test "$_unit" = "T" && echo 2^40 + test "$_unit" = "P" && echo 2^50 # phyiscal # test "$_unit" = "m" && echo 10^-3 @@ -296,7 +298,7 @@ function ph.toUnit(){ local _divisor=`ph._getExp $_unit` # echo "DEBUG ... $_divisor .. $_multiply" - echo "`echo $_value | tr -d "[:alpha:]" `*${_multiply}/$_divisor" | bc + echo "$(echo $_value | tr -d "[:alpha:]" )*${_multiply}/$_divisor" | bc } @@ -318,6 +320,7 @@ function ph.getFileAge(){ # get file for storage of last value # global string dir_data custom path; default is /tmp/icinga_counter/ +# param string varName variable name of a value to store function ph._getStorefile(){ local varName=$1 @@ -332,6 +335,8 @@ function ph._getStorefile(){ } # save a value - needed for gdAddDeltaData +# param string varName variable name of a value to store +# param * value value as float/ integer function ph._savecounter() { local varName=$1 local value=$2 @@ -341,6 +346,9 @@ function ph._savecounter() { echo ${value} > "${sStoreFile}" } +# get age of last storage of a value +# used in perfdeltaspeed +# param string varName variable name of a value to store function ph._getageoflastvalue() { local varName=$1 local sStoreFile=$(ph._getStorefile "${varName}") @@ -349,6 +357,9 @@ function ph._getageoflastvalue() { # local inow=`date +%s` # echo $(( ${inow}-${ilast}+1 )) } +# get the last value +# used in perfdeltaspeed +# param string varName variable name of a value to store function ph._readlastvalue(){ local varName=$1 local sStoreFile=$(ph._getStorefile "${varName}")