#!/bin/sh # # Nagios plugin for RAID controller you can check with the dptutil # # (c) 2007 Kai-H. Weutzing # # # sudo is needed! # use the 'visudo' command and append # 'nagios ALL = NOPASSWD: /usr/dpt/dptutil -L all' # "nagios" is the user who executes this script # # # the regular expression in awk are based on output from the # DPTUTIL Version: 2.27 Date: 4/11/2000 # PATH='/bin:/sbin:/usr/bin:/usr/sbin' PROGNAME="$(basename $0)" PROGPATH="$(dirname $0)" REVISION='1.0' print_usage() { echo "Usage: $PROGNAME (Checks all controllers found)" echo "Usage: $PROGNAME --help|-h" echo "Usage: $PROGNAME --version|-V" } print_help() { print_usage echo -e "\nThis Nagios plugin checks RAID controller you can check with the dptutil commandline tool.\n" exit 0 } while test -n "$1" do case "$1" in --help|-h) print_help exit 0 ;; --version|-V) echo "${PROGNAME} Rev. ${REVISION}" exit 0 ;; *) print_usage exit 3 ;; esac done DPTUTIL='/usr/dpt/dptutil' if [ "$EUID" -eq 0 ] then SUDO='' else # TODO # test on sudo rights: # (root) NOPASSWD: /usr/dpt/dptutil -L logical SUDO='sudo' fi DPTUTIL_ALL="${DPTUTIL} -L all" TEMPFILE="$(mktemp)" || TEMPFILE="/tmp/tempfile.$(date +%s%N)" trap "rm -f ${TEMPFILE} >& /dev/null" exit if $SUDO ${DPTUTIL_ALL} >& "${TEMPFILE}" then awk ' BEGIN { FS = "\n" RS = "" STATE_OK = 0 STATE_WARNING = 1 STATE_CRITICAL = 2 STATE_UNKNOWN = 3 STATE_DEPENDENT = 4 EXITCODE = STATE_UNKNOWN count["total"] = 0 count["ok"] = 0 count["warn"] = 0 count["crit"] = 0 buffer = "" } /^# b0 b1 b2/ { total_lines = NF - 2; count["total"] = count["total"] + total_lines for ( i = 3; i <= NF; i++ ) { matched = 0 if ( match ( $i, "Optimal$" ) ) { count["ok"]++ matched++ } if ( match ( $i, "Verifying [[:digit:]]+%$" ) ) { count["warn"]++ buffer = buffer " -- " $i matched++ } if ( matched == 0 ) { count["crit"]++ buffer = buffer " -- " $i } } } /^Physical View/ { total_lines = NF - 3; count["total"] = count["total"] + total_lines for ( i = 4; i <= NF; i++ ) { matched = 0 if ( match ( $i, "Optimal$" ) ) { count["ok"]++ matched++ } if ( match ( $i, "Verifying [[:digit:]]+%$" ) ) { count["warn"]++ buffer = buffer " -- " $i matched++ } if ( matched == 0 ) { count["crit"]++ buffer = buffer " -- " $i } } } /^Logical View/ { total_lines = NF - 3; count["total"] = count["total"] + total_lines for ( i = 4; i <= NF; i++ ) { matched = 0 if ( match ( $i, "Optimal$" ) ) { count["ok"]++ matched++ } if ( match ( $i, "Verifying [[:digit:]]+%$" ) ) { count["warn"]++ buffer = buffer " -- " $i matched++ } if ( matched == 0 ) { count["crit"]++ buffer = buffer " -- " $i } } } END { # DEBUG #print "total: "count["total"] #print "ok: "count["ok"] #print "warning: "count["warn"] #print "critical: "count["crit"] if ( count["total"] == count["ok"] && count["warn"] == 0 && count["crit"] == 0 ) { EXITCODE = STATE_OK print "OK: Found " count["ok"] " ok states" } if ( count["warn"] >= 1 && count["crit"] == 0 ) { EXITCODE = STATE_WARNING print "WARNING: Found " count["warn"] " warning and " count["ok"] " ok states -- " buffer } if ( count["crit"] >= 1 ) { EXITCODE = STATE_CRITICAL print "CRITICAL: Found " count["crit"] " critical, " count["warn"] " warning and " count["ok"] " ok states -- " buffer } exit EXITCODE } ' "${TEMPFILE}" STATE="$?" else echo "Error: command failed" >&2 STATE="$STATE_UNKNOWN" fi exit $STATE