#!/usr/bin/sh ############################################### # # Nagios script to check NIS status on a host # # See usage for command line switches # # Author: Ian Yates (i.yates@uea.ac.uk) # # Created: 2006-07-04 (i.yates@uea.ac.uk) # ############################################### . /usr/local/nagios/libexec/utils.sh VERSION="1.0" AWK=/usr/bin/awk SED=/usr/bin/sed GREP=/usr/bin/grep YPPOLL=/usr/sbin/yppoll FLAG_VERBOSE=FALSE NIS_HOST="" NIS_DOMAIN="" RESULT="" EXIT_STATUS=$STATE_OK ############################################### # ## FUNCTIONS # ## Print usage usage() { echo " check_nis $VERSION - Nagios NIS check script" echo "" echo " Usage: check_nis -H -d [ -v ] [ -h ]" echo "" echo " -H Name of host running the NIS service you wish to check" echo " -d NIS domain" echo " -v Verbose output" echo " -h Show this page" echo "" } ## Process command line options doopts() { if ( `test 0 -lt $#` ) then while getopts H:d:vh myarg "$@" do case $myarg in h|\?) usage exit;; H) NIS_HOST=$OPTARG;; d) NIS_DOMAIN=$OPTARG;; v) FLAG_VERBOSE=TRUE;; *) # Default usage exit;; esac done else usage exit fi } # Write output and return result theend() { echo $RESULT exit $EXIT_STATUS } # ## END FUNCTIONS # ############################################# # ## MAIN # # Handle command line options doopts $@ # Do the do OUTPUT=`$YPPOLL -h $NIS_HOST -d $NIS_DOMAIN passwd.byname 2> /dev/null | $GREP 'is supported'` if test "$OUTPUT" != "" ; then RESULT="NIS OK - domain $NIS_DOMAIN" EXIT_STATUS=$STATE_OK else RESULT="NIS CRITICAL - domain $NIS_DOMAIN not answering" EXIT_STATUS=$STATE_CRITICAL fi # Quit and return information and exit status theend