#!/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."
VERSION='1.1'
VERMSG="
Version: ${VERSION}"
RAID=""
SMARTCTL="/usr/sbin/smartctl"
SUDO="/usr/bin/sudo"
DATE=$(date)
EXTRA='OK'
# 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
fullResult=$(${SUDO} ${SMARTCTL} -H ${device[$d]})
# 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'
EXTRA='Failure'
fi
fi
((d = d + 1))
done
#DEBUG# echo "DEBUG $BB $BBDISP \"status $MACHINE.$COLUMN $COLOR ${DATE} $MSG ${DASHES}${VERSION}\""
#DEBUG# echo "DEBUG $BB $BBDISP \"status $MACHINE.$COLUMN $COLOR ${DATE} $MSG ${DASHES}${VERSION}\""
#DEBUG# echo "set"
#DEBUG# set | grep -i xymon
#DEBUG# set | grep -i bb
${BB} ${BBDISP} "status ${MACHINE}.${COLUMN} ${COLOR} ${DATE} ${EXTRA} ${MSG} ${DASHES} ${VERMSG}"
#DEBUG# tmp="$?"
#DEBUG# echo "error code: $tmp"