X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fexec-smartctl;h=d469816037946d34ae2daf7df5f36b91da0bfb11;hb=157045783cadbe242b237ed9c39f1ca5e622efaf;hp=a5d8b134f6fb22ae7f352e6b9cb4f5deaf01167c;hpb=33e893df1a9d4243155b86dd32b7288cc0f04f18;p=collectd.git diff --git a/contrib/exec-smartctl b/contrib/exec-smartctl index a5d8b134..d4698160 100755 --- a/contrib/exec-smartctl +++ b/contrib/exec-smartctl @@ -1,5 +1,24 @@ #!/bin/bash +# Sample script for the exec plugin (collectd-exec(5)) +# +# This script uses smartctl(8) to read HDD temperatures. The drives are +# attached to a 3ware RAID controller which hddtempd can't handle. +# Unfortunately the smartmontools don't have a library so we can't write a +# C-plugin, at least not easily. +# Please note that only root can read the SMART attributes from harddrives, +# because special ``capabilities'' are necessary. However, the exec plugin will +# refuse to run scripts as root, which is why `sudo' is used here for +# fine-grained root privileges for the user `smart'. This isn't as straigt +# forward as one might hope, but we think that the gained security is worth it. + +# The sudo configuration looks something like this: +# -- 8< -- +# Cmnd_Alias SMARTCTL = /usr/sbin/smartctl -d 3ware\,0 -A /dev/twe0, /usr/sbin/smartctl -d 3ware\,1 -A /dev/twe0, /usr/sbin/smartctl -d ata -A /dev/sda +# smart ALL = (root) NOPASSWD: SMARTCTL +# -- >8 -- + +HOST="huhu" INTERVAL=60 while true @@ -9,21 +28,21 @@ do then TEMP="U" fi - echo "huhu/exec-smart/temperature-3ware_0 interval=$INTERVAL N:$TEMP" + echo "$HOST/exec-smart/temperature-3ware_0 interval=$INTERVAL N:$TEMP" TEMP=$((sudo smartctl -d 3ware,1 -A /dev/twe0 | grep Temperature_Celsius | awk '{ print $10; }') 2>/dev/null); if [ $? -ne 0 ] then TEMP="U" fi - echo "huhu/exec-smart/temperature-3ware_1 interval=$INTERVAL N:$TEMP" + echo "$HOST/exec-smart/temperature-3ware_1 interval=$INTERVAL N:$TEMP" TEMP=$((sudo smartctl -d ata -A /dev/sda | grep Temperature_Celsius | awk '{ print $10; }') 2>/dev/null); if [ $? -ne 0 ] then TEMP="U" fi - echo "huhu/exec-smart/temperature-sata_0 interval=$INTERVAL N:$TEMP" + echo "$HOST/exec-smart/temperature-sata_0 interval=$INTERVAL N:$TEMP" sleep $INTERVAL done