forked from evolix/ansible-roles
nagios-nrpe: Improve readability for check_mount_rw
This commit is contained in:
parent
a733e2794f
commit
c880ce43a2
|
@ -1,30 +1,40 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Verify that given mountpoints have 'read-write' option.
|
||||||
|
|
||||||
output=$(mktemp --tmpdir $(basename $0).XXXXXXXXXX)
|
output=$(mktemp --tmpdir $(basename "$0").XXXXXXXXXX)
|
||||||
critical_count=0
|
critical_count=0
|
||||||
ok_count=0
|
ok_count=0
|
||||||
|
|
||||||
trap "rm -f $output" EXIT
|
trap "rm -f $output" EXIT
|
||||||
|
|
||||||
for mountpoint in $@; do
|
for mountpoint in $@; do
|
||||||
|
# We verify no mointpoints have 'read-only' option instead of checking
|
||||||
|
# for 'read-write' option, because there could be multiple device
|
||||||
|
# mounted on a sigle path. In that edge case only checking for the
|
||||||
|
# presence of the 'read-write' option would yeild a flase positive.
|
||||||
if findmnt -O ro --noheadings "$mountpoint" 1>/dev/null 2>&1; then
|
if findmnt -O ro --noheadings "$mountpoint" 1>/dev/null 2>&1; then
|
||||||
echo "CRITICAL - $mountpoint" >> "$output"
|
echo "CRITICAL - $mountpoint" >> "$output"
|
||||||
critical_count=$(( critical_count + 1))
|
critical_count=$(( critical_count + 1))
|
||||||
else
|
else
|
||||||
echo "OK - $mountpoint" >> "$output"
|
echo "OK - $mountpoint" >> "$output"
|
||||||
ok_count=$(( ok_count + 1))
|
ok_count=$(( ok_count + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
total_count=$(( ok_count + critical_count ))
|
total_count=$(( ok_count + critical_count ))
|
||||||
|
|
||||||
|
plural=''
|
||||||
|
test "$total_count" -gt 1 && plural='s'
|
||||||
|
|
||||||
if [ $ok_count -eq $total_count ]; then
|
if [ $ok_count -eq $total_count ]; then
|
||||||
printf "OK - %d/%d no read-only mountpoint\n\n" "$ok_count" "$total_count"
|
printf "OK - %d/%d mountpoint%s have 'read-write' option\n\n" \
|
||||||
|
"$ok_count" "$total_count" "$plural"
|
||||||
cat "$output"
|
cat "$output"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
printf "CRITICAL - %d/%d read-only mountpoint\n\n" "$critical_count" "$total_count"
|
printf "CRITICAL - %d/%d mountpoint%s don't have 'read-write' option\n\n" \
|
||||||
|
"$critical_count" "$total_count" "$plural"
|
||||||
cat "$output"
|
cat "$output"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue