From 72e252029b616d679547d55d11a119a93f806a55 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Mon, 24 Apr 2023 15:44:41 +0200
Subject: [PATCH] update ceph_status

---
 check_ceph_status | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/check_ceph_status b/check_ceph_status
index 8ea08c2..d9c59ed 100755
--- a/check_ceph_status
+++ b/check_ceph_status
@@ -18,9 +18,10 @@
 # 2020-03-05  v1.1  <axel.hahn@iml.unibe.ch>  switch to ph.* helper functions
 # 2021-03-31  v1.2  <axel.hahn@iml.unibe.ch>  estimate remaining time of ceph recovery
 # 2021-04-12  v1.3  <axel.hahn@iml.unibe.ch>  if degraded items are 0 delete init file too
+# 2023-04-24  v1.4  <axel.hahn@unibe.ch>      update for newer ceph versions
 # ======================================================================
 
-. `dirname $0`/inc_pluginfunctions
+. $(dirname $0)/inc_pluginfunctions
 
 initfile=/tmp/ceph-status-not-ok-start
 tmpfile=/tmp/ceph-status.out_$$
@@ -46,16 +47,16 @@ function readCephStatus(){
         fi
 }
 function getCephStatus(){
-        cat $tmpfile | grep "health" | awk '{ print $2 }' 
+        cat $tmpfile | grep "health:" | awk '{ print $2 }' 
 }
 function getTotalObjects(){
-        cat $tmpfile | grep "recovery.*objects degraded" | awk '{ print $2 }' | cut -f 2 -d "/"
+        cat $tmpfile | grep "pgs:.*objects degraded" | awk '{ print $2 }' | cut -f 2 -d "/"
 }
 function getDegraded(){
-        cat $tmpfile | grep "recovery.*objects degraded" | awk '{ print $2 }' | cut -f 1 -d "/"
+        cat $tmpfile | grep "pgs:.*objects degraded" | awk '{ print $2 }' | cut -f 1 -d "/"
 }
 function getMisplaced(){
-        cat $tmpfile | grep "recovery.*objects misplaced" | awk '{ print $2 }' | cut -f 1 -d "/"
+        cat $tmpfile | grep ".*objects misplaced" | awk '{ print $2 }' | cut -f 1 -d "/"
 }
 
 
@@ -67,10 +68,10 @@ function getMisplaced(){
 readCephStatus
 if [ ! -f $initfile ]; then
         echo "
-                sStart=\"`date`\"
-                iTsStart=`date +%s`
-                typeset -i iDeg=`getDegraded`
-                typeset -i iMis=`getMisplaced`
+                sStart=\"$(date)\"
+                iTsStart=$(date +%s)
+                typeset -i iDeg=$(getDegraded)
+                typeset -i iMis=$(getMisplaced)
 
         ">$initfile
 fi
@@ -78,7 +79,8 @@ fi
 
 iLastDeg=$iDeg
 iLastMis=$iMis
-sCephStatus=`getCephStatus`
+
+sCephStatus=$(getCephStatus)
 
 if [ "$sCephStatus" = "HEALTH_OK" ]; then
         ph.setStatus "ok"
@@ -99,8 +101,8 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
 
         iTsNow=`date +%s`
 
-        typeset -i iDegNow=`getDegraded`
-        typeset -i iMisNow=`getMisplaced`
+        typeset -i iDegNow=$(getDegraded)
+        typeset -i iMisNow=$(getMisplaced)
 
         typeset -i iTsDelta=$iTsNow-$iTsStart
         typeset -i iTsDeltaMin=$iTsDelta/60
@@ -116,7 +118,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
                 typeset -i iDegPerMin=$iDoneDeg/$iTsDelta*60
                 if [ $iDegPerMin -gt 0 ]; then
                         # timeByDeg=`echo $iTsDelta*$iObjCount/$iDoneDeg/60 - $iTsDelta/60 | bc`
-                        timeByDeg=`echo $iDegNow/$iDegPerMin | bc`
+                        timeByDeg=$(echo $iDegNow/$iDegPerMin | bc)
 
                 else
                         timeByDeg="???"
@@ -125,14 +127,14 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
                 typeset -i iMisPerMin=$iDoneMis/$iTsDelta*60
                 if [ $iMisPerMin -gt 0 ]; then
                         # timeByMis=`echo $iTsDelta*$iObjCount/$iDoneMis/60 - $iTsDelta/60 | bc`
-                        timeByMis=`echo $iMisNow/$iMisPerMin | bc`
+                        timeByMis=$(echo $iMisNow/$iMisPerMin | bc)
                 else
                         timeByMis="???"
                 fi
                 if [ $iDegPerMin -gt 0 -o $iMisPerMin -gt 0 ]; then
-                        sTimeLeft=`echo "($iDegNow+$iMisNow)/($iDegPerMin+$iMisPerMin)" | bc`
+                        sTimeLeft=$(echo "($iDegNow+$iMisNow)/($iDegPerMin+$iMisPerMin)" | bc)
                         if [ $sTimeLeft -gt 120 ]; then
-                                sTimeLeft="$sTimeLeft min ... about `echo $sTimeLeft/60 | bc` h"
+                                sTimeLeft="$sTimeLeft min ... about $(echo $sTimeLeft/60 | bc) h"
                         else
                                 sTimeLeft="$sTimeLeft min"
                         fi
@@ -142,7 +144,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
         fi
         typeset -i iDoneTotal=$iDoneDeg+$iDoneMis
         typeset -i iNowTotal=$iDegNow+$iMisNow
-        typeset -i iProgress=`echo "$iDoneTotal*100/$iObjCount" | bc`
+        typeset -i iProgress=$(echo "$iDoneTotal*100/$iObjCount" | bc)
         if [ "$eater" = "o" ]; then
                 eater="C"
         else
@@ -155,8 +157,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
         # ----- output
 
         test $doSingleLoop = 1 || clear
-        # echo "Rebuild detected on $sStart ... running for $iTsDelta s [= $iTsDeltaMin min]"
-        echo "Rebuild detected on $sStart ... running for $iTsDeltaMin min"
+        echo "Problem detected on $sStart ... running for $iTsDeltaMin min"
 
         # --- progress bar
         echo -n "["
@@ -188,7 +189,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
         else
                 sleep $iSleep
                 readCephStatus
-                sCephStatus=`getCephStatus`
+                sCephStatus=$(getCephStatus)
         fi
 
 done
-- 
GitLab