#!/bin/bash
VERSION='1.4'
# clientlaunch.d/smartmon.cfg
#[smart]
# ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
# CMD $XYMONCLIENTHOME/ext/smartmon.bash
# LOGFILE $XYMONCLIENTHOME/logs/smartmon.log
# INTERVAL 5m
# IMPORTANT::
# yum install smartmontools
# Add the following to sudoers file (visudo):
# * Defaults:xymon !requiretty
# * xymon ALL=NOPASSWD:/usr/sbin/smartctl
#DEBUG# echo "bb=[$BB]"
#DEBUG# echo "bbdisp=[$BBDISP]"
NL="
"
DASHES="
"
DASH="
"
COLOR="clear"
COLUMN="smart"
MSG="No S.M.A.R.T. device detected."
VERMSG="
Version: ${VERSION}"
RAID=""
SMARTCTL="/usr/sbin/smartctl"
SUDO="/usr/bin/sudo"
DATE=$(date)
EXTRA='OK'
MSGdetail=''
shopt -s lastpipe
# build a list of devices smartmon might be monitoring
((cnt=0))
scan=$(${SUDO} ${SMARTCTL} --scan | awk '{print $1,$3}')
cnt=$(echo "${scan}" | wc -l)
# if no devices, leave color clear
if ((0 < cnt))
then
COLOR='green'
MSG=''
# process each device and build up messages
set ${scan}
for i in $(seq 1 ${cnt})
do
dev="$1"
shift
kind="$1"
shift
# smartctl -d scsi -H /dev/sda
statusResult=$(${SUDO} ${SMARTCTL} -d ${kind} -H ${dev} | grep 'SMART Health Status')
# Cd/DVD devices are Unavailable -- so skip them
skip=$(echo ${statusResult} | grep 'SMART support is: Unavailable')
if [[ 'X' == "X${skip}" ]]
then
status=$(echo "${statusResult}" | grep 'OK' | wc -l)
# anytime we get a problem -- make color red
if (( 0 == status ))
then
COLOR='red'
EXTRA='Failure!'
fi
summary=$(${SUDO} ${SMARTCTL} -i ${dev})
MSG="${MSG}${NL}${dev}${DASH}${statusResult}
${summary}${DASHES}"
detail=$(${SUDO} ${SMARTCTL} --all ${dev})
MSGdetail="${MSGdetail}${NL}${dev}${DASH}${detail}${DASHES}"
fi
done
fi
${BB} ${BBDISP} "status ${MACHINE}.${COLUMN} ${COLOR} ${DATE} ${EXTRA} Device Info
${MSG} Device details
${MSGdetail}${NL}${VERMSG}"
#DEBUG# tmp="$?"
#DEBUG# echo "error code: $tmp"