144 lines
3.1 KiB
Text
144 lines
3.1 KiB
Text
|
#!/bin/sh
|
||
|
#
|
||
|
# Shows status of areca RAID controllers: arcmsr(4)
|
||
|
#
|
||
|
# Authors: Bjoern A. Zeeb
|
||
|
#
|
||
|
# $FreeBSD$
|
||
|
#
|
||
|
|
||
|
# If there is a global system configuration file, suck it in.
|
||
|
#
|
||
|
if [ -r /etc/defaults/periodic.conf ]
|
||
|
then
|
||
|
. /etc/defaults/periodic.conf
|
||
|
source_periodic_confs
|
||
|
fi
|
||
|
|
||
|
# Defaults.
|
||
|
: ${daily_status_arcmsr_raid_enable:=NO}
|
||
|
# Verbose.
|
||
|
: ${daily_status_arcmsr_raid_verbose:=YES}
|
||
|
# SMART.
|
||
|
: ${daily_status_arcmsr_raid_smart:=YES}
|
||
|
# Logs persist between "areca-cli event info" invocation?
|
||
|
: ${daily_status_arcmsr_raid_persist_logs:=YES}
|
||
|
|
||
|
areca_cli=${areca_cli:-%%PREFIX%%/sbin/areca-cli}
|
||
|
logdir=${logdir:-/var/log}
|
||
|
|
||
|
verbose()
|
||
|
{
|
||
|
local cmd
|
||
|
local scmd
|
||
|
local log
|
||
|
cmd=$1
|
||
|
scmd=$2
|
||
|
log=$3
|
||
|
|
||
|
case ${daily_status_arcmsr_raid_verbose} in
|
||
|
[Nn][Oo])
|
||
|
return
|
||
|
;;
|
||
|
*) ;;
|
||
|
esac
|
||
|
|
||
|
${areca_cli} ${cmd} ${scmd} >> ${log}
|
||
|
}
|
||
|
|
||
|
smart()
|
||
|
{
|
||
|
local log
|
||
|
local disk
|
||
|
log=$1
|
||
|
|
||
|
case ${daily_status_arcmsr_raid_smart} in
|
||
|
[Nn][Oo])
|
||
|
return
|
||
|
;;
|
||
|
*) ;;
|
||
|
esac
|
||
|
|
||
|
for disk in `${areca_cli} disk info | awk '
|
||
|
BEGIN { run=0 }
|
||
|
{ if (/^=======/) {
|
||
|
if (run==0) { run=1; } else { run=0; } }
|
||
|
else { if (run==1) { printf "%d ", $1; } } };'`; do
|
||
|
echo "SMART data for disk ${disk}" >> ${log}
|
||
|
${areca_cli} disk smart drv=${disk} >> ${log}
|
||
|
done
|
||
|
}
|
||
|
|
||
|
case "$daily_status_arcmsr_raid_enable" in
|
||
|
[Yy][Ee][Ss])
|
||
|
echo
|
||
|
echo 'Checking status of Areca RAID controllers:'
|
||
|
|
||
|
rc=0
|
||
|
|
||
|
# Checking the currently selected (1st) controller.
|
||
|
# XXX TODO set curctrl=[1..4]; along with that
|
||
|
# XXX TODO try to only call areca-cli once (per ctrl).
|
||
|
echo ""
|
||
|
echo "Controller ${ctrl}:"
|
||
|
ctrl_log=${logdir}/arcmsr_raid_${ctrl}
|
||
|
if test ! -f ${ctrl_log}.today; then
|
||
|
touch ${ctrl_log}.today
|
||
|
fi
|
||
|
mv -f ${ctrl_log}.today ${ctrl_log}.yesterday
|
||
|
# Not too efficient to call areca_cli lots of times.
|
||
|
verbose sys info ${ctrl_log}.today
|
||
|
${areca_cli} rsf info >> ${ctrl_log}.today
|
||
|
verbose vsf info ${ctrl_log}.today
|
||
|
verbose disk info ${ctrl_log}.today
|
||
|
smart ${ctrl_log}.today
|
||
|
verbose hw info ${ctrl_log}.today
|
||
|
lines=`wc -l ${ctrl_log}.today | awk '{ print $1 }'`
|
||
|
diff -u -$lines ${ctrl_log}.yesterday ${ctrl_log}.today
|
||
|
raid_rc=$?
|
||
|
if test $raid_rc -eq 0; then
|
||
|
cat ${ctrl_log}.today
|
||
|
fi
|
||
|
[ $rc -eq 0 ] && [ $raid_rc -ne 0 ] && rc=3
|
||
|
|
||
|
# Checking logs.
|
||
|
echo "Logs (most recent first):"
|
||
|
logs_log=${logdir}/arcmsr_log_${ctrl}
|
||
|
case "$daily_status_arcmsr_raid_persist_logs" in
|
||
|
[Yy][Ee][Ss])
|
||
|
if test ! -f ${logs_log}.today; then
|
||
|
touch ${logs_log}.today
|
||
|
fi
|
||
|
mv -f ${logs_log}.today ${logs_log}.yesterday
|
||
|
${areca_cli} event info > ${logs_log}.today
|
||
|
cmp -zs ${logs_log}.yesterday ${logs_log}.today
|
||
|
raid_rc=$?
|
||
|
if test $raid_rc -ne 0; then
|
||
|
diff -u ${logs_log}.yesterday ${logs_log}.today | \
|
||
|
grep -v '^-\|^$'
|
||
|
fi
|
||
|
;;
|
||
|
*)
|
||
|
raid_rc=0
|
||
|
${areca_cli} event info > ${logs_log}.today
|
||
|
${areca_cli} event clear >> ${logs_log}.today
|
||
|
lines=`wc -l ${logs_log}.today | awk '{ print $1 }'`
|
||
|
if test $lines -gt 4; then
|
||
|
cat ${logs_log}.today
|
||
|
raid_rc=1
|
||
|
fi
|
||
|
;;
|
||
|
esac
|
||
|
if test $raid_rc -eq 0; then
|
||
|
echo " No new alarms."
|
||
|
fi
|
||
|
[ $rc -eq 0 ] && [ $raid_rc -ne 0 ] && rc=3
|
||
|
;;
|
||
|
|
||
|
*) rc=0;;
|
||
|
esac
|
||
|
|
||
|
exit $rc
|
||
|
|
||
|
# end
|