scripts/xymon/plugins/client/ext/smart

59 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# NOTE: Must be run as root, so you probably need to setup sudo for this.
if test -f /tmp/dres; then rm -f /tmp/dres; fi
2020-02-19 11:18:25 +01:00
smartctl --scan > /tmp/dscan
# MODIFY below to match your setup - the "scsi-SATA" is pretty generic, but you
# can add more disks if you like. E.g. I have a USB disk permanently plugged in.
2020-02-19 11:18:25 +01:00
while read LINE
do
2020-02-19 11:18:25 +01:00
DISK=$(echo "${LINE}" | cut -d" " -f1)
TYPE=$(echo "${LINE}" | cut -d" " -f3)
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
DCODE=$?
DSTBY=$(( DCODE & 2 ))
DFAIL=$(( DCODE & 8 ))
DWARN=$(( DCODE & 32 ))
if test $DSTBY -ne 0
then
COLOR="4&clear"
elif test $DFAIL -ne 0
then
COLOR="1&red"
elif test $DWARN -ne 0
then
COLOR="2&yellow"
else
COLOR="3&green"
fi
2020-02-19 11:18:25 +01:00
echo "${COLOR} $DISK ${TYPE}"
2020-02-19 11:18:25 +01:00
echo "${COLOR} $DISK ${TYPE}" | cut -c2- >>/tmp/dres
echo "" >>/tmp/dres
echo "$DRES" | egrep -v "^smartctl|^Copyright|^$|^===" >>/tmp/dres
echo "------------------------------------------------------------" >>/tmp/dres
echo "" >>/tmp/dres
echo "" >>/tmp/dres
2020-02-19 11:18:25 +01:00
done < /tmp/dscan >/tmp/dcheck
COLOR=$(< /tmp/dcheck awk '{print $1}' | sort | uniq | head -1 | cut -c3-)
$XYMON $XYMSRV "status ${MACHINE}.smart ${COLOR} SMART health check
$(< /tmp/dcheck cut -c2-)
==================== Detailed status ====================
$(cat /tmp/dres)
"
2020-02-19 11:18:25 +01:00
rm -f /tmp/dres /tmp/dcheck /tmp/dscan
exit 0