Date: Sat, 29 Jan 2011 21:23:34 GMT From: Marian Jamrich <jamrich.majo@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/154382: [update port version] - nagios_check_hdd_health - Nagios plug-in to check HDD health from S.M.A.R.T Message-ID: <201101292123.p0TLNYgq083966@red.freebsd.org> Resent-Message-ID: <201101292130.p0TLUAXT003140@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 154382 >Category: ports >Synopsis: [update port version] - nagios_check_hdd_health - Nagios plug-in to check HDD health from S.M.A.R.T >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Sat Jan 29 21:30:10 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Marian Jamrich >Release: >Organization: >Environment: >Description: - update port from 1.0.1 to 1.1 version >How-To-Repeat: >Fix: Patch attached with submission follows: diff -ruN /usr/ports/net-mgmt/nagios-check_hdd_health/pkg-descr /home/jamrich/ports/hdd/pkg-descr --- /usr/ports/net-mgmt/nagios-check_hdd_health/pkg-descr 2010-12-10 05:51:19.000000000 +0100 +++ /home/jamrich/ports/hdd/pkg-descr 2011-01-25 13:58:05.377870636 +0100 @@ -1,5 +1,7 @@ -check_hdd_health is a Nagios plug-in written in shell to check HDD health. -This script check HDD from S.M.A.R.T this values: +Check_hdd_health is a Nagios plug-in written in shell to check HDD health. + +This script check HDD from this S.M.A.R.T values: + - Spin Retry Count - Reallocated Sector Ct - Reallocated Event Count diff -ruN /usr/ports/net-mgmt/nagios-check_hdd_health/src/check_hdd_health /home/jamrich/ports/hdd/src/check_hdd_health --- /usr/ports/net-mgmt/nagios-check_hdd_health/src/check_hdd_health 2011-01-03 14:45:25.000000000 +0100 +++ /home/jamrich/ports/hdd/src/check_hdd_health 2011-01-25 14:24:00.385428300 +0100 @@ -16,7 +16,7 @@ PROGNAME=`basename $0` # Version -VERSION="Version 1.0.1" +VERSION="Version 1.1" # Author AUTHOR="Marian Jamrich" @@ -26,9 +26,9 @@ # Clean up when done or when aborting trap "rm -f ${TMPFILE}" 0 1 2 3 15 -#print_version() { -# echo "$PROGNAME $VERSION $1" -#} +print_version() { + echo "Nagios-$PROGNAME ($VERSION)" +} mini_help() { echo "Usage $0 --device $device --without [src rsc rec cps ou]" @@ -36,9 +36,9 @@ print_help() { clear; - echo "*********************************************************************************" - echo "* $PROGNAME $VERSION $1""($AUTHOR) <jamrich.majo@gmail.com> (2011) *" - echo "*********************************************************************************" + echo "**************************************************************************************" + echo "* $PROGNAME $VERSION $1""($AUTHOR) <jamrich.majo@gmail.com> (2011) *" + echo "**************************************************************************************" echo "This is Nagios plugin to check HDD health from S.M.A.R.T. by Smartmontools." echo ' The S.M.A.R.T. attributes are specific properties (parameters) of various parts of a disk. @@ -80,7 +80,7 @@ echo "Critical - if some value is greater than \"0\" except \"Spin Retry Count (>=10)\" and \"Reallocated Event Count (>=10)\"." echo -e "\n---------------------------------------------------------------------" echo "Usage:" - echo "$0 --device /dev/ad0 [ --without [src rsc rec cps ou]]" + echo "$0 --device ad0 [ --without [src rsc rec cps ou]]" echo "---------------------------------------------------------------------" exit $ST_UN } @@ -93,12 +93,12 @@ -d | --device) device=$2 ;; - -V) + -v) print_version - exit + exit $ST_UN ;; *) - echo "Unknown argument: $1" + echo "Unknown argument: $1" echo "For more information please try -h or --help!" exit $ST_UN ;; @@ -108,26 +108,30 @@ test -z $device && echo -e "\nYou forgot to define device! Please try \"-h or --help\" to help." && exit $ST_UN test `uname` != "FreeBSD" && echo "This plugin is only for FreeBSD." && exit $ST_UN +format_device=`echo $device | grep -w 'dev'` +if [ -z $format_device ]; then + device=/dev/`echo $device` +fi + if [ ! -e $device ]; then - echo - echo "Unknown device \"$device\"!" - exit $ST_UN + echo "Unknown device \"$device\"!" + exit $ST_UN fi if [ -z $smartctl ]; then - echo -e "\nYou don't have installed $SMT. Please install it at http://smartmontools.sourceforge.net or pkg_add -r \"smartmontools\"..." - exit $ST_UN + echo -e "\nYou don't have installed $SMT. Please install it from 'http://smartmontools.sourceforge.net' or pkg_add -r \"smartmontools\"..." + exit $ST_UN fi $smartctl -a $device > ${TMPFILE} SMART_SUPPORT=`awk '/SMART support is/ {print $4}' ${TMPFILE} | tail -n 1` if [ "${SMART_SUPPORT}" = "Unavailable" ]; then - echo -e "\nS.M.A.R.T support is Unavailable for $device !!! You should enable it \"smartctl -s on $device\"." - exit $ST_UN + echo -e "\nS.M.A.R.T support is unavailable for $device !!! You should enable it \"smartctl -s on $device\"." + exit $ST_UN elif [ "${SMART_SUPPORT}" != "Enabled" ]; then - echo -e "\nMaybe you don't have enabled S.M.A.R.T support in $SMT! Please type \"smartctl -s on $device\" that you have it turned on. Or device does not support S.M.A.R.T function." - exit $ST_UN + echo -e "\nMaybe you don't have enabled S.M.A.R.T support in $SMT! Please type \"smartctl -s on $device\" that you have it turned on, or device does not support S.M.A.R.T function." + exit $ST_UN fi ## start S.M.A.R.T test and set variables @@ -138,7 +142,7 @@ ou=`awk '/Offline_Uncorrectable/ {print $10}' ${TMPFILE} ` pass=`awk -F\: '/test result/ { if ( $2 == " PASSED") print "PASSED"; else print "FAILED" }' ${TMPFILE} ` -## if one or more S.M.A.R.T function is not supported by your HDD, then you define --without variable and then value is set to "0" +## if one or more S.M.A.R.T function is not supported by your HDD, then you define --without variable and then value is set automatically to "0" args=`getopt w:without: $*` for arg; do case "$arg" in @@ -150,16 +154,18 @@ esac done -# test if your HDD support all parameters: -[ -z "$src" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support Spin_Retry_Count. Please try \"--without src\"." && mini_help && exit $ST_UN -[ -z "$rsc" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support Reallocated_Sector_Ct. Please try \"--without rsc\"." && mini_help && exit $ST_UN -[ -z "$rec" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support Reallocated_Event_Count. Please try --without rec." && mini_help && exit $ST_UN -[ -z "$cps" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support Current_Pending_Sector. Please try --without cps." && mini_help && exit $ST_UN -[ -z "$ou" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support Offline_Uncorrectable. Please try \"--without ou\"." && mini_help && exit $ST_UN +# test if your HDD support all this parameters: +[ -z "$src" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support "Spin Retry Count". Please try \"--without src\"." && mini_help && exit $ST_UN +[ -z "$rsc" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support "Reallocated Sector Ct". Please try \"--without rsc\"." && mini_help && exit $ST_UN +[ -z "$rec" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support "Reallocated Event Count". Please try --without rec." && mini_help && exit $ST_UN +[ -z "$cps" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support "Current Pending Sector". Please try --without cps." && mini_help && exit $ST_UN +[ -z "$ou" ] && echo -e "***********\n** ERROR **\n***********\n${device} don't support "Offline Uncorrectable". Please try \"--without ou\"." && mini_help && exit $ST_UN perfdata="smart=src=$src; rsc=$rsc; rec=$rec; cps=$cps; ou=$ou; pass=$pass" +############################################################ ##### finally run test, print result and set exit code ##### +############################################################ if [ $src -eq 0 ] && [ $rsc -eq 0 ] && [ $rec -eq 0 ] && [ $cps -eq 0 ] && [ $ou -eq 0 ] && [ "$pass" = "PASSED" ]; then echo "OK - HDD S.M.A.R.T health: src=$src, rsc=$rsc, rec=$rec, cps=$cps, ou=$ou, HEALTH_STATUS=$pass for $device. |${perfdata}" exit $ST_OK >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101292123.p0TLNYgq083966>