evolinux-base: check_hpraid.cron.sh: Better logic and use mail
First step is to detect errors Second step is to detect different state Added mail comand to replace cron output
This commit is contained in:
parent
14d8eaac2f
commit
fe1756d22a
|
@ -10,6 +10,18 @@ awk=$(command -v awk)
|
||||||
check_hpraid="/usr/local/lib/nagios/plugins/check_hpraid -v -p"
|
check_hpraid="/usr/local/lib/nagios/plugins/check_hpraid -v -p"
|
||||||
check_hpraid_output=$(mktemp -p $TMPDIR check_hpraid_XXX)
|
check_hpraid_output=$(mktemp -p $TMPDIR check_hpraid_XXX)
|
||||||
check_hpraid_last="$TMPDIR/check_hpraid_last"
|
check_hpraid_last="$TMPDIR/check_hpraid_last"
|
||||||
|
# set to false to use cron output (MAILTO)
|
||||||
|
# otherwise send output with mail command
|
||||||
|
use_mail=true
|
||||||
|
body=$(mktemp --tmpdir=/tmp check_hpraid_XXX)
|
||||||
|
clientmail=$(grep EVOMAINTMAIL /etc/evomaintenance.cf | cut -d'=' -f2)
|
||||||
|
hostname=$(grep HOSTNAME /etc/evomaintenance.cf | cut -d'=' -f2)
|
||||||
|
hostname=${hostname%%.evolix.net}
|
||||||
|
# If hostname is composed with -, remove the first part.
|
||||||
|
if [[ $hostname =~ "-" ]]; then
|
||||||
|
hostname=$(echo "$hostname" | cut -d'-' -f2-)
|
||||||
|
fi
|
||||||
|
|
||||||
trap trapFunc EXIT ERR
|
trap trapFunc EXIT ERR
|
||||||
|
|
||||||
testDeps() {
|
testDeps() {
|
||||||
|
@ -25,6 +37,23 @@ main() {
|
||||||
else
|
else
|
||||||
error=false
|
error=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If check_hpraid returned error, display output, save status and
|
||||||
|
# exit
|
||||||
|
if $error; then
|
||||||
|
cp "$check_hpraid_output" "$check_hpraid_last"
|
||||||
|
if $use_mail; then
|
||||||
|
mail -s "RAID error on $hostname" "$clientmail" \
|
||||||
|
<<< "$check_hpraid_output"
|
||||||
|
else
|
||||||
|
cat "$check_hpraid_output"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
cp "$check_hpraid_output" $check_hpraid_last
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f $check_hpraid_last ]; then
|
if [ ! -f $check_hpraid_last ]; then
|
||||||
cp "$check_hpraid_output" $check_hpraid_last
|
cp "$check_hpraid_output" $check_hpraid_last
|
||||||
fi
|
fi
|
||||||
|
@ -34,32 +63,31 @@ main() {
|
||||||
md5_now=$(md5sum "$check_hpraid_output" | awk '{print $1}')
|
md5_now=$(md5sum "$check_hpraid_output" | awk '{print $1}')
|
||||||
md5_last=$(md5sum $check_hpraid_last | awk '{print $1}')
|
md5_last=$(md5sum $check_hpraid_last | awk '{print $1}')
|
||||||
if [[ "$md5_now" != "$md5_last" ]]; then
|
if [[ "$md5_now" != "$md5_last" ]]; then
|
||||||
cat << EOT
|
cat << EOT > "$body"
|
||||||
Different RAID state detected.
|
Different RAID state detected.
|
||||||
Was:
|
|
||||||
$(cat $check_hpraid_last)
|
|
||||||
Is now:
|
|
||||||
$(cat $check_hpraid_output)
|
|
||||||
EOT
|
|
||||||
cp "$check_hpraid_output" $check_hpraid_last
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If check_hpraid returned error, display output, save status and
|
Was:
|
||||||
# exit
|
$(sed 's/^/> /g' "$check_hpraid_last")
|
||||||
if $error; then
|
|
||||||
cp "$check_hpraid_output" $check_hpraid_last
|
###########################
|
||||||
cat "$check_hpraid_output"
|
|
||||||
exit 1
|
Is now:
|
||||||
|
$(sed 's/^/> /g' "$check_hpraid_output")
|
||||||
|
EOT
|
||||||
|
if $use_mail; then
|
||||||
|
mail -s "RAID status is different on $hostname" \
|
||||||
|
"$clientmail" <<< "$body"
|
||||||
else
|
else
|
||||||
cp "$check_hpraid_output" $check_hpraid_last
|
cat "$body"
|
||||||
exit 0
|
fi
|
||||||
|
cp "$check_hpraid_output" "$check_hpraid_last"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
trapFunc() {
|
trapFunc() {
|
||||||
|
|
||||||
rm "$check_hpraid_output"
|
rm "$check_hpraid_output" "$body"
|
||||||
}
|
}
|
||||||
|
|
||||||
testDeps
|
testDeps
|
||||||
|
|
Loading…
Reference in a new issue