#!/bin/bash # call this script with 6 parameters # $1 = DC IP-address # $2 = username # $3 = password # $4 = storage-name # $5 = warning value in percent # $6 = critical value in percent # # for example # ./check_esx_storage.sh 192.168.100.250 checker checkerpassword datastore1 80 95 # ########################### # # prerequisites for this script # * add a user on the ESX/ESXi server with read-only access so he cannot break anything # * download check_esx3.pl script - at least version from Fri, 17 Sep 2010 09:14:32 +0000 # Info: http://www.monitoringexchange.org/inventory/Check-Plugins/Virtualization/VMware-%2528ESX%2529/check_esx3 # Download: http://git.op5.org/git/?p=nagios/op5plugins.git;a=blob;f=check_esx3.pl# # +++ For correct usage you have to install some perl-mods - for more info; see check_esx3.pl-file ########################### # used later for the Nagios status exits . /usr/local/nagios/libexec/utils.sh # most echos are for debugging # multiplied by 100 for calculation purpose. In a bash script you cannot calculate floats so easily WARNING=$(($5 * 100)) CRITICAL=$(($6 * 100)) # get free MB. This is normally a float figure! Here the . is removed so that the number can be used for calcualting stuff. FREEMB=$(/usr/local/nagios/libexec/check_esx.pl -D $1 -u $2 -p $3 -l vmfs -s $4 | awk '{print $4 }' | awk -F '=' '{print $2}' | sed 's/[.]//') #echo "FREE: $FREEMB" # get free MB in "percent". This is normally a float figure! Here the . is removed so that the number can be used for calculation FREEPERCENT=$(/usr/local/nagios/libexec/check_esx.pl -D $1 -u $2 -p $3 -l vmfs -s $4 | awk '{print $6}' | sed 's/[(]//' | sed 's/[)]//' | sed 's/[.]//' | sed 's/[%]//' | sed 's/[)]//') #echo "FREE %: $FREEPERCENT" # calculate how much MB are used in "percent". Remember stuff above! USEDPERCENT=$((10000 - $FREEPERCENT)) #echo "USED: $USEDPERCENT" # "1%" in MB ONEPERCENT=$(($FREEMB / $FREEPERCENT)) #echo "ONE PERCENT: $ONEPERCENT" # calculate the amount of "MB" that are used. USEDMB=$(($ONEPERCENT * $USEDPERCENT)) #echo "USED: $USEDMB" # calculate the total MB of the datastore TOTALMB=$(($USEDMB + $FREEMB)) #echo "TOTAL: $TOTALMB" # calculate the real used MB USEDMB_FLOAT=`echo "scale=2 ; $USEDMB / 100" | bc` # calculate the real free MB FREEMB_FLOAT=`echo "scale=2 ; $FREEMB / 100" | bc` # calculate the real used amount in percent USEDPERCENT_FLOAT=`echo "scale=2 ; $USEDPERCENT / 100" | bc` # calculate the real free amount in percent FREEPERCENT_FLOAT=`echo "scale=2 ; $FREEPERCENT / 100" | bc` # calculate the real total amount in MB TOTALMB_FLOAT=`echo "scale=2 ; $TOTALMB / 100" | bc` # Nagios output with perfdata for nice graphs echo "$4: $USEDPERCENT_FLOAT% used ($USEDMB_FLOAT/$TOTALMB_FLOAT) | $4=$USEDPERCENT_FLOAT%;$5;$6;0;100" # Nagios status exits if [ $USEDPERCENT -lt $WARNING ] && [ $USEDPERCENT -lt $CRITICAL ]; then # echo OK exit $STATE_OK elif [ $USEDPERCENT -ge $WARNING ] && [ $USEDPERCENT -lt $CRITICAL ]; then # echo WARN exit $STATE_WARNING elif [ $USEDPERCENT -ge $WARNING ] && [ $USEDPERCENT -ge $CRITICAL ]; then # echo CRIT exit $STATE_CRITICAL fi
Kommentare