diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2008-02-28 16:21:59 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2008-02-28 16:21:59 (GMT) |
commit | 9f3d864fd3e47d4e728b196b1b6948a8a5e47e4e (patch) | |
tree | ffaf70a0a09e40cf706f1362a01450f76e845d18 | |
parent | f00e6a9676154eaac8aed140c49bde76e52d6cee (diff) | |
download | monitoring-plugins-9f3d864fd3e47d4e728b196b1b6948a8a5e47e4e.tar.gz |
Reverted check_procs for solaris back to using pst3 due to truncation
for argument fields using other methods
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1937 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | configure.in | 49 | ||||
-rw-r--r-- | plugins-root/Makefile.am | 3 | ||||
-rw-r--r-- | plugins-root/pst3.c | 3 | ||||
-rw-r--r-- | plugins/check_procs.c | 26 | ||||
-rw-r--r-- | plugins/t/check_procs.t | 44 |
6 files changed, 105 insertions, 22 deletions
@@ -12,6 +12,8 @@ This file documents the major additions and syntax changes between releases. | |||
12 | check_ntp_peer now checks for the LI_ALARM flag | 12 | check_ntp_peer now checks for the LI_ALARM flag |
13 | Sync to latest Gnulib (includes new floorf function) | 13 | Sync to latest Gnulib (includes new floorf function) |
14 | check_pgsql now successfully builds with postgres lib v8.3 (Bug #1878972) | 14 | check_pgsql now successfully builds with postgres lib v8.3 (Bug #1878972) |
15 | check_procs now accepts --ereg-argument-array for a regular expression match to the argument array | ||
16 | Reverted back to using pst3 for Solaris systems. Fixed issues re: -m64 needed to compile on 64bit systems | ||
15 | 17 | ||
16 | 1.4.11 13th December 2007 | 18 | 1.4.11 13th December 2007 |
17 | Fixed check_http regression in 1.4.10 where following redirects to | 19 | Fixed check_http regression in 1.4.10 where following redirects to |
diff --git a/configure.in b/configure.in index 341add8..6d94582 100644 --- a/configure.in +++ b/configure.in | |||
@@ -512,16 +512,49 @@ if test -n "$PS_COMMAND" && test -n "$PS_FORMAT" && test -n "$PS_COLS" && test - | |||
512 | ac_cv_ps_cols="$PS_COLS" | 512 | ac_cv_ps_cols="$PS_COLS" |
513 | AC_MSG_RESULT([(command-line) $ac_cv_ps_command]) | 513 | AC_MSG_RESULT([(command-line) $ac_cv_ps_command]) |
514 | 514 | ||
515 | dnl Now using the pst3/kmem hack for solaris systems to avoid truncation | ||
516 | elif test "$ac_cv_uname_s" = "SunOS"; then | ||
517 | # | ||
518 | # this is a very, very ugly hack, to hardcode the location for plugins | ||
519 | # | ||
520 | if test "$libexecdir" = '${exec_prefix}/libexec'; then | ||
521 | if test "$exec_prefix" = "NONE"; then | ||
522 | if test "$prefix" = "NONE"; then | ||
523 | pst3="$ac_default_prefix/libexec/pst3" | ||
524 | else | ||
525 | pst3="$prefix/libexec/pst3" | ||
526 | fi | ||
527 | else | ||
528 | pst3="$exec_prefix/libexec/pst3" | ||
529 | fi | ||
530 | else | ||
531 | pst3="$libexecdir/pst3" | ||
532 | fi | ||
533 | ac_cv_ps_command="$pst3" | ||
534 | ac_cv_ps_format="%s %d %d %d %d %d %f %s %n" | ||
535 | ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]" | ||
536 | ac_cv_ps_cols=9 | ||
537 | AC_MSG_RESULT([using nagios-plugins internal ps command (pst3) for solaris]) | ||
538 | if test `isainfo -b` = 64 ; then | ||
539 | PST3CFLAGS="-m64" | ||
540 | AC_SUBST(PST3CFLAGS) | ||
541 | AC_MSG_NOTICE([using 64bit pst3]) | ||
542 | else | ||
543 | AC_MSG_NOTICE([using 32bit pst3]) | ||
544 | fi | ||
545 | EXTRAS_ROOT="$EXTRAS_ROOT pst3" | ||
546 | |||
547 | dnl Removing this for the moment - Ton | ||
515 | dnl Using /usr/ucb/ps on Solaris systems, to avoid truncation | 548 | dnl Using /usr/ucb/ps on Solaris systems, to avoid truncation |
516 | dnl Limitation that command name is not available | 549 | dnl Limitation that command name is not available |
517 | elif test "$ac_cv_uname_s" = "SunOS" && /usr/ucb/ps -alxwwn 2>/dev/null | \ | 550 | dnl elif test "$ac_cv_uname_s" = "SunOS" && /usr/ucb/ps -alxwwn 2>/dev/null | \ |
518 | egrep -i ["^ *F +UID +PID +PPID +%C +PRI +NI +SZ +RSS +WCHAN +S +TT +TIME +COMMAND"] > /dev/null | 551 | dnl egrep -i ["^ *F +UID +PID +PPID +%C +PRI +NI +SZ +RSS +WCHAN +S +TT +TIME +COMMAND"] > /dev/null |
519 | then | 552 | dnl then |
520 | ac_cv_ps_varlist="[&procuid,&procpid,&procppid,&procpcpu,&procvsz,&procrss,procstat,&pos]" | 553 | dnl ac_cv_ps_varlist="[&procuid,&procpid,&procppid,&procpcpu,&procvsz,&procrss,procstat,&pos]" |
521 | ac_cv_ps_command="/usr/ucb/ps -alxwwn" | 554 | dnl ac_cv_ps_command="/usr/ucb/ps -alxwwn" |
522 | ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT]%*s %*s %n"] | 555 | dnl ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT]%*s %*s %n"] |
523 | ac_cv_ps_cols=8 | 556 | dnl ac_cv_ps_cols=8 |
524 | AC_MSG_RESULT([$ac_cv_ps_command]) | 557 | dnl AC_MSG_RESULT([$ac_cv_ps_command]) |
525 | 558 | ||
526 | dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo. | 559 | dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo. |
527 | dnl so test for this first... | 560 | dnl so test for this first... |
diff --git a/plugins-root/Makefile.am b/plugins-root/Makefile.am index e61ebc7..3e6ee43 100644 --- a/plugins-root/Makefile.am +++ b/plugins-root/Makefile.am | |||
@@ -7,7 +7,7 @@ INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$( | |||
7 | datadir = @datadir@ | 7 | datadir = @datadir@ |
8 | localedir = $(datadir)/locale | 8 | localedir = $(datadir)/locale |
9 | DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ | 9 | DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ |
10 | LIBS = @LIBINTL@ @LIBS@ @SSLLIBS@ | 10 | LIBS = @LIBINTL@ @LIBS@ |
11 | 11 | ||
12 | noinst_PROGRAMS = check_dhcp check_icmp @EXTRAS_ROOT@ | 12 | noinst_PROGRAMS = check_dhcp check_icmp @EXTRAS_ROOT@ |
13 | 13 | ||
@@ -68,6 +68,7 @@ install-exec-local: $(noinst_PROGRAMS) | |||
68 | # the actual targets | 68 | # the actual targets |
69 | check_dhcp_LDADD = $(NETLIBS) | 69 | check_dhcp_LDADD = $(NETLIBS) |
70 | check_icmp_LDADD = $(NETLIBS) $(SOCKETLIBS) | 70 | check_icmp_LDADD = $(NETLIBS) $(SOCKETLIBS) |
71 | pst3_CFLAGS = @PST3CFLAGS@ | ||
71 | pst3_LDADD = -lkvm | 72 | pst3_LDADD = -lkvm |
72 | 73 | ||
73 | check_dhcp_DEPENDENCIES = check_dhcp.c $(NETOBJS) $(DEPLIBS) | 74 | check_dhcp_DEPENDENCIES = check_dhcp.c $(NETOBJS) $(DEPLIBS) |
diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c index bf4b40d..8734006 100644 --- a/plugins-root/pst3.c +++ b/plugins-root/pst3.c | |||
@@ -187,9 +187,10 @@ static int HandlePsInfo (char *szPath, psinfo_t *pPsInfo) | |||
187 | thisProg = myArgv[0]; | 187 | thisProg = myArgv[0]; |
188 | 188 | ||
189 | /* Display the ps columns (except for argv) */ | 189 | /* Display the ps columns (except for argv) */ |
190 | printf("%c %5d %5d %6lu %6lu %4.1f %s ", | 190 | printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ", |
191 | pPsInfo->pr_lwp.pr_sname, | 191 | pPsInfo->pr_lwp.pr_sname, |
192 | (int)(pPsInfo->pr_euid), | 192 | (int)(pPsInfo->pr_euid), |
193 | (int)(pPsInfo->pr_pid), | ||
193 | (int)(pPsInfo->pr_ppid), | 194 | (int)(pPsInfo->pr_ppid), |
194 | (unsigned long)(pPsInfo->pr_size), | 195 | (unsigned long)(pPsInfo->pr_size), |
195 | (unsigned long)(pPsInfo->pr_rssize), | 196 | (unsigned long)(pPsInfo->pr_rssize), |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 690b855..7dae845 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -43,6 +43,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
43 | #include "common.h" | 43 | #include "common.h" |
44 | #include "popen.h" | 44 | #include "popen.h" |
45 | #include "utils.h" | 45 | #include "utils.h" |
46 | #include "regex.h" | ||
46 | 47 | ||
47 | #include <pwd.h> | 48 | #include <pwd.h> |
48 | 49 | ||
@@ -69,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */ | |||
69 | #define RSS 128 | 70 | #define RSS 128 |
70 | #define PCPU 256 | 71 | #define PCPU 256 |
71 | #define ELAPSED 512 | 72 | #define ELAPSED 512 |
73 | #define EREG_ARGS 1024 | ||
72 | /* Different metrics */ | 74 | /* Different metrics */ |
73 | char *metric_name; | 75 | char *metric_name; |
74 | enum metric { | 76 | enum metric { |
@@ -89,6 +91,7 @@ float pcpu; | |||
89 | char *statopts; | 91 | char *statopts; |
90 | char *prog; | 92 | char *prog; |
91 | char *args; | 93 | char *args; |
94 | regex_t re_args; | ||
92 | char *fmt; | 95 | char *fmt; |
93 | char *fails; | 96 | char *fails; |
94 | char tmp[MAX_INPUT_BUFFER]; | 97 | char tmp[MAX_INPUT_BUFFER]; |
@@ -211,6 +214,8 @@ main (int argc, char **argv) | |||
211 | resultsum |= STAT; | 214 | resultsum |= STAT; |
212 | if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) | 215 | if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) |
213 | resultsum |= ARGS; | 216 | resultsum |= ARGS; |
217 | if ((options & EREG_ARGS) && procargs && (regexec(&re_args, procargs, (size_t) 0, NULL, 0) == 0)) | ||
218 | resultsum |= EREG_ARGS; | ||
214 | if ((options & PROG) && procprog && (strcmp (prog, procprog) == 0)) | 219 | if ((options & PROG) && procprog && (strcmp (prog, procprog) == 0)) |
215 | resultsum |= PROG; | 220 | resultsum |= PROG; |
216 | if ((options & PPID) && (procppid == ppid)) | 221 | if ((options & PPID) && (procppid == ppid)) |
@@ -231,6 +236,12 @@ main (int argc, char **argv) | |||
231 | continue; | 236 | continue; |
232 | 237 | ||
233 | procs++; | 238 | procs++; |
239 | if (verbose >= 2) { | ||
240 | printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", | ||
241 | procuid, procvsz, procrss, | ||
242 | procpid, procppid, procpcpu, procstat, | ||
243 | procetime, procprog, procargs); | ||
244 | } | ||
234 | 245 | ||
235 | if (metric == METRIC_VSZ) | 246 | if (metric == METRIC_VSZ) |
236 | i = check_thresholds (procvsz); | 247 | i = check_thresholds (procvsz); |
@@ -326,6 +337,9 @@ process_arguments (int argc, char **argv) | |||
326 | char *user; | 337 | char *user; |
327 | struct passwd *pw; | 338 | struct passwd *pw; |
328 | int option = 0; | 339 | int option = 0; |
340 | int err; | ||
341 | int cflags = REG_NOSUB | REG_EXTENDED; | ||
342 | char errbuf[MAX_INPUT_BUFFER]; | ||
329 | static struct option longopts[] = { | 343 | static struct option longopts[] = { |
330 | {"warning", required_argument, 0, 'w'}, | 344 | {"warning", required_argument, 0, 'w'}, |
331 | {"critical", required_argument, 0, 'c'}, | 345 | {"critical", required_argument, 0, 'c'}, |
@@ -342,6 +356,7 @@ process_arguments (int argc, char **argv) | |||
342 | {"help", no_argument, 0, 'h'}, | 356 | {"help", no_argument, 0, 'h'}, |
343 | {"version", no_argument, 0, 'V'}, | 357 | {"version", no_argument, 0, 'V'}, |
344 | {"verbose", no_argument, 0, 'v'}, | 358 | {"verbose", no_argument, 0, 'v'}, |
359 | {"ereg-argument-array", required_argument, 0, CHAR_MAX+1}, | ||
345 | {0, 0, 0, 0} | 360 | {0, 0, 0, 0} |
346 | }; | 361 | }; |
347 | 362 | ||
@@ -450,6 +465,15 @@ process_arguments (int argc, char **argv) | |||
450 | asprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args); | 465 | asprintf (&fmt, "%s%sargs '%s'", (fmt ? fmt : ""), (options ? ", " : ""), args); |
451 | options |= ARGS; | 466 | options |= ARGS; |
452 | break; | 467 | break; |
468 | case CHAR_MAX+1: | ||
469 | err = regcomp(&re_args, optarg, cflags); | ||
470 | if (err != 0) { | ||
471 | regerror (err, &re_args, errbuf, MAX_INPUT_BUFFER); | ||
472 | die (STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | ||
473 | } | ||
474 | asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), optarg); | ||
475 | options |= EREG_ARGS; | ||
476 | break; | ||
453 | case 'r': /* RSS */ | 477 | case 'r': /* RSS */ |
454 | if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { | 478 | if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { |
455 | asprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss); | 479 | asprintf (&fmt, "%s%sRSS >= %d", (fmt ? fmt : ""), (options ? ", " : ""), rss); |
@@ -716,6 +740,8 @@ print_help (void) | |||
716 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); | 740 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); |
717 | printf (" %s\n", "-a, --argument-array=STRING"); | 741 | printf (" %s\n", "-a, --argument-array=STRING"); |
718 | printf (" %s\n", _("Only scan for processes with args that contain STRING.")); | 742 | printf (" %s\n", _("Only scan for processes with args that contain STRING.")); |
743 | printf (" %s\n", "--ereg-argument-array=STRING"); | ||
744 | printf (" %s\n", _("Only scan for processes with args that contain the regex STRING.")); | ||
719 | printf (" %s\n", "-C, --command=COMMAND"); | 745 | printf (" %s\n", "-C, --command=COMMAND"); |
720 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); | 746 | printf (" %s\n", _("Only scan for exact matches of COMMAND (without path).")); |
721 | 747 | ||
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t index b8c2e8a..2a41ac5 100644 --- a/plugins/t/check_procs.t +++ b/plugins/t/check_procs.t | |||
@@ -6,20 +6,40 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use Test; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | use vars qw($tests); | ||
13 | BEGIN {$tests = 12; plan tests => $tests} | ||
14 | |||
15 | my $t; | 12 | my $t; |
16 | 13 | ||
17 | $t += checkCmd( "./check_procs -w 100000 -c 100000", 0, '/^PROCS OK: [0-9]+ process(es)?$/' ); | 14 | if (`uname -s` eq "SunOS\n") { |
18 | $t += checkCmd( "./check_procs -w 100000 -c 100000 -s Z", 0, '/^PROCS OK: [0-9]+ process(es)? with /' ); | 15 | plan skip_all => "Ignoring tests on solaris because of pst3"; |
19 | $t += checkCmd( "./check_procs -w 0 -c 10000000", 1, '/^PROCS WARNING: [0-9]+ process(es)?$/' ); | 16 | } else { |
20 | $t += checkCmd( "./check_procs -w 0 -c 0", 2, '/^PROCS CRITICAL: [0-9]+ process(es)?$/' ); | 17 | plan tests => 12; |
21 | $t += checkCmd( "./check_procs -w 0 -c 0 -s S", 2, '/^PROCS CRITICAL: [0-9]+ process(es)? with /' ); | 18 | } |
22 | $t += checkCmd( "./check_procs -w 0 -c 10000000 -p 1", 1, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/' ); | 19 | |
20 | my $result; | ||
21 | |||
22 | $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" ); | ||
23 | is( $result->return_code, 0, "Checking less than 10000 processes" ); | ||
24 | like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" ); | ||
25 | |||
26 | $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" ); | ||
27 | is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); | ||
28 | like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" ); | ||
29 | |||
30 | $result = NPTest->testCmd( "./check_procs -w 0 -c 100000" ); | ||
31 | is( $result->return_code, 1, "Checking warning if processes > 0" ); | ||
32 | like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)?$/', "Output correct" ); | ||
33 | |||
34 | $result = NPTest->testCmd( "./check_procs -w 0 -c 0" ); | ||
35 | is( $result->return_code, 2, "Checking critical if processes > 0" ); | ||
36 | like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" ); | ||
37 | |||
38 | $result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" ); | ||
39 | is( $result->return_code, 2, "Checking critical if sleeping processes" ); | ||
40 | like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" ); | ||
41 | |||
42 | $result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" ); | ||
43 | is( $result->return_code, 1, "Checking warning for processes by parentid = 1" ); | ||
44 | like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" ); | ||
23 | 45 | ||
24 | exit(0) if defined($Test::Harness::VERSION); | ||
25 | exit($tests - $t); | ||