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

no more tmpfile

parent 36a30c40
Branches
No related tags found
1 merge request!123no more tmpfile
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
# 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions # 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 # 2023-04-24 v1.2 <axel.hahn@unibe.ch> update for newer ceph versions
# 2023-05-09 v1.3 <axel.hahn@unibe.ch> add help # 2023-05-09 v1.3 <axel.hahn@unibe.ch> add help
# 2023-06-19 v1.4 <axel.hahn@unibe.ch> no more tmpfile
# ====================================================================== # ======================================================================
. $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
tmpfile=/tmp/ceph_df_output__$$
outfile=/tmp/check_ceph_df_out__$$ outfile=/tmp/check_ceph_df_out__$$
typeset -i iWarning=0 typeset -i iWarning=0
...@@ -31,7 +31,7 @@ typeset -i iCritical=0 ...@@ -31,7 +31,7 @@ typeset -i iCritical=0
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.3 self_APPVERSION=1.4
function showHelp(){ function showHelp(){
cat <<EOF cat <<EOF
...@@ -76,9 +76,9 @@ typeset -i iWarnLimit=$( ph.getValueWithParam 70 w "$@") ...@@ -76,9 +76,9 @@ typeset -i iWarnLimit=$( ph.getValueWithParam 70 w "$@")
typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@") typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@")
if ! sudo /bin/ceph df > $tmpfile 2>&1 if ! data=$( sudo /bin/ceph df 2>&1 )
then then
rm -f $tmpfile echo "$data"
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 fi
...@@ -86,13 +86,14 @@ rm -f $outfile 2>/dev/null ...@@ -86,13 +86,14 @@ rm -f $outfile 2>/dev/null
isHeader=0 isHeader=0
area= area=
grep "[a-zA-Z]" $tmpfile | while read line out=$(
grep "[a-zA-Z]" <<< "$data" | while read line
do do
newArea=$(echo $line | grep "^\-\-\- [A-Z]*" | sed "s#--- ##" | sed "s# ---##" ) newArea=$(echo $line | grep "^\-\-\- [A-Z]*" | sed "s#--- ##" | sed "s# ---##" )
lineStatus=" " lineStatus=" "
if [ ! -z "$newArea" ]; then if [ -n "$newArea" ]; then
echo>>$outfile echo
area=$(echo $newArea | cut -f 1 -d ":") area=$(echo "$newArea" | cut -f 1 -d ":")
isHeader=1 isHeader=1
# Position of disk usage in the sections # Position of disk usage in the sections
...@@ -111,10 +112,8 @@ do ...@@ -111,10 +112,8 @@ do
percentUsed=$(echo $line | awk -v ipos=$iPos '{ print $ipos }' | sed "s#\..*##") percentUsed=$(echo $line | awk -v ipos=$iPos '{ print $ipos }' | sed "s#\..*##")
if [ $percentUsed -ge $iWarnLimit ]; then if [ $percentUsed -ge $iWarnLimit ]; then
if [ $percentUsed -ge $iCriticalLimit ]; then if [ $percentUsed -ge $iCriticalLimit ]; then
iCritical=$iCritical+1
lineStatus="CRITICAL " lineStatus="CRITICAL "
else else
iWarning=$iWarning+1
lineStatus="WARNING " lineStatus="WARNING "
fi fi
else else
...@@ -122,9 +121,12 @@ do ...@@ -122,9 +121,12 @@ do
fi fi
fi fi
fi fi
echo "$lineStatus $line" >> $outfile echo "$lineStatus $line"
done done
)
iWarning=$( grep -c "^WARNING" <<< "$out" )
iCritical=$( grep -c "^CRITICAL" <<< "$out" )
if [ $iCritical -gt 0 ]; then if [ $iCritical -gt 0 ]; then
ph.setStatus "critical" ph.setStatus "critical"
...@@ -135,10 +137,10 @@ else ...@@ -135,10 +137,10 @@ else
fi fi
ph.status "Disksize on Ceph cluster and its pools - warnings: $iWarning ($iWarnLimit %) .. critcal: $iCritical ($iCriticalLimit %)" ph.status "Disksize on Ceph cluster and its pools - warnings: $iWarning ($iWarnLimit %) .. critcal: $iCritical ($iCriticalLimit %)"
cat $outfile echo "$out"
# global size status is in TOTAL... # global size status is in TOTAL...
totalLine="$( grep '^TOTAL' $tmpfile | sed 's#iB##g' )" totalLine="$( grep '^TOTAL' <<< "$data" | sed 's#iB##g' )"
# echo "DEBUG: totalLine = $totalLine" # echo "DEBUG: totalLine = $totalLine"
# DEBUG: totalLine = TOTAL 18 T 18 T 428 G 428 G 2.30 # DEBUG: totalLine = TOTAL 18 T 18 T 428 G 428 G 2.30
...@@ -155,9 +157,6 @@ ph.perfadd "global-total" "${iTotal}" "" "" 0 ${iTotal} ...@@ -155,9 +157,6 @@ ph.perfadd "global-total" "${iTotal}" "" "" 0 ${iTotal}
ph.perfadd "global-avail" "${iAvail}" "" "" 0 ${iTotal} ph.perfadd "global-avail" "${iAvail}" "" "" 0 ${iTotal}
ph.perfadd "global-used" "${iUsed}" "" "" 0 ${iTotal} ph.perfadd "global-used" "${iUsed}" "" "" 0 ${iTotal}
# cleanup
rm -f $tmpfile $outfile 2>/dev/null
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment