summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1bc7a4a)
raw | patch | inline | side by side (parent: 1bc7a4a)
author | Sebastian Harl <sh@teamix.net> | |
Fri, 8 Apr 2011 08:18:48 +0000 (10:18 +0200) | ||
committer | Sebastian Harl <sh@teamix.net> | |
Fri, 8 Apr 2011 08:18:48 +0000 (10:18 +0200) |
This adds support for @<range> and makes stuff a bit simpler by removing code
duplications.
Note: Previously, the compatibility code for 'check_procs <warn> <max>'
accepted something like 'check_procs -w 10:-1 -c 10:-1 20 50' as well
(treating it as if '-w 10:20 -c 10:50' was specified). This is no longer the
case … additional arguments are only used as warn/crit thresholds in case
-w/-c is not specified at all.
duplications.
Note: Previously, the compatibility code for 'check_procs <warn> <max>'
accepted something like 'check_procs -w 10:-1 -c 10:-1 20 50' as well
(treating it as if '-w 10:20 -c 10:50' was specified). This is no longer the
case … additional arguments are only used as warn/crit thresholds in case
-w/-c is not specified at all.
plugins/check_procs.c | patch | blob | history |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index d875a618f3eb259644928f39b4299a650467aa13..41228c52742d3bf1083bdcd1602a8790945d9179 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
int process_arguments (int, char **);
int validate_arguments (void);
-int check_thresholds (int);
int convert_to_seconds (char *);
void print_help (void);
void print_usage (void);
-int wmax = -1;
-int cmax = -1;
-int wmin = -1;
-int cmin = -1;
+char *warning_range = NULL;
+char *critical_range = NULL;
+thresholds *procs_thresholds = NULL;
int options = 0; /* bitmask of filter criteria to test against */
#define ALL 1
}
if (metric == METRIC_VSZ)
- i = check_thresholds (procvsz);
+ i = get_status ((double)procvsz, procs_thresholds);
else if (metric == METRIC_RSS)
- i = check_thresholds (procrss);
+ i = get_status ((double)procrss, procs_thresholds);
/* TODO? float thresholds for --metric=CPU */
else if (metric == METRIC_CPU)
- i = check_thresholds ((int)procpcpu);
+ i = get_status (procpcpu, procs_thresholds);
else if (metric == METRIC_ELAPSED)
- i = check_thresholds (procseconds);
+ i = get_status ((double)procseconds, procs_thresholds);
if (metric != METRIC_PROCS) {
if (i == STATE_WARNING) {
/* Needed if procs found, but none match filter */
if ( metric == METRIC_PROCS ) {
- result = max_state (result, check_thresholds (procs) );
+ result = max_state (result, get_status ((double)procs, procs_thresholds) );
}
if ( result == STATE_OK ) {
timeout_interval = atoi (optarg);
break;
case 'c': /* critical threshold */
- if (is_integer (optarg))
- cmax = atoi (optarg);
- else if (sscanf (optarg, ":%d", &cmax) == 1)
- break;
- else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2)
- break;
- else if (sscanf (optarg, "%d:", &cmin) == 1)
- break;
- else
- usage4 (_("Critical Process Count must be an integer!"));
+ critical_range = optarg;
break;
case 'w': /* warning threshold */
- if (is_integer (optarg))
- wmax = atoi (optarg);
- else if (sscanf (optarg, ":%d", &wmax) == 1)
- break;
- else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2)
- break;
- else if (sscanf (optarg, "%d:", &wmin) == 1)
- break;
- else
- usage4 (_("Warning Process Count must be an integer!"));
+ warning_range = optarg;
break;
case 'p': /* process id */
if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
}
c = optind;
- if (wmax == -1 && argv[c])
- wmax = atoi (argv[c++]);
- if (cmax == -1 && argv[c])
- cmax = atoi (argv[c++]);
+ if ((! warning_range) && argv[c])
+ warning_range = argv[c++];
+ if ((! critical_range) && argv[c])
+ critical_range = argv[c++];
if (statopts == NULL && argv[c]) {
asprintf (&statopts, "%s", argv[c++]);
asprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts);
options |= STAT;
}
+ /* this will abort in case of invalid ranges */
+ set_thresholds (&procs_thresholds, warning_range, critical_range);
+
return validate_arguments ();
}
int
validate_arguments ()
{
-
- if (wmax >= 0 && wmin == -1)
- wmin = 0;
- if (cmax >= 0 && cmin == -1)
- cmin = 0;
- if (wmax >= wmin && cmax >= cmin) { /* standard ranges */
- if (wmax > cmax && cmax != -1) {
- printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax);
- return ERROR;
- }
- if (cmin > wmin && wmin != -1) {
- printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin);
- return ERROR;
- }
- }
-
-/* if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { */
-/* printf ("At least one threshold must be set\n"); */
-/* return ERROR; */
-/* } */
-
if (options == 0)
options = ALL;
}
-
-/* Check thresholds against value */
-int
-check_thresholds (int value)
-{
- if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) {
- return OK;
- }
- else if (cmax >= 0 && cmin >= 0 && cmax < cmin) {
- if (value > cmax && value < cmin)
- return STATE_CRITICAL;
- }
- else if (cmax >= 0 && value > cmax) {
- return STATE_CRITICAL;
- }
- else if (cmin >= 0 && value < cmin) {
- return STATE_CRITICAL;
- }
-
- if (wmax >= 0 && wmin >= 0 && wmax < wmin) {
- if (value > wmax && value < wmin) {
- return STATE_WARNING;
- }
- }
- else if (wmax >= 0 && value > wmax) {
- return STATE_WARNING;
- }
- else if (wmin >= 0 && value < wmin) {
- return STATE_WARNING;
- }
- return STATE_OK;
-}
-
-
/* convert the elapsed time to seconds */
int
convert_to_seconds(char *etime) {