#!/bin/bash VERSION='Xymon smartmon script: version 1.2a' # hacked to skip over x server raid arrays # 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=$(${SUDO} ${SMARTCTL} --scan 2>/dev/null | tr "\n" "|") while (( 0 < ${#devices} )) do loc=$(expr index "${devices}" "#") ((cnt = cnt + 1)) device[${cnt}]=${devices:0:${loc}-1} #DEBUG# echo ${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]} 2>/dev/null) #DEBUG# echo "${dt} $d ${device[$d]} ${fullResult}" # Cd/DVD devices are Unavailable -- so skip them skip1=$(echo ${fullResult} | grep 'SMART support is: Unavailable') skip2=$(echo ${fullResult} | grep 'mandatory SMART command failed:') if [[ 'X' == "X${skip1}" && 'X' == "X${skip2}" ]] then # this grabs reult or status line (scsi reports status: Ok and converts ok to passed) result=$(${SUDO} ${SMARTCTL} -H ${device[$d]} 2>/dev/null | egrep 'result:|Status:' | awk -F':' '{print $2}' | sed 's/ //g'| sed 's/OK/PASSED/') info=$(${SUDO} ${SMARTCTL} -i ${device[$d]} 2>/dev/null) 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"