diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2008-02-28 16:21:59 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2008-02-28 16:21:59 +0000 |
commit | 9f3d864fd3e47d4e728b196b1b6948a8a5e47e4e (patch) | |
tree | ffaf70a0a09e40cf706f1362a01450f76e845d18 /plugins | |
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
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_procs.c | 26 | ||||
-rw-r--r-- | plugins/t/check_procs.t | 44 |
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"; #include "common.h" #include "popen.h" #include "utils.h" +#include "regex.h" #include <pwd.h> @@ -69,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */ #define RSS 128 #define PCPU 256 #define ELAPSED 512 +#define EREG_ARGS 1024 /* Different metrics */ char *metric_name; enum metric { @@ -89,6 +91,7 @@ float pcpu; char *statopts; char *prog; char *args; +regex_t re_args; char *fmt; char *fails; char tmp[MAX_INPUT_BUFFER]; @@ -211,6 +214,8 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) 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 @@ process_arguments (int argc, char **argv) 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 @@ process_arguments (int argc, char **argv) {"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 @@ process_arguments (int argc, char **argv) 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 @@ print_help (void) 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).")); 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 @@ # 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; +} + +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" ); -exit(0) if defined($Test::Harness::VERSION); -exit($tests - $t); |