Skip to content

Commit fd7dffb

Browse files
committed
Merge branch 'atward', customink#5
2 parents 8f8276b + 24a8464 commit fd7dffb

File tree

2 files changed

+59
-45
lines changed

2 files changed

+59
-45
lines changed

check_glusterfs

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
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
@@ -24,7 +15,7 @@
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.
@@ -36,7 +27,7 @@
3627
PATH=/sbin:/bin:/usr/sbin:/usr/bin
3728

3829
PROGNAME=$(basename -- $0)
39-
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
30+
PROGPATH=$(sed -e 's,[\\/][^\\/][^\\/]*$,,' <<<$0)
4031
REVISION="1.0.3"
4132

4233
if [ -f $PROGPATH/utils.sh ]
@@ -47,18 +38,21 @@ else
4738
exit 1
4839
fi
4940

41+
5042
# parse command line
5143
usage () {
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
6862
done
6963

70-
if [ -z "${VOLUME}" -o -z "${BRICKS}" ]; then
64+
if [[ -z $VOLUME ]] || [[ -z $BRICKS ]]; then
7165
usage
7266
fi
7367

@@ -97,12 +91,12 @@ fi
9791
# get volume heal status
9892
heal=0
9993
for 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
10397
done
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"
107101
fi
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
152146
done < <(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"
159153
fi
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
171166
fi
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}"

ssh_wrapper

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Lock down ssh authorized_keys command
3+
# command="/usr/bin/ssh_wrapper",no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding ssh-rsa ...
4+
5+
CHECK_GLUSTER=/usr/bin/check_glusterfs
6+
GLUSTER_REGEX='^check_glusterfs -v [-_[:alnum:]]+ -n [0-9]+( -w [0-9.]+ -c [0-9.]+)?$'
7+
8+
case "$SSH_ORIGINAL_COMMAND" in
9+
check_glusterfs*)
10+
# assert command looks good, assumes GNU grep
11+
if grep -E "$GLUSTER_REGEX" <<<$SSH_ORIGINAL_COMMAND; then
12+
exec $CHECK_GLUSTER ${SSH_ORIGINAL_COMMAND#* }
13+
fi
14+
;;
15+
esac
16+
17+
echo "Sorry. Only these commands are available to you:"
18+
echo "check_glusterfs -v VOLUME -n BRICKS [-w GB -c GB]"
19+
exit 1

0 commit comments

Comments
 (0)