diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 7c5d0ec..7c3bc4b 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -63,6 +63,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
63 | #define L_CALCULATE_RATE CHAR_MAX+1 | 63 | #define L_CALCULATE_RATE CHAR_MAX+1 |
64 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 64 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
65 | #define L_INVERT_SEARCH CHAR_MAX+3 | 65 | #define L_INVERT_SEARCH CHAR_MAX+3 |
66 | #define L_OFFSET CHAR_MAX+4 | ||
66 | 67 | ||
67 | /* Gobble to string - stop incrementing c when c[0] match one of the | 68 | /* Gobble to string - stop incrementing c when c[0] match one of the |
68 | * characters in s */ | 69 | * characters in s */ |
@@ -138,6 +139,7 @@ char *output_delim; | |||
138 | char *miblist = NULL; | 139 | char *miblist = NULL; |
139 | int needmibs = FALSE; | 140 | int needmibs = FALSE; |
140 | int calculate_rate = 0; | 141 | int calculate_rate = 0; |
142 | double offset = 0.0; | ||
141 | int rate_multiplier = 1; | 143 | int rate_multiplier = 1; |
142 | state_data *previous_state; | 144 | state_data *previous_state; |
143 | double previous_value[MAX_OIDS]; | 145 | double previous_value[MAX_OIDS]; |
@@ -274,35 +276,36 @@ main (int argc, char **argv) | |||
274 | snmpcmd = strdup (PATH_TO_SNMPGET); | 276 | snmpcmd = strdup (PATH_TO_SNMPGET); |
275 | } | 277 | } |
276 | 278 | ||
277 | /* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 279 | /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
278 | command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 280 | command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
279 | command_line[0] = snmpcmd; | 281 | command_line[0] = snmpcmd; |
280 | command_line[1] = strdup ("-t"); | 282 | command_line[1] = strdup ("-Le"); |
281 | xasprintf (&command_line[2], "%d", timeout_interval); | 283 | command_line[2] = strdup ("-t"); |
282 | command_line[3] = strdup ("-r"); | 284 | xasprintf (&command_line[3], "%d", timeout_interval); |
283 | xasprintf (&command_line[4], "%d", retries); | 285 | command_line[4] = strdup ("-r"); |
284 | command_line[5] = strdup ("-m"); | 286 | xasprintf (&command_line[5], "%d", retries); |
285 | command_line[6] = strdup (miblist); | 287 | command_line[6] = strdup ("-m"); |
286 | command_line[7] = "-v"; | 288 | command_line[7] = strdup (miblist); |
287 | command_line[8] = strdup (proto); | 289 | command_line[8] = "-v"; |
290 | command_line[9] = strdup (proto); | ||
288 | 291 | ||
289 | for (i = 0; i < numauthpriv; i++) { | 292 | for (i = 0; i < numauthpriv; i++) { |
290 | command_line[9 + i] = authpriv[i]; | 293 | command_line[10 + i] = authpriv[i]; |
291 | } | 294 | } |
292 | 295 | ||
293 | xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); | 296 | xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port); |
294 | 297 | ||
295 | /* This is just for display purposes, so it can remain a string */ | 298 | /* This is just for display purposes, so it can remain a string */ |
296 | xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", | 299 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s", |
297 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | 300 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", |
298 | server_address, port); | 301 | server_address, port); |
299 | 302 | ||
300 | for (i = 0; i < numoids; i++) { | 303 | for (i = 0; i < numoids; i++) { |
301 | command_line[9 + numauthpriv + 1 + i] = oids[i]; | 304 | command_line[10 + numauthpriv + 1 + i] = oids[i]; |
302 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 305 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
303 | } | 306 | } |
304 | 307 | ||
305 | command_line[9 + numauthpriv + 1 + numoids] = NULL; | 308 | command_line[10 + numauthpriv + 1 + numoids] = NULL; |
306 | 309 | ||
307 | if (verbose) | 310 | if (verbose) |
308 | printf ("%s\n", cl_hidden_auth); | 311 | printf ("%s\n", cl_hidden_auth); |
@@ -429,7 +432,7 @@ main (int argc, char **argv) | |||
429 | ptr = strpbrk (show, "0123456789"); | 432 | ptr = strpbrk (show, "0123456789"); |
430 | if (ptr == NULL) | 433 | if (ptr == NULL) |
431 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 434 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
432 | response_value[i] = strtod (ptr, NULL); | 435 | response_value[i] = strtod (ptr, NULL) + offset; |
433 | 436 | ||
434 | if(calculate_rate) { | 437 | if(calculate_rate) { |
435 | if (previous_state!=NULL) { | 438 | if (previous_state!=NULL) { |
@@ -618,6 +621,7 @@ process_arguments (int argc, char **argv) | |||
618 | {"next", no_argument, 0, 'n'}, | 621 | {"next", no_argument, 0, 'n'}, |
619 | {"rate", no_argument, 0, L_CALCULATE_RATE}, | 622 | {"rate", no_argument, 0, L_CALCULATE_RATE}, |
620 | {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, | 623 | {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, |
624 | {"offset", required_argument, 0, L_OFFSET}, | ||
621 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, | 625 | {"invert-search", no_argument, 0, L_INVERT_SEARCH}, |
622 | {"perf-oids", no_argument, 0, 'O'}, | 626 | {"perf-oids", no_argument, 0, 'O'}, |
623 | {0, 0, 0, 0} | 627 | {0, 0, 0, 0} |
@@ -832,6 +836,9 @@ process_arguments (int argc, char **argv) | |||
832 | if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) | 836 | if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) |
833 | usage2(_("Rate multiplier must be a positive integer"),optarg); | 837 | usage2(_("Rate multiplier must be a positive integer"),optarg); |
834 | break; | 838 | break; |
839 | case L_OFFSET: | ||
840 | offset=strtod(optarg,NULL); | ||
841 | break; | ||
835 | case L_INVERT_SEARCH: | 842 | case L_INVERT_SEARCH: |
836 | invert_search=1; | 843 | invert_search=1; |
837 | break; | 844 | break; |
@@ -1080,6 +1087,8 @@ print_help (void) | |||
1080 | printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); | 1087 | printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); |
1081 | printf (" %s\n", "--rate-multiplier"); | 1088 | printf (" %s\n", "--rate-multiplier"); |
1082 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); | 1089 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); |
1090 | printf (" %s\n", "--offset=OFFSET"); | ||
1091 | printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data")); | ||
1083 | 1092 | ||
1084 | /* Tests Against Strings */ | 1093 | /* Tests Against Strings */ |
1085 | printf (" %s\n", "-s, --string=STRING"); | 1094 | printf (" %s\n", "-s, --string=STRING"); |