Просмотр исходного кода

Merge branch 'master' into maint

abrist 12 лет назад
Родитель
Сommit
6cb3335edb

+ 5 - 1
NEWS

@@ -5,7 +5,7 @@ This file documents the major additions and syntax changes between releases.
 	Added performance data to check_mysql_query (sreinhardt)
 	New check_file_age option -i/--ignore-missing which returns OK if file is missing (waja)
 	Added performance data to check_nt UPTIME -l seconds|minutes|hours|days (abrist)
-	
+
 	FIXES
 	Don't let e.g. check_http's -C option reset SSL version if e.g. -S 1 -C 5 is specified
 	check_ide_smart now defaults to nagios-compatible output (sreinhardt)
@@ -17,6 +17,10 @@ This file documents the major additions and syntax changes between releases.
 	Fixed check_ide_smart attribute comparison (waja)
 	Fixed bug in check_ntp_time average time calculation (larsi)
 
+	WARNINGS
+	check_procs now ignores its parent process to avoid unexpected results when invoked via certain shells
+	utils.sh no longer defines ECHO
+
 1.5 2nd October 2013
 	ENHANCEMENTS
 	New check_dbi plugin for checking an (SQL) database using DBI

+ 1 - 1
configure.in

@@ -6,7 +6,7 @@ AC_CONFIG_FILES([gl/Makefile
 	nagios-plugins.spec])
 AC_CONFIG_AUX_DIR(build-aux)
 AM_INIT_AUTOMAKE([1.8.3])
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADERS([config.h])
 AC_CANONICAL_HOST
 
 RELEASE=1

+ 1 - 6
doc/developer-guidelines.sgml

@@ -678,11 +678,6 @@ To run a test, from the top level directory, run "make test". This will run
 all the current tests and report an overall success rate.
 </para>
 
-<para>
-See the <ulink url="http://tinderbox.opsera.com">Nagios Plugins Tinderbox server</ulink>
-for the daily test results.
-</para>
-
 <section><title>Test cases for plugins</title>
 <para>These use perl's Test::More. To do a one time test, run "cd plugins && perl t/check_disk.t".
 </para>
@@ -699,7 +694,7 @@ This runs the test in a summary format.
 
 <para>
 For a good and amusing tutorial on using Test::More, see this 
-<ulink url="http://search.cpan.org/~mschwern/Test-Simple-0.62/lib/Test/Tutorial.pod">
+<ulink url="http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod">
 link</ulink>
 </para>
 

+ 5 - 6
plugins-scripts/check_log.sh

@@ -60,7 +60,6 @@
 # TV: removed PATH restriction. Need to think more about what this means overall
 #PATH=""
 
-ECHO="/bin/echo"
 GREP="/bin/egrep"
 DIFF="/bin/diff"
 TAIL="/bin/tail"
@@ -167,10 +166,10 @@ done
 # If the source log file doesn't exist, exit
 
 if [ ! -e $logfile ]; then
-    $ECHO "Log check error: Log file $logfile does not exist!\n"
+    echo "Log check error: Log file $logfile does not exist!"
     exit $STATE_UNKNOWN
 elif [ ! -r $logfile ] ; then
-    $ECHO "Log check error: Log file $logfile is not readable!\n"
+    echo "Log check error: Log file $logfile is not readable!"
     exit $STATE_UNKNOWN
 fi
 
@@ -180,7 +179,7 @@ fi
 
 if [ ! -e $oldlog ]; then
     $CAT $logfile > $oldlog
-    $ECHO "Log check data initialized...\n"
+    echo "Log check data initialized..."
     exit $STATE_OK
 fi
 
@@ -209,10 +208,10 @@ $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"
+    echo "Log check ok - 0 pattern matches found"
     exitstatus=$STATE_OK
 else # Print total matche count and the last entry we found
-    $ECHO "($count) $lastentry"
+    echo "($count) $lastentry"
     exitstatus=$STATE_CRITICAL
 fi
 

+ 2 - 8
plugins-scripts/utils.sh.in

@@ -6,19 +6,13 @@ STATE_CRITICAL=2
 STATE_UNKNOWN=3
 STATE_DEPENDENT=4
 
-if test -x /usr/bin/printf; then
-	ECHO=/usr/bin/printf
-else
-	ECHO=echo
-fi
-
 print_revision() {
 	echo "$1 v$2 (@PACKAGE@ @VERSION@)"
-	$ECHO "@WARRANTY@" | sed -e 's/\n/ /g'
+	printf '%b' "@WARRANTY@"
 }
 
 support() {
-	$ECHO "@SUPPORT@" | sed -e 's/\n/ /g'
+	printf '%b' "@SUPPORT@"
 }
 
 #

+ 8 - 0
plugins/check_procs.c

@@ -123,6 +123,7 @@ main (int argc, char **argv)
 	char *procprog;
 
 	pid_t mypid = 0;
+	pid_t myppid = 0;
 	struct stat statbuf;
 	dev_t mydev = 0;
 	ino_t myino = 0;
@@ -172,6 +173,7 @@ main (int argc, char **argv)
 
 	/* find ourself */
 	mypid = getpid();
+	myppid = getppid();
 	if (usepid || stat_exe(mypid, &statbuf) == -1) {
 		/* usepid might have been set by -T */
 		usepid = 1;
@@ -241,6 +243,12 @@ main (int argc, char **argv)
 					 printf("not considering - is myself or gone\n");
 				continue;
 			}
+			/* Ignore parent*/
+			else if (myppid == procpid) {
+				if (verbose >= 3)
+					 printf("not considering - is parent\n");
+				continue;
+			}
 
 			/* filter kernel threads (childs of KTHREAD_PARENT)*/
 			/* TODO adapt for other OSes than GNU/Linux

+ 6 - 1
plugins/t/check_procs.t

@@ -13,7 +13,7 @@ my $t;
 if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") {
 	plan skip_all => "Ignoring tests on solaris because of pst3";
 } else {
-	plan tests => 12;
+	plan tests => 14;
 }
 
 my $result;
@@ -26,6 +26,11 @@ $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
 is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
 like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
 
+if(fork() == 0) { exec("sleep 7"); } # fork a test process
+$result = NPTest->testCmd( "./check_procs -a 'sleep 7'" );
+is( $result->return_code, 0, "Parent process is ignored" );
+like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );
+
 $result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
 is( $result->return_code, 1, "Checking warning if processes > 0" );
 like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );