44# # http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/GlusterFS-checks/details
55
66# ## CHANGELOG
7- # # 1.0.2
8- # * 07/01/2014
9- # * Modified by Doug Wilson <[email protected] >10- # * includes carrillm’s fix to support TB sized volumes
11- # * outputs all errors on a critical alarm, not just free space
12- #
13- # * 20/08/2014
14- # * Modified by emitor
15- # * fix the regular expresion where get the free space (it didn't work for me on centOS)
16- # * fix OK status to print the free space as it is
7+ # See Git history
178
18- # This Nagios script was written against version 3.3 & 3.4 of Gluster. Older
9+ # This Nagios script was written against version 3.5 of Gluster. Older
1910# versions will most likely not work at all with this monitoring script.
2011#
2112# Gluster currently requires elevated permissions to do anything. In order to
2415# following in /etc/sudoers (or something equivalent):
2516#
2617# Defaults:nagios !requiretty
27- # nagios ALL=(root) NOPASSWD:/usr/sbin/gluster volume status [[\:graph \:]]* detail,/usr/sbin/gluster volume heal [[\:graph \:]]* info
18+ # nagios ALL=(root) NOPASSWD:/usr/sbin/gluster volume status [-_ [\:alnum \:]]+ detail,/usr/sbin/gluster volume heal [-_ [\:alnum \:]]+ info
2819#
2920# That should give us all the access we need to check the status of any
3021# currently defined peers and volumes.
3627PATH=/sbin:/bin:/usr/sbin:/usr/bin
3728
3829PROGNAME=$( basename -- $0 )
39- PROGPATH=` echo $0 | sed -e ' s,[\\/][^\\/][^\\/]*$,,' `
30+ PROGPATH=$( sed -e ' s,[\\/][^\\/][^\\/]*$,,' <<< $0 )
4031REVISION=" 1.0.3"
4132
4233if [ -f $PROGPATH /utils.sh ]
4738 exit 1
4839fi
4940
41+
5042# parse command line
5143usage () {
52- echo " "
53- echo " USAGE: "
54- echo " $PROGNAME -v VOLUME -n BRICKS [-w GB -c GB]"
55- echo " -n BRICKS: number of bricks"
56- echo " -w and -c values in GB"
44+ cat << -USAGE
45+ USAGE:
46+ $PROGNAME -v VOLUME -n BRICKS [-w GB -c GB]
47+ -n BRICKS: number of bricks
48+ -w and -c values in GB
49+ USAGE
5750 exit $STATE_UNKNOWN
5851}
5952
60- while getopts " v :n:w:c:" opt; do
53+ while getopts " hv :n:w:c:" opt; do
6154 case $opt in
55+ h) usage ;;
6256 v) VOLUME=${OPTARG} ;;
6357 n) BRICKS=${OPTARG} ;;
6458 w) WARN=${OPTARG} ;;
@@ -67,7 +61,7 @@ while getopts "v:n:w:c:" opt; do
6761 esac
6862done
6963
70- if [ -z " ${ VOLUME} " -o -z " ${ BRICKS} " ]; then
64+ if [[ -z $ VOLUME ]] || [[ -z $ BRICKS ] ]; then
7165 usage
7266fi
7367
9791# get volume heal status
9892heal=0
9993for entries in $( sudo gluster volume heal ${VOLUME} info | awk ' /^Number of entries: /{print $4}' ) ; do
100- if [ " $entries " -gt 0 ]; then
101- let $(( heal+= entries))
94+ if [[ $entries -gt 0 ] ]; then
95+ let heal+=entries
10296 fi
10397done
104- if [ " $heal " -gt 0 ]; then
105- errors=( " ${errors[@]} " " $ heal unsynched entries" )
98+ if [[ " $heal " -gt 0 ] ]; then
99+ errors+=( $ heal unsynched entries)
106100 ex_stat=" WARNING_stat"
107101fi
108102
@@ -118,30 +112,30 @@ while read -r line; do
118112 ;;
119113 Disk)
120114 key=${field[@]: 0: 3}
121- if [ " ${ key} " = " Disk Space Free" ]; then
115+ if [[ $ key == " Disk Space Free" ] ]; then
122116 freeunit=${field[@]: 4}
123- free=${freeunit: 0: ${# freeunit} -2}
117+ free=${freeunit: 0: $(( $ {# freeunit} -2)) }
124118 freeconvgb=` echo " ($free *1024)" | bc`
125119 unit=${freeunit# $free }
126- if [ " $unit " = " TB" ]; then
127- free=$freeconvgb
120+ if [[ $unit == " TB" ] ]; then
121+ free=$(( $ freeconvgb * 1024 ))
128122 unit=" GB"
129123 fi
130- if [ " $unit " != " GB" ]; then
124+ if [[ $unit != " GB" ] ]; then
131125 Exit UNKNOWN " unknown disk space size $freeunit "
132126 fi
133- free=$( echo " ${ free} / 1" | bc -q )
134- if [ $free -lt $freegb ]; then
127+ free=$( bc -q <<< " $ free / 1" )
128+ if [[ $free -lt $freegb ] ]; then
135129 freegb=$free
136130 fi
137131 fi
138132 ;;
139133 Online)
140134 online=${field[@]: 2}
141- if [ " ${online} " = " Y" ]; then
142- let $(( bricksfound++ ))
135+ if [[ ${online} = " Y" ] ]; then
136+ let bricksfound++
143137 else
144- errors=( " ${errors[@]} " " $ brick offline" )
138+ errors+=( $ brick offline)
145139 fi
146140 ;;
147141 Volume)
@@ -151,31 +145,32 @@ while read -r line; do
151145 esac
152146done < <( sudo gluster volume status ${VOLUME} detail 2>&1 )
153147
154- if [ $bricksfound -eq 0 ]; then
148+ if [[ $bricksfound -eq 0 ] ]; then
155149 Exit CRITICAL " no bricks found"
156- elif [ $bricksfound -lt $BRICKS ]; then
157- errors=( " ${errors[@]} " " found $bricksfound bricks, expected $BRICKS " )
150+ elif [[ $bricksfound -lt $BRICKS ] ]; then
151+ errors+=( found $bricksfound bricks, expected $BRICKS )
158152 ex_stat=" WARNING_stat"
159153fi
160154
161- if [ -n " $CRIT " -a -n " $WARN " ]; then
162- if [ $CRIT -ge $WARN ]; then
155+ if [[ -n $CRIT ]] && [[ -n $WARN ] ]; then
156+ if [[ $CRIT -ge $WARN ] ]; then
163157 Exit UNKNOWN " critical threshold below warning"
164- elif [ $freegb -lt $CRIT ]; then
165- errors=( " ${errors[@]} " " free space ${freegb} GB" )
158+ elif [[ $freegb -lt $CRIT ] ]; then
159+ errors+=( free space ${freegb} GB)
166160 ex_stat=" CRITICAL_stat"
167- elif [ $freegb -lt $WARN ]; then
168- errors=(" ${errors[@]} " " free space ${freegb} GB" )
161+
162+ elif [[ $freegb -lt $WARN ]]; then
163+ errors+=(free space ${freegb} GB)
169164 ex_stat=" WARNING_stat"
170165 fi
171166fi
172167
173168# exit with warning if errors
174- if [ -n " $errors " ]; then
169+ if [[ -n $errors ] ]; then
175170 sep=' ; '
176171 msg=$( printf " ${sep} %s" " ${errors[@]} " )
177172 msg=${msg: ${# sep} }
178- if [ " ${ex_stat} " == " CRITICAL_stat" ]; then
173+ if [[ ${ex_stat} == " CRITICAL_stat" ] ]; then
179174 Exit CRITICAL " ${msg} "
180175 else
181176 Exit WARNING " ${msg} "
0 commit comments