Check_MK/Nagios script to monitor multipath count

428 Views Asked by At

i'm noob in bash.

I want to create check so if 1 path is dead i want to get warning message,more than 1 path down-critical, no dead path-all is OK

i would use this command and it's output:

powermt display dev=all 

CHECK_DEGRADED=/usr/local/bin/sudo /sbin/powermt display | grep dead| wc -l
 if [ $CHECK_DEGRADED -eq 1 ]; then

status=1
statustxt=WARNING

 else if [ $CHECK_DEGRADED -gt 1 ];  then

status=2
statustxt=CRITICAL


else

status=0
statustxt=OK

 fi 

output should be something like: Path is in $statustxt state

1

There are 1 best solutions below

11
On

First of all Welcome to Stack Overflow.

  1. declare an array of path
  2. scan on all of them
  3. check if the path exist
  4. if exist increment a counter
  5. then check the counter for exit status

Something like that should be fine:

deadPath=0
 declare -a pathArray=(/usr/local/bin/sudo /sbin/powermt display)
 for i in "${pathArray[@]}"
 do
   if [ -d "$i" ]; then
      # Will enter here if path exists
      echo "Path $i Exists"
   else
    deadPath=$[$deadPath+1] 
   fi
done
if (( deadPath > 1 )); then
  echo "Critical"
  exit 2
elif (( deadPath == 1 )); then
  echo "Warning"
  exit 1
else 
  echo "OK"
  exit 0
fi