#!/bin/bash
VERSION='Xymon smartmon script: version 1.2'
# 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."
RAID=""
SMARTCTL="/usr/sbin/smartctl"
SUDO="/usr/bin/sudo"
DATE=$(date)
# build a list of devices smartmon might be monitoring
((cnt=0))
devices=$(/usr/sbin/smartctl --scan | tr "\n" "|")
while (( 0 < ${#devices} ))
do
loc=$(expr index "${devices}" "#")
((cnt = cnt + 1))
device[${cnt}]=${devices:0:${loc}-1}
loc=$(expr index "${devices}" "|")
devices=${devices:loc}
done
# process through each device
((d=1))
while ((d <= cnt))
do
dt=$(date)
fullResult=$(${SUDO} ${SMARTCTL} -H ${device[$d]})
#DEBUG# echo "${dt} $d ${device[$d]} ${fullResult}"
# Cd/DVD devices are Unavailable -- so skip them
skip=$(echo ${fullResult} | grep 'SMART support is: Unavailable')
if [[ 'X' == "X${skip}" ]]
then
# this grabs reult or status line (scsi reports status: Ok and converts ok to passed)
result=$(${SUDO} ${SMARTCTL} -H ${device[$d]} | egrep 'result:|Status:' | awk -F':' '{print $2}' | sed 's/ //g'| sed 's/OK/PASSED/')
info=$(${SUDO} ${SMARTCTL} -i ${device[$d]})
if [[ 'clear' == "${COLOR}" ]]
then
MSG="${NL}
${device[$d]}
${DASHES}${fullResult}${DASH}${info}"
else
MSG="${MSG}
${device[$d]}
${DASHES}${fullResult}${DASH}${info}"
fi
if [[ 'XPASSED' == "X${result}" ]]
then
if [[ 'clear' == "${COLOR}" ]]
then
COLOR='green'
fi
else
COLOR='red'
fi
fi
((d = d + 1))
done
#DEBUG# echo "$BB $BBDISP \"status $MACHINE.$COLUMN $COLOR ${DATE} $MSG\""
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR ${DATE} $MSG ${DASHES}${VERSION}"
#DEBUG# tmp="$?"
#DEBUG# echo "error code: $tmp"