Index: check_nis
===================================================================
--- check_nis	(revision 471)
+++ check_nis	(working copy)
@@ -1,4 +1,6 @@
-#!/usr/bin/sh
+#!/bin/bash
+# vim:ts=4:sw=4:si:tw=80:isfname-==
+#
 ###############################################
 #
 # Nagios script to check NIS status on a host
@@ -9,33 +11,38 @@
 # 
 # Created: 2006-07-04 (i.yates@uea.ac.uk)
 #
+# Roy Sigurd Karlsbakk <roy@karlsbakk.net> 2010-09-20:
+#
+#   Added variable for nagios install path, changed the she shell to something
+#   less Solarisish, later bashified the script, added som vim settings, checks
+#   for includes, saner error checking (there were very little), added return
+#   code 2 (unknown) in case of something wierd (or usage() called), added test
+#   for -d to be required.
+#
 ###############################################
 
-. /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
-
-
+# Set this to your nagios install
+NAGIOS_PATH="/usr/local/nagios"
+NAGUTILS="$NAGIOS_PATH/libexec/utils.sh"
+VERSION="1.1"
 FLAG_VERBOSE=FALSE
 NIS_HOST=""
 NIS_DOMAIN=""
 RESULT=""
 EXIT_STATUS=$STATE_OK
 
-
 ###############################################
 #
 ## FUNCTIONS 
 #
 
+function die() {
+	echo "UNKNOWN: " $@
+	exit 2
+}
+
 ## Print usage
-usage() {
+function usage() {
 	echo " check_nis $VERSION - Nagios NIS check script"
 	echo ""
 	echo " Usage: check_nis -H <hostname> -d <nis domain> [ -v ] [ -h ]"
@@ -44,39 +51,48 @@
 	echo "		 -d  NIS domain"
 	echo "		 -v  Verbose output"
 	echo "		 -h  Show this page"
-	echo ""
+	echo
+	exit 2
 }
  
 ## Process command line options
-doopts() {
+function doopts() {
 	if ( `test 0 -lt $#` )
 	then
 		while getopts H:d:vh myarg "$@"
 		do
 			case $myarg in
-				h|\?)
+				'?'|'h')
 					usage
-					exit;;
-				H)
-					NIS_HOST=$OPTARG;;
-				d)
-					NIS_DOMAIN=$OPTARG;;
-				v)
-					FLAG_VERBOSE=TRUE;;
+					;;
+				'H')
+					NIS_HOST=$OPTARG
+					;;
+				'd')
+					NIS_DOMAIN=$OPTARG
+					;;
+				'v')
+					FLAG_VERBOSE=TRUE
+					;;
 				*)	# Default
 					usage
-					exit;;
+					;;
 			esac
 		done
 	else
 		usage
-		exit
 	fi
+
+	# check if we got what we need
+	if [ "$NIS_HOST" == "" ] || [ "$NIS_DOMAIN" == "" ]; then
+		echo "UNKNOWN: Need both NIS host and domain"
+		exit $STATE_UNKNOWN
+	fi
 }
 
 
 # Write output and return result
-theend() {
+function theend() {
 	echo $RESULT
 	exit $EXIT_STATUS
 }
@@ -86,6 +102,15 @@
 ## END FUNCTIONS 
 #
 
+# Programs needed
+GREP=`which grep` || die "Can't find grep"
+YPPOLL=`which yppoll` || die "Can't find ypoll"
+
+if [ ! -f $NAGUTILS ]; then
+	echo "UNKNOWN: Cant find Nagios' utils.sh $NAGUTILS: $!"
+	exit $STATE_UNKNOWN
+fi
+
 #############################################
 #
 ## MAIN 
@@ -107,3 +132,4 @@
 
 # Quit and return information and exit status
 theend
+
