2011-06-29 18:36:13 +02:00
#!/bin/bash
2011-09-22 14:23:45 +02:00
DISK=${0/*smart-by-id_/}
SMARTCTL="`which smartctl | head -1` $SMARTOPTS"
2011-06-29 18:36:13 +02:00
echo "# $DISK"
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
case $1 in
config)
echo 'graph_title S.M.A.R.T values for drive '`readlink -f /dev/disk/by-id/$DISK`
echo 'graph_vlabel Attribute S.M.A.R.T value'
echo 'graph_args --base 1000 --lower-limit 0'
echo 'graph_category disk'
2011-09-22 10:50:27 +02:00
echo 'graph_info This graph shows the value of all S.M.A.R.T attributes of drive '`$SMARTCTL -i /dev/disk/by-id/$DISK | grep -Ei 'model|serial|firmware' | sed -re 's/.+?: +//gm' | tr '\n' ' '`
2011-06-29 18:36:13 +02:00
echo 'smartctl_exit_status.label smartctl exit value'
echo 'smartctl_exit_status.draw LINE2'
echo 'smartctl_exit_class.label smartctl exit status'
echo 'smartctl_exit_class.draw AREA'
echo 'smartctl_exit_class.warning :0'
echo 'smartctl_exit_class.critical :1'
2011-09-22 10:50:27 +02:00
$SMARTCTL -A /dev/disk/by-id/$DISK | grep 0x | while read
2011-06-29 18:36:13 +02:00
do
2011-09-22 10:50:27 +02:00
OP=($REPLY)
ON=`echo -n ${OP[1]} | tr -c '[A-z0-9]' '_'`
OL=`echo -n ${OP[1]} | tr '_' ' '`
echo ${ON}.label ${OL}
echo ${ON}.draw LINE2
2011-09-22 14:23:45 +02:00
echo ${ON}.critical ${OP[5]}:
2011-06-29 18:36:13 +02:00
done
;;
suggest)
ls -1 /dev/disk/by-id/scsi-* | grep -v part | grep -o scsi.*
;;
"")
2011-09-22 10:50:27 +02:00
$SMARTCTL -a /dev/disk/by-id/$DISK &> /dev/null
2011-06-29 18:36:13 +02:00
SES=$?
echo "smartctl_exit_status.value $SES"
if [ $SES -gt 0 ]
then
2011-09-22 10:50:27 +02:00
if [ $((SES & 7)) -gt 0 ] ; then exit 1 ; fi
if [ $((SES & 24)) -gt 0 ] ; then SES=2 ; fi
if [ $((SES & 224)) -gt 0 ] ; then SES=1 ; fi
2011-06-29 18:36:13 +02:00
fi
echo "smartctl_exit_class.value $SES"
2011-09-22 14:23:45 +02:00
$SMARTCTL -A /dev/disk/by-id/$DISK | awk '/0x/ { gsub(/[^a-zA-Z0-9]/,"_",$2); print $2.".value",$4; }'
2011-06-29 18:36:13 +02:00
;;
esac
2011-09-22 14:23:45 +02:00
#exit 0