2020-06-04 09:50:35 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# This script is meant to be executed as a cron by executing Nagios
|
|
|
|
# NRPE plugin check_hpraid and notify by mail any errors
|
|
|
|
|
|
|
|
TMPDIR=/tmp
|
|
|
|
md5sum=$(command -v md5sum)
|
|
|
|
awk=$(command -v awk)
|
|
|
|
check_hpraid="/usr/local/lib/nagios/plugins/check_hpraid -v"
|
|
|
|
check_hpraid_output=$(mktemp -p $TMPDIR check_hpraid_XXX)
|
|
|
|
check_hpraid_last="$TMPDIR/check_hpraid_last"
|
|
|
|
trap trapFunc EXIT ERR
|
|
|
|
|
|
|
|
testDeps() {
|
|
|
|
|
|
|
|
test -x "$md5sum" || (echo "md5sum binary not found"; exit 1)
|
|
|
|
test -x "$awk" || (echo "awk binary not found"; exit 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
|
|
|
if ! $check_hpraid > "$check_hpraid_output"; then
|
|
|
|
error=true
|
|
|
|
else
|
|
|
|
error=false
|
|
|
|
fi
|
|
|
|
if [ ! -f $check_hpraid_last ]; then
|
|
|
|
cp "$check_hpraid_output" $check_hpraid_last
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If output and last check is different, display differences and
|
|
|
|
# exit
|
|
|
|
md5_now=$(md5sum "$check_hpraid_output" | awk '{print $1}')
|
|
|
|
md5_last=$(md5sum $check_hpraid_last | awk '{print $1}')
|
|
|
|
if [[ "$md5_now" != "$md5_last" ]]; then
|
|
|
|
cat << EOT
|
|
|
|
Different RAID state detected.
|
|
|
|
Was:
|
2020-06-04 10:23:14 +02:00
|
|
|
$(cat $check_hpraid_last)
|
2020-06-04 09:50:35 +02:00
|
|
|
Is now:
|
2020-06-04 10:23:14 +02:00
|
|
|
$(cat $check_hpraid_output)
|
2020-06-04 09:50:35 +02:00
|
|
|
EOT
|
2020-06-04 10:23:14 +02:00
|
|
|
cp "$check_hpraid_output" $check_hpraid_last
|
|
|
|
exit 1
|
2020-06-04 09:50:35 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If check_hpraid returned error, display output, save status and
|
|
|
|
# exit
|
|
|
|
if $error; then
|
|
|
|
cp "$check_hpraid_output" $check_hpraid_last
|
|
|
|
cat "$check_hpraid_output"
|
|
|
|
exit 1
|
|
|
|
else
|
2020-06-04 10:32:49 +02:00
|
|
|
cp "$check_hpraid_output" $check_hpraid_last
|
2020-06-04 09:50:35 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trapFunc() {
|
|
|
|
|
|
|
|
rm "$check_hpraid_output"
|
|
|
|
}
|
|
|
|
|
|
|
|
testDeps
|
|
|
|
main
|