[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1937] nagiosplug/trunk
tonvoon at users.sourceforge.net
tonvoon at users.sourceforge.net
Thu Feb 28 17:21:59 CET 2008
Revision: 1937
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1937&view=rev
Author: tonvoon
Date: 2008-02-28 08:21:59 -0800 (Thu, 28 Feb 2008)
Log Message:
-----------
Reverted check_procs for solaris back to using pst3 due to truncation
for argument fields using other methods
Modified Paths:
--------------
nagiosplug/trunk/NEWS
nagiosplug/trunk/configure.in
nagiosplug/trunk/plugins/check_procs.c
nagiosplug/trunk/plugins/t/check_procs.t
nagiosplug/trunk/plugins-root/Makefile.am
nagiosplug/trunk/plugins-root/pst3.c
Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/NEWS 2008-02-28 16:21:59 UTC (rev 1937)
@@ -12,6 +12,8 @@
check_ntp_peer now checks for the LI_ALARM flag
Sync to latest Gnulib (includes new floorf function)
check_pgsql now successfully builds with postgres lib v8.3 (Bug #1878972)
+ check_procs now accepts --ereg-argument-array for a regular expression match to the argument array
+ Reverted back to using pst3 for Solaris systems. Fixed issues re: -m64 needed to compile on 64bit systems
1.4.11 13th December 2007
Fixed check_http regression in 1.4.10 where following redirects to
Modified: nagiosplug/trunk/configure.in
===================================================================
--- nagiosplug/trunk/configure.in 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/configure.in 2008-02-28 16:21:59 UTC (rev 1937)
@@ -512,16 +512,49 @@
ac_cv_ps_cols="$PS_COLS"
AC_MSG_RESULT([(command-line) $ac_cv_ps_command])
+dnl Now using the pst3/kmem hack for solaris systems to avoid truncation
+elif test "$ac_cv_uname_s" = "SunOS"; then
+ #
+ # this is a very, very ugly hack, to hardcode the location for plugins
+ #
+ if test "$libexecdir" = '${exec_prefix}/libexec'; then
+ if test "$exec_prefix" = "NONE"; then
+ if test "$prefix" = "NONE"; then
+ pst3="$ac_default_prefix/libexec/pst3"
+ else
+ pst3="$prefix/libexec/pst3"
+ fi
+ else
+ pst3="$exec_prefix/libexec/pst3"
+ fi
+ else
+ pst3="$libexecdir/pst3"
+ fi
+ ac_cv_ps_command="$pst3"
+ ac_cv_ps_format="%s %d %d %d %d %d %f %s %n"
+ ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]"
+ ac_cv_ps_cols=9
+ AC_MSG_RESULT([using nagios-plugins internal ps command (pst3) for solaris])
+ if test `isainfo -b` = 64 ; then
+ PST3CFLAGS="-m64"
+ AC_SUBST(PST3CFLAGS)
+ AC_MSG_NOTICE([using 64bit pst3])
+ else
+ AC_MSG_NOTICE([using 32bit pst3])
+ fi
+ EXTRAS_ROOT="$EXTRAS_ROOT pst3"
+
+dnl Removing this for the moment - Ton
dnl Using /usr/ucb/ps on Solaris systems, to avoid truncation
dnl Limitation that command name is not available
-elif test "$ac_cv_uname_s" = "SunOS" && /usr/ucb/ps -alxwwn 2>/dev/null | \
- egrep -i ["^ *F +UID +PID +PPID +%C +PRI +NI +SZ +RSS +WCHAN +S +TT +TIME +COMMAND"] > /dev/null
-then
- ac_cv_ps_varlist="[&procuid,&procpid,&procppid,&procpcpu,&procvsz,&procrss,procstat,&pos]"
- ac_cv_ps_command="/usr/ucb/ps -alxwwn"
- ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT]%*s %*s %n"]
- ac_cv_ps_cols=8
- AC_MSG_RESULT([$ac_cv_ps_command])
+dnl elif test "$ac_cv_uname_s" = "SunOS" && /usr/ucb/ps -alxwwn 2>/dev/null | \
+dnl egrep -i ["^ *F +UID +PID +PPID +%C +PRI +NI +SZ +RSS +WCHAN +S +TT +TIME +COMMAND"] > /dev/null
+dnl then
+dnl ac_cv_ps_varlist="[&procuid,&procpid,&procppid,&procpcpu,&procvsz,&procrss,procstat,&pos]"
+dnl ac_cv_ps_command="/usr/ucb/ps -alxwwn"
+dnl ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT]%*s %*s %n"]
+dnl ac_cv_ps_cols=8
+dnl AC_MSG_RESULT([$ac_cv_ps_command])
dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo.
dnl so test for this first...
Modified: nagiosplug/trunk/plugins/check_procs.c
===================================================================
--- nagiosplug/trunk/plugins/check_procs.c 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/plugins/check_procs.c 2008-02-28 16:21:59 UTC (rev 1937)
@@ -43,6 +43,7 @@
#include "common.h"
#include "popen.h"
#include "utils.h"
+#include "regex.h"
#include <pwd.h>
@@ -69,6 +70,7 @@
#define RSS 128
#define PCPU 256
#define ELAPSED 512
+#define EREG_ARGS 1024
/* Different metrics */
char *metric_name;
enum metric {
@@ -89,6 +91,7 @@
char *statopts;
char *prog;
char *args;
+regex_t re_args;
char *fmt;
char *fails;
char tmp[MAX_INPUT_BUFFER];
@@ -211,6 +214,8 @@
resultsum |= STAT;
if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL))
resultsum |= ARGS;
+ if ((options & EREG_ARGS) && procargs && (regexec(&re_args, procargs, (size_t) 0, NULL, 0) == 0))
+ resultsum |= EREG_ARGS;
if ((options & PROG) && procprog && (strcmp (prog, procprog) == 0))
resultsum |= PROG;
if ((options & PPID) && (procppid == ppid))
@@ -231,6 +236,12 @@
continue;
procs++;
+ if (verbose >= 2) {
+ printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
+ procuid, procvsz, procrss,
+ procpid, procppid, procpcpu, procstat,
+ procetime, procprog, procargs);
+ }
if (metric == METRIC_VSZ)
i = check_thresholds (procvsz);
@@ -326,6 +337,9 @@
char *user;
struct passwd *pw;
int option = 0;
+ int err;
+ int cflags = REG_NOSUB | REG_EXTENDED;
+ char errbuf[MAX_INPUT_BUFFER];
static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
@@ -342,6 +356,7 @@
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
+ {"ereg-argument-array", required_argument, 0, CHAR_MAX+1},
{0, 0, 0, 0}
};
@@ -450,6 +465,15 @@
asprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args);
options |= ARGS;
break;
+ case CHAR_MAX+1:
+ err = regcomp(&re_args, optarg, cflags);
+ if (err != 0) {
+ regerror (err, &re_args, errbuf, MAX_INPUT_BUFFER);
+ die (STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
+ }
+ asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), optarg);
+ options |= EREG_ARGS;
+ break;
case 'r': /* RSS */
if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) {
asprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss);
@@ -716,6 +740,8 @@
printf (" %s\n", _("Only scan for processes with user name or ID indicated."));
printf (" %s\n", "-a, --argument-array=STRING");
printf (" %s\n", _("Only scan for processes with args that contain STRING."));
+ printf (" %s\n", "--ereg-argument-array=STRING");
+ printf (" %s\n", _("Only scan for processes with args that contain the regex STRING."));
printf (" %s\n", "-C, --command=COMMAND");
printf (" %s\n", _("Only scan for exact matches of COMMAND (without path)."));
Modified: nagiosplug/trunk/plugins/t/check_procs.t
===================================================================
--- nagiosplug/trunk/plugins/t/check_procs.t 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/plugins/t/check_procs.t 2008-02-28 16:21:59 UTC (rev 1937)
@@ -6,20 +6,40 @@
#
use strict;
-use Test;
+use Test::More;
use NPTest;
-use vars qw($tests);
-BEGIN {$tests = 12; plan tests => $tests}
-
my $t;
-$t += checkCmd( "./check_procs -w 100000 -c 100000", 0, '/^PROCS OK: [0-9]+ process(es)?$/' );
-$t += checkCmd( "./check_procs -w 100000 -c 100000 -s Z", 0, '/^PROCS OK: [0-9]+ process(es)? with /' );
-$t += checkCmd( "./check_procs -w 0 -c 10000000", 1, '/^PROCS WARNING: [0-9]+ process(es)?$/' );
-$t += checkCmd( "./check_procs -w 0 -c 0", 2, '/^PROCS CRITICAL: [0-9]+ process(es)?$/' );
-$t += checkCmd( "./check_procs -w 0 -c 0 -s S", 2, '/^PROCS CRITICAL: [0-9]+ process(es)? with /' );
-$t += checkCmd( "./check_procs -w 0 -c 10000000 -p 1", 1, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/' );
+if (`uname -s` eq "SunOS\n") {
+ plan skip_all => "Ignoring tests on solaris because of pst3";
+} else {
+ plan tests => 12;
+}
-exit(0) if defined($Test::Harness::VERSION);
-exit($tests - $t);
+my $result;
+
+$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
+is( $result->return_code, 0, "Checking less than 10000 processes" );
+like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" );
+
+$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" );
+
+$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)?$/', "Output correct" );
+
+$result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
+is( $result->return_code, 2, "Checking critical if processes > 0" );
+like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" );
+
+$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
+is( $result->return_code, 2, "Checking critical if sleeping processes" );
+like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" );
+
+$result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" );
+is( $result->return_code, 1, "Checking warning for processes by parentid = 1" );
+like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" );
+
Modified: nagiosplug/trunk/plugins-root/Makefile.am
===================================================================
--- nagiosplug/trunk/plugins-root/Makefile.am 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/plugins-root/Makefile.am 2008-02-28 16:21:59 UTC (rev 1937)
@@ -7,7 +7,7 @@
datadir = @datadir@
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
-LIBS = @LIBINTL@ @LIBS@ @SSLLIBS@
+LIBS = @LIBINTL@ @LIBS@
noinst_PROGRAMS = check_dhcp check_icmp @EXTRAS_ROOT@
@@ -68,6 +68,7 @@
# the actual targets
check_dhcp_LDADD = $(NETLIBS)
check_icmp_LDADD = $(NETLIBS) $(SOCKETLIBS)
+pst3_CFLAGS = @PST3CFLAGS@
pst3_LDADD = -lkvm
check_dhcp_DEPENDENCIES = check_dhcp.c $(NETOBJS) $(DEPLIBS)
Modified: nagiosplug/trunk/plugins-root/pst3.c
===================================================================
--- nagiosplug/trunk/plugins-root/pst3.c 2008-02-28 12:54:49 UTC (rev 1936)
+++ nagiosplug/trunk/plugins-root/pst3.c 2008-02-28 16:21:59 UTC (rev 1937)
@@ -187,9 +187,10 @@
thisProg = myArgv[0];
/* Display the ps columns (except for argv) */
- printf("%c %5d %5d %6lu %6lu %4.1f %s ",
+ printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ",
pPsInfo->pr_lwp.pr_sname,
(int)(pPsInfo->pr_euid),
+ (int)(pPsInfo->pr_pid),
(int)(pPsInfo->pr_ppid),
(unsigned long)(pPsInfo->pr_size),
(unsigned long)(pPsInfo->pr_rssize),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list