Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #pastebin-url: http://pastebin.com/t1tcLX6n
- IFS=$'\n'
- DEBUG=0
- #units 1000 or 1024
- UNITS="GB"
- KB=1024
- MB=$[KB*KB]
- GB=$[MB*KB]
- bc=$(which bc)
- usage()
- {
- echo "Usage:"
- echo " "`basename $0`" [ -w <warn> ] [ -c <crit> ] [ -l <storage-label> | -u <storage-uuid> ]"
- echo
- }
- crit=10
- warn=20
- storage="Local storage"
- by_uuid=0
- while [ "$1" != "" ]; do
- case $1 in
- -c) shift
- crit=$1
- ;;
- -w) shift
- warn=$1
- ;;
- -l) shift
- storage="$1"
- by_uuid=0
- ;;
- -u) shift
- storage="$1"
- by_uuid=1
- ;;
- -d) DEBUG=1
- ;;
- * ) usage
- exit 1
- esac
- shift
- done
- if [ $by_uuid -gt 0 ]; then
- VG_SIZE=$(xe sr-list uuid=$storage params=physical-size | awk '{print($NF)}' | head -n1)
- VG_USED=$(xe sr-list uuid=$storage params=physical-utilisation | awk '{print($NF)}' | head -n1)
- else
- VG_SIZE=$(xe sr-list name-label=$storage params=physical-size | awk '{print($NF)}' | head -n1)
- VG_USED=$(xe sr-list name-label=$storage params=physical-utilisation | awk '{print($NF)}' | head -n1)
- fi
- #need more accuracy in calculations
- FREE_PERCENT=$(echo "\$v=(($VG_SIZE-$VG_USED)/$VG_SIZE)*100; printf \"%0.2f\",\$v;" | perl)
- if [ $DEBUG -gt 0 ]; then
- echo "VG_SIZE=$VG_SIZE"
- echo "VG_USED=$VG_USED"
- echo "FREE_PERCENT=$FREE_PERCENT"
- fi
- crit_value=$(echo "$crit>$FREE_PERCENT" | $bc)
- warn_value=$(echo "$warn>$FREE_PERCENT" | $bc)
- MSG="OK"
- if [ $warn_value -gt 0 ]; then
- MSG="WARNING"
- fi
- if [ $crit_value -gt 0 ]; then
- MSG="CRITICAL"
- fi
- SIZE_GB=$(echo "scale=2; $VG_SIZE/$GB" | $bc)
- FREE_GB=$(echo "scale=2; ($VG_SIZE-$VG_USED)/$GB" | $bc)
- echo "DISK $MSG - free space: $FREE_GB / $SIZE_GB $UNITS ($FREE_PERCENT% free)"
Advertisement
Add Comment
Please, Sign In to add comment