[Nagiosplug-devel] Patches to Plugins

Bertelson, Tom (CAP, CARD) Tom.Bertelson at gecapital.com
Wed Jun 5 10:24:04 CEST 2002


Here are some patches I came up with to get the plugins working for my
Solaris environment.  They should work for other platforms, too.

configure.in:  ntpdc may be called xntpdc
check_flexlm:  Gracefully fail if lmstat not found
check_log:     Work more like contrib/check_log2.  WARNING:  This may not be
               backward compatible with the original check_log.
check_ntp:     Work even if ntpdc not found
check_oracle:  Add test for Oracle names server, can dynamically determine
               ORACLE_HOME
subst:         Can mess up substitutions
utils.sh:      Not POSIXLY_CORRECT
check_disk:    Add flag to display mount points instead of partitions,
produce
               output even if df has errrors

(I hope !#%!@* Outlook doesn't mangle this too badly)
Enjoy!
-- 
Tom Bertelson                "Any sufficient advanced technlogy
GE Card Services              is indistinguishable from magic."
Tom.Bertelson at gecapital.com      -- Arthur C. Clarke

--- configure.in.orig	Sun May 26 22:03:37 2002
+++ configure.in	Tue Jun  4 20:56:08 2002
@@ -488,6 +504,8 @@
 elif [ps -el 2>/dev/null | egrep -i "^ *F +S +UID +PID +PPID +C +PRI +NI
+ADDR +SZ +WCHAN +TTY +TIME +[RGSCOMDNA]+" >/dev/null]
 then
 	AC_DEFINE(USE_PS_VARS)
+	AC_DEFINE_UNQUOTED(PS_RAW_COMMAND,"$PATH_TO_PS -ef")
+	EXTRAS="$EXTRAS check_nagios"
 
AC_DEFINE_UNQUOTED(PS_VARLIST,[procstat,&procuid,&procppid,&pos,procprog])
 	AC_DEFINE_UNQUOTED(PS_COMMAND,"$PATH_TO_PS -el")
 	AC_DEFINE_UNQUOTED(PS_FORMAT,"%*s %s %d %*s %d %*s %*s %*s %*s %*s
%*s %*s %*s %n%s")
@@ -649,7 +667,7 @@
 AC_DEFINE_UNQUOTED(PATH_TO_RPCINFO,"$PATH_TO_RPCINFO")
 
 AC_PATH_PROG(PATH_TO_NTPDATE,ntpdate)
-AC_PATH_PROG(PATH_TO_NTPDC,ntpdc)
+AC_PATH_PROGS(PATH_TO_NTPDC,ntpdc xntpdc)
 if (test -x "$PATH_TO_NTPDATE" || test -x "$PATH_TO_NTPDC")
 then
 	AC_DEFINE_UNQUOTED(PATH_TO_NTPDC,"$PATH_TO_NTPDC")
--- plugins-scripts/check_flexlm.pl.orig	Tue May  7 01:35:49 2002
+++ plugins-scripts/check_flexlm.pl	Tue Jun  4 20:56:08 2002
@@ -66,7 +66,11 @@
 };
 alarm($TIMEOUT);
 
-my $lmstat = "/opt/lic/sw/cadadm/default/bin/lmstat";
+my $lmstat = $utils::PATH_TO_LMSTAT;
+unless (-x $lmstat) {
+  print "Cannot find \"$lmstat\"\n";
+  exit $ERRORS{'UNKNOWN'};
+}
 
 ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
 my $licfile = $1 if ($opt_F =~ /^(.*)$/);
--- plugins-scripts/check_log.sh.orig	Thu Feb 28 01:43:00 2002
+++ plugins-scripts/check_log.sh	Tue Jun  4 20:56:08 2002
@@ -62,10 +62,10 @@
 
 ECHO="/bin/echo"
 GREP="/bin/grep"
-DIFF="/bin/diff"
 TAIL="/bin/tail"
-CAT="/bin/cat"
-RM="/bin/rm"
+LS="/bin/ls"
+NAWK="/bin/nawk"
+HEAD="/bin/head"
 
 PROGNAME=`/bin/basename $0`
 PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
@@ -74,7 +74,7 @@
 . $PROGPATH/utils.sh
 
 print_usage() {
-	echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
+	echo "Usage: $PROGNAME -F logfile -O oldlog -q query -T tailcmd"
 	echo "Usage: $PROGNAME --help"
 	echo "Usage: $PROGNAME --version"
 }
@@ -153,6 +153,10 @@
 			exitstatus=$2
 			shift
 			;;
+		-T|--tailcmd)
+			TAIL=$2
+			shift
+			;;
 		*)
 			echo "Unknown argument: $1"
 			print_usage
@@ -164,7 +168,7 @@
 
 # If the source log file doesn't exist, exit
 
-if [ ! -e $logfile ]; then
+if [ ! -f $logfile ]; then
 	$ECHO "Log check error: Log file $logfile does not exist!\n"
 	exit 2
 fi
@@ -173,42 +177,42 @@
 # we're running this test, so copy the original log file over to
 # the old diff file and exit
 
-if [ ! -e $oldlog ]; then
-	$CAT $logfile > $oldlog
-	$ECHO "Log check data initialized...\n"
-	exit 0
-fi
+umask 066
+#if [ "$oldlog" != /dev/null -a ! -f $oldlog ]; then
+#	$LS -lidL $logfile > $oldlog
+#	$ECHO "Log check data initialized...\n"
+#	exit $STATE_OK
+#fi
 
 # The old log file exists, so compare it to the original log now
-
-# The temporary file that the script should use while
-# processing the log file.
-if [-x /bin/mktemp]; then
-	tempdiff="/bin/mktemp /tmp/check_log.XXXXXXXXXX"
+#     93593 -rw-r--r--   1 root     other     109889 May 29 14:45
/var/adm/messages
+set -- `$LS -lidL $logfile`
+inum=$1; perm=$2; nlinks=$3; uid=$4; gid=$5; size=$6; date="$7 $8 $9"
+if [ $oldlog = "/dev/null" -o ! -f $oldlog ] ; then
+	oinum=$inum; osize=0
 else
-	tempdiff="/tmp/check_log.`/bin/date '+%H%M%S'`"
-  /bin/touch $tempdiff
-	chmod 600 $tempdiff
+	set -- `$HEAD -1 $oldlog`
+	oinum=$1; operm=$2; onlinks=$3; ouid=$4; ogid=$5; osize=$6;
odate="$7 $8 $9"
 fi
 
-$DIFF $logfile $oldlog > $tempdiff
-
-# Count the number of matching log entries we have
-count=`$GREP -c "$query" $tempdiff`
-
-# Get the last matching entry in the diff file
-lastentry=`$GREP "$query" $tempdiff | $TAIL --lines=1`
-
-$RM -f $tempdiff
-$CAT $logfile > $oldlog
-
-if [ "$count" = "0" ]; then # no matches, exit with no error
-	$ECHO "Log check ok - 0 pattern matches found\n"
-	exitstatus=0
-else # Print total matche count and the last entry we found
-	$ECHO "($count) $lastentry"
+$LS -lidL $logfile > $oldlog
+if [ "$inum" != "$oinum" -o "$size" -lt "$osize" ]; then
+	# Re-initialize
+	osize=0
 fi
 
-exit exitstatus
-
-
+$TAIL +${osize}c $logfile | $NAWK '
+# Cannot handle "/"s in $query
+# /'"$query"'/ { count++; lastentry = $0 }
+# Works, but requires nawk
+{ if (match($0, "'"$query"'")) { count++; lastentry = $0; } }
+END {
+    if (count == 0) {
+	print "Log check ok - 0 pattern matches found";
+	exit 0;
+    } else {
+	print "(" count ") " lastentry;
+	exit '$exitstatus';
+    }
+}'
+exit $?
--- plugins-scripts/check_ntp.pl.orig	Sun May 26 22:10:07 2002
+++ plugins-scripts/check_ntp.pl	Tue Jun  4 20:56:08 2002
@@ -119,6 +119,7 @@
 my $dispersion_error = $ERRORS{'UNKNOWN'};
 
 my $key = undef;
+my $have_ntpdc;
 
 # Just in case of problems, let's not hang Nagios
 $SIG{'ALRM'} = sub {
@@ -176,22 +177,26 @@
 ### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3)
 ###
 
-if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) {
-	while (<NTPDC>) {
-		print $_ if ($verbose);
-		if
(/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\
s+([-0-9.]+)\s+([-0-9.]+)/) {
-			if ($8>15) {
-				print "Dispersion = $8 \n" if ($verbose);
-				$dispersion_error = $ERRORS{'CRITICAL'};
-			} elsif ($8>5 &&
$dispersion_error<$ERRORS{'CRITICAL'}) {
-				print "Dispersion = $8 \n" if ($verbose);
-				$dispersion_error = $ERRORS{'WARNING'};
-			} else {
-				$dispersion_error = $ERRORS{'OK'};
+$have_ntpdc = 0;
+if ($utils::PATH_TO_NTPDC && -x $utils::PATH_TO_NTPDC) {
+	$have_ntpdc = 1;
+	if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) {
+		while (<NTPDC>) {
+			print $_ if ($verbose);
+			if
(/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\
s+([-0-9.]+)\s+([-0-9.]+)/) {
+				if ($8>15) {
+					print "Dispersion = $8 \n" if
($verbose);
+					$dispersion_error =
$ERRORS{'CRITICAL'};
+				} elsif ($8>5 &&
$dispersion_error<$ERRORS{'CRITICAL'}) {
+					print "Dispersion = $8 \n" if
($verbose);
+					$dispersion_error =
$ERRORS{'WARNING'};
+				} else {
+					$dispersion_error = $ERRORS{'OK'};
+				}
 			}
 		}
+		close NTPDC;
 	}
-	close NTPDC;
 }
 
 
@@ -205,7 +210,7 @@
 		$answer = "Server error and time difference $offset seconds
greater than +/- $warning sec\n";
 	}
 
-} elsif ($dispersion_error != $ERRORS{'OK'}) {
+} elsif ($have_ntpdc && $dispersion_error != $ERRORS{'OK'}) {
 	$state = $dispersion_error;
 	$answer = "Dispersion too high\n";
 	if (defined($offset) && abs($offset) > $critical) {
--- plugins-scripts/check_oracle.sh.orig	Thu Feb 28 01:43:00 2002
+++ plugins-scripts/check_oracle.sh	Tue Jun  4 20:56:08 2002
@@ -36,6 +36,7 @@
   echo "Usage:"
   echo "  $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
   echo "  $PROGNAME --db <ORACLE_SID>"
+  echo "  $PROGNAME --oranames <Hostname>"
   echo "  $PROGNAME --help"
   echo "  $PROGNAME --version"
 }
@@ -52,13 +53,15 @@
   echo "--db=SID"
   echo "   Check local database (search /bin/ps for PMON process and check"
 	echo "   filesystem for sgadefORACLE_SID.dbf"
+  echo "--oranames=Hostname"
+  echo "   Check remote Oracle Names server"
   echo "--help"
 	echo "   Print this help screen"
   echo "--version"
 	echo "   Print version and license information"
 	echo ""
-  echo "If the plugin doesn't work, check that the $ORACLE_HOME
environment"
-	echo "variable is set, that $ORACLE_HOME/bin is in your PATH, and
the"
+  echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
+	echo "variable is set, that ORACLE_HOME/bin is in your PATH, and
the"
   echo "tnsnames.ora file is locatable and is properly configured."
   echo ""
   echo "When checking Local Database status your ORACLE_SID is case
sensitive."
@@ -78,27 +81,76 @@
     ;;
 esac
 
+# Hunt down a reasonable ORACLE_HOME
+if [ -z "$ORACLE_HOME" ] ; then
+	# Adjust to taste
+	for oratab in /var/opt/oracle/oratab /etc/oratab
+	do
+	[ ! -f $oratab ] && continue
+	ORACLE_HOME=`IFS=:
+		while read SID ORACLE_HOME junk;
+		do
+			if [ "$SID" = "$2" ] ; then
+				echo $ORACLE_HOME;
+				exit;
+			fi;
+		done < $oratab`
+	[ -n "$ORACLE_HOME" ] && break
+	done
+fi
+# Last resort
+[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] &&
ORACLE_HOME=$PROGPATH/oracle
+
+if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
+	echo "Cannot determine ORACLE_HOME for sid $2"
+	exit $STATE_UNKNOWN
+fi
+PATH=$PATH:$ORACLE_HOME/bin
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
+export ORACLE_HOME PATH LD_LIBRARY_PATH
+
 case "$cmd" in
 --tns)
-    export tnschk=` tnsping $2`
-    export tnschk2=` echo  $tnschk | grep -c OK`
-    export tnschk3=` echo $tnschk | cut -d\( -f7 | sed y/\)/" "/`
+    tnschk=` tnsping $2`
+    tnschk2=` echo  $tnschk | grep -c OK`
     if [ ${tnschk2} -eq 1 ] ; then 
+	tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
 	echo "OK - reply time ${tnschk3} from $2"
-	exit 0
+	exit $STATE_OK
     else
 	echo "No TNS Listener on $2"
 	exit $STATE_CRITICAL
     fi
     ;;
+--oranames)
+    namesctl status $2 | awk '
+    /Server has been running for:/ {
+	msg = "OK: Up"
+	for (i = 6; i <= NF; i++) {
+	    msg = msg " " $i
+	}
+	status = '$STATE_OK'
+    }
+    /error/ {
+	msg = "CRITICAL: " $0
+	status = '$STATE_CRITICAL'
+    }
+    END {
+	print msg
+	exit status
+    }'
+    ;;
 --db)
-    export pmonchk=`ps -ef | grep -v grep | grep ${2} | grep -c pmon`
-    if [ -e $ORACLE_HOME/dbs/sga*${2}* ] ; then
-	if [ ${pmonchk} -eq 1 ] ; then
-    export utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
-	    echo "${2} OK - running since ${utime}"
-	    exit $STATE_OK
-	fi
+    pmonchk=`ps -ef | grep -v grep | grep ${2} | grep -c pmon`
+    if [ ${pmonchk} -ge 1 ] ; then
+	echo "${2} OK - ${pmonchk} PMON process(es) running"
+	exit $STATE_OK
+    #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
+	#if [ ${pmonchk} -eq 1 ] ; then
+    #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
+	    #echo "${2} OK - running since ${utime}"
+	    #exit $STATE_OK
+	#fi
     else
 	echo "${2} Database is DOWN"
 	exit $STATE_CRITICAL
--- plugins-scripts/subst.in.orig	Mon Mar 18 00:15:04 2002
+++ plugins-scripts/subst.in	Tue Jun  4 20:56:09 2002
@@ -29,7 +29,7 @@
 		return "\"" led3 "/libexec\" " ;
 	
 	}
-	return led1;
+	return "\"" led1 "\"";
 }
 
 BEGIN {
--- plugins-scripts/utils.sh.in.orig	Thu Feb 28 01:43:00 2002
+++ plugins-scripts/utils.sh.in	Tue Jun  4 20:56:09 2002
@@ -1,10 +1,10 @@
 #! /bin/sh
 
-STATE_DEPENDENT=-2
-STATE_UNKNOWN=-1
 STATE_OK=0
 STATE_WARNING=1
 STATE_CRITICAL=2
+STATE_UNKNOWN=3
+STATE_DEPENDENT=4
 
 if test -x /usr/bin/printf; then
 	ECHO=/usr/bin/printf
@@ -19,4 +19,4 @@
 
 support() {
 	$ECHO "@SUPPORT@" | /bin/sed -e 's/\n/ /g'
-}
\ No newline at end of file
+}
--- plugins/check_disk.c.orig	Wed Jun  5 11:18:38 2002
+++ plugins/check_disk.c	Wed Jun  5 12:23:56 2002
@@ -51,6 +51,7 @@
 float c_dfp = -1.0;
 char *path = NULL;
 int verbose = FALSE;
+int display_mntp = FALSE;
 
 int
 main (int argc, char **argv)
@@ -64,6 +65,7 @@
 	char *command_line = NULL;
 	char input_buffer[MAX_INPUT_BUFFER] = "";
 	char file_system[MAX_INPUT_BUFFER] = "";
+	char mntp[MAX_INPUT_BUFFER] = "";
 	char outbuf[MAX_INPUT_BUFFER] = "";
 	char *output = NULL;
 
@@ -92,15 +94,15 @@
 			continue;
 
 		if (sscanf
-				(input_buffer, "%s %d %d %d %d%%",
file_system, &total_disk,
-				 &used_disk, &free_disk, &usp) == 5
-				|| sscanf (input_buffer, "%s %*s %d %d %d
%d%%", file_system,
-
&total_disk, &used_disk, &free_disk, &usp) == 5) {
+				(input_buffer, "%s %d %d %d %d%% %s",
file_system, &total_disk,
+				 &used_disk, &free_disk, &usp, &mntp) == 6
+				|| sscanf (input_buffer, "%s %*s %d %d %d
%d%% %s", file_system,
+
&total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) {
 			result = max (result, check_disk (usp, free_disk));
 			len =
 				snprintf (outbuf, MAX_INPUT_BUFFER - 1,
 									"
[%d kB (%d%%) free on %s]", free_disk, 100 - usp,
-
file_system);
+
display_mntp ? mntp : file_system);
 			outbuf[len] = 0;
 			output = strscat (output, outbuf);
 		}
@@ -121,8 +123,8 @@
 	if (spclose (child_process))
 		result = max (result, STATE_WARNING);
 
-	else if (usp < 0)
-		printf ("Disk %s not mounted or nonexistant\n", argv[3]);
+	if (usp < 0)
+		printf ("Disk \"%s\" not mounted or nonexistant\n", path);
 	else if (result == STATE_UNKNOWN)
 		printf ("Unable to read output\n%s\n%s\n", command_line,
input_buffer);
 	else
@@ -183,6 +185,7 @@
 		{"verbose", no_argument, 0, 'v'},
 		{"version", no_argument, 0, 'V'},
 		{"help", no_argument, 0, 'h'},
+		{"mountpoint", no_argument, 0, 'm'},
 		{0, 0, 0, 0}
 	};
 #endif
@@ -190,9 +193,9 @@
 	while (1) {
 #ifdef HAVE_GETOPT_H
 		c =
-			getopt_long (argc, argv, "+?Vhvt:c:w:p:",
long_options, &option_index);
+			getopt_long (argc, argv, "+?Vhvt:c:w:p:m",
long_options, &option_index);
 #else
-		c = getopt (argc, argv, "+?Vhvt:c:w:p:");
+		c = getopt (argc, argv, "+?Vhvt:c:w:p:m");
 #endif
 
 		i++;
@@ -255,6 +258,9 @@
 		case 'v':
/* verbose */
 			verbose = TRUE;
 			break;
+		case 'm':
/* display mountpoint */
+			display_mntp = TRUE;
+			break;
 		case 'V':
/* version */
 			print_revision (my_basename (argv[0]), "$Revision:
1.1.1.1 $");
 			exit (STATE_OK);
@@ -335,6 +341,8 @@
 		 "   Exit with CRITCAL status if more than PERCENT of disk
space is free\n"
 		 " -p, --path=PATH, --partition=PARTTION\n"
 		 "    Path or partition (checks all mounted partitions if
unspecified)\n"
+		 " -m, --mountpoint\n"
+		 "    Display the mountpoint instead of the partition\n"
 		 " -v, --verbose\n"
 		 "    Show details for command-line debugging (do not use
with nagios server)\n"
 		 " -h, --help\n"
@@ -347,7 +355,7 @@
 print_usage (void)
 {
 	printf
-		("Usage: %s -w limit -c limit [-p path] [-t timeout]
[--verbose]\n"
+		("Usage: %s -w limit -c limit [-p path] [-t timeout] [-m]
[--verbose]\n"
 		 "       %s (-h|--help)\n"
 		 "       %s (-V|--version)\n", PROGNAME, PROGNAME,
PROGNAME);
 }






More information about the Devel mailing list