summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2008-02-28 16:21:59 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2008-02-28 16:21:59 +0000
commit9f3d864fd3e47d4e728b196b1b6948a8a5e47e4e (patch)
treeffaf70a0a09e40cf706f1362a01450f76e845d18 /plugins
parentf00e6a9676154eaac8aed140c49bde76e52d6cee (diff)
downloadmonitoring-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
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_procs.c26
-rw-r--r--plugins/t/check_procs.t44
2 files changed, 58 insertions, 12 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 690b8554..7dae8454 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 */
73char *metric_name; 75char *metric_name;
74enum metric { 76enum metric {
@@ -89,6 +91,7 @@ float pcpu;
89char *statopts; 91char *statopts;
90char *prog; 92char *prog;
91char *args; 93char *args;
94regex_t re_args;
92char *fmt; 95char *fmt;
93char *fails; 96char *fails;
94char tmp[MAX_INPUT_BUFFER]; 97char 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 b8c2e8a5..2a41ac5c 100644
--- a/plugins/t/check_procs.t
+++ b/plugins/t/check_procs.t
@@ -6,20 +6,40 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests);
13BEGIN {$tests = 12; plan tests => $tests}
14
15my $t; 12my $t;
16 13
17$t += checkCmd( "./check_procs -w 100000 -c 100000", 0, '/^PROCS OK: [0-9]+ process(es)?$/' ); 14if (`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
20my $result;
21
22$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
23is( $result->return_code, 0, "Checking less than 10000 processes" );
24like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" );
25
26$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
27is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
28like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
29
30$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
31is( $result->return_code, 1, "Checking warning if processes > 0" );
32like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)?$/', "Output correct" );
33
34$result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
35is( $result->return_code, 2, "Checking critical if processes > 0" );
36like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" );
37
38$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
39is( $result->return_code, 2, "Checking critical if sleeping processes" );
40like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" );
41
42$result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" );
43is( $result->return_code, 1, "Checking warning for processes by parentid = 1" );
44like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" );
23 45
24exit(0) if defined($Test::Harness::VERSION);
25exit($tests - $t);