summaryrefslogtreecommitdiffstats
path: root/plugins/check_procs.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_procs.c')
-rw-r--r--plugins/check_procs.c26
1 files changed, 26 insertions, 0 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