1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 02:18:08 +00:00

optimized version, replaced grep/sed with tr and awk in some places, provisioning for special chars in SMART attributes

This commit is contained in:
Stefan Seidel 2011-09-22 10:50:27 +02:00 committed by Steve Schnepp
parent f038b18b35
commit 0767fa14ba

View file

@ -1,6 +1,7 @@
#!/bin/bash
DISK=${0/*smart-by-id_/}
DISK="${0/*smart-by-id_/}"
SMARTCTL="smartctl $SMARTOPTS"
echo "# $DISK"
@ -12,39 +13,39 @@ config)
echo 'graph_vlabel Attribute S.M.A.R.T value'
echo 'graph_args --base 1000 --lower-limit 0'
echo 'graph_category disk'
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' ' '`
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' ' '`
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'
smartctl -A /dev/disk/by-id/$DISK | grep 0x | while read
$SMARTCTL -A /dev/disk/by-id/$DISK | grep 0x | while read
do
OP=($REPLY)
ON=`echo ${OP[1]} | sed -e 's/-/_/g'`
OL=`echo ${OP[1]} | sed -e 's/_/ /g'`
echo ${ON}.label ${OL}
echo ${ON}.draw LINE2 | sed -e 's/-/_/g'
echo ${ON}.critical ${OP[5]}: | sed -e 's/-/_/g'
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
echo ${ON}.critical $((${OP[5]})):
done
;;
suggest)
ls -1 /dev/disk/by-id/scsi-* | grep -v part | grep -o scsi.*
;;
"")
smartctl -a /dev/disk/by-id/$DISK &> /dev/null
$SMARTCTL -a /dev/disk/by-id/$DISK &> /dev/null
SES=$?
echo "smartctl_exit_status.value $SES"
if [ $SES -gt 0 ]
then
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
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
fi
echo "smartctl_exit_class.value $SES"
smartctl -A /dev/disk/by-id/$DISK | grep 0x | awk '{ print $2.".value",$4; }' | sed -e 's/-/_/g'
$SMARTCTL -A /dev/disk/by-id/$DISK | awk '/0x/ { gsub(/[^a-Z0-9]/,"_",$2); print $2.".value",$4; }'
;;
esac