diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 04dc6c6f..2acada22 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -65,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
66 | #define L_INVERT_SEARCH CHAR_MAX+3 | 66 | #define L_INVERT_SEARCH CHAR_MAX+3 |
67 | #define L_OFFSET CHAR_MAX+4 | 67 | #define L_OFFSET CHAR_MAX+4 |
68 | #define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 | ||
68 | 69 | ||
69 | /* Gobble to string - stop incrementing c when c[0] match one of the | 70 | /* Gobble to string - stop incrementing c when c[0] match one of the |
70 | * characters in s */ | 71 | * characters in s */ |
@@ -159,6 +160,7 @@ char* ip_version = ""; | |||
159 | double multiplier = 1.0; | 160 | double multiplier = 1.0; |
160 | char *fmtstr = ""; | 161 | char *fmtstr = ""; |
161 | char buffer[DEFAULT_BUFFER_SIZE]; | 162 | char buffer[DEFAULT_BUFFER_SIZE]; |
163 | bool ignore_mib_parsing_errors = false; | ||
162 | 164 | ||
163 | static char *fix_snmp_range(char *th) | 165 | static char *fix_snmp_range(char *th) |
164 | { | 166 | { |
@@ -306,42 +308,55 @@ main (int argc, char **argv) | |||
306 | } | 308 | } |
307 | 309 | ||
308 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 310 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
309 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 311 | |
310 | command_line[0] = snmpcmd; | 312 | unsigned index = 0; |
311 | command_line[1] = strdup ("-Le"); | 313 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
312 | command_line[2] = strdup ("-t"); | 314 | |
313 | xasprintf (&command_line[3], "%d", timeout_interval); | 315 | command_line[index++] = snmpcmd; |
314 | command_line[4] = strdup ("-r"); | 316 | command_line[index++] = strdup ("-Le"); |
315 | xasprintf (&command_line[5], "%d", retries); | 317 | command_line[index++] = strdup ("-t"); |
316 | command_line[6] = strdup ("-m"); | 318 | xasprintf (&command_line[index++], "%d", timeout_interval); |
317 | command_line[7] = strdup (miblist); | 319 | command_line[index++] = strdup ("-r"); |
318 | command_line[8] = "-v"; | 320 | xasprintf (&command_line[index++], "%d", retries); |
319 | command_line[9] = strdup (proto); | 321 | command_line[index++] = strdup ("-m"); |
322 | command_line[index++] = strdup (miblist); | ||
323 | command_line[index++] = "-v"; | ||
324 | command_line[index++] = strdup (proto); | ||
325 | |||
326 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", | ||
327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); | ||
328 | |||
329 | if (ignore_mib_parsing_errors) { | ||
330 | command_line[index++] = "-Pe"; | ||
331 | xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); | ||
332 | } | ||
333 | |||
320 | 334 | ||
321 | for (i = 0; i < numcontext; i++) { | 335 | for (i = 0; i < numcontext; i++) { |
322 | command_line[10 + i] = contextargs[i]; | 336 | command_line[index++] = contextargs[i]; |
323 | } | 337 | } |
324 | 338 | ||
325 | for (i = 0; i < numauthpriv; i++) { | 339 | for (i = 0; i < numauthpriv; i++) { |
326 | command_line[10 + numcontext + i] = authpriv[i]; | 340 | command_line[index++] = authpriv[i]; |
327 | } | 341 | } |
328 | 342 | ||
329 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 343 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
330 | 344 | ||
331 | /* This is just for display purposes, so it can remain a string */ | 345 | xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", |
332 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", | 346 | cl_hidden_auth, |
333 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 347 | server_address, |
334 | server_address, port); | 348 | port); |
335 | 349 | ||
336 | for (i = 0; i < numoids; i++) { | 350 | for (i = 0; i < numoids; i++) { |
337 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 351 | command_line[index++] = oids[i]; |
338 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 352 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
339 | } | 353 | } |
340 | 354 | ||
341 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 355 | command_line[index++] = NULL; |
342 | 356 | ||
343 | if (verbose) | 357 | if (verbose) { |
344 | printf ("%s\n", cl_hidden_auth); | 358 | printf ("%s\n", cl_hidden_auth); |
359 | } | ||
345 | 360 | ||
346 | /* Set signal handling and alarm */ | 361 | /* Set signal handling and alarm */ |
347 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 362 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
@@ -708,6 +723,7 @@ process_arguments (int argc, char **argv) | |||
708 | {"ipv6", no_argument, 0, '6'}, | 723 | {"ipv6", no_argument, 0, '6'}, |
709 | {"multiplier", required_argument, 0, 'M'}, | 724 | {"multiplier", required_argument, 0, 'M'}, |
710 | {"fmtstr", required_argument, 0, 'f'}, | 725 | {"fmtstr", required_argument, 0, 'f'}, |
726 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
711 | {0, 0, 0, 0} | 727 | {0, 0, 0, 0} |
712 | }; | 728 | }; |
713 | 729 | ||
@@ -974,6 +990,8 @@ process_arguments (int argc, char **argv) | |||
974 | fmtstr=optarg; | 990 | fmtstr=optarg; |
975 | } | 991 | } |
976 | break; | 992 | break; |
993 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
994 | ignore_mib_parsing_errors = true; | ||
977 | } | 995 | } |
978 | } | 996 | } |
979 | 997 | ||
@@ -1307,6 +1325,9 @@ print_help (void) | |||
1307 | printf (" %s\n", "-O, --perf-oids"); | 1325 | printf (" %s\n", "-O, --perf-oids"); |
1308 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1326 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
1309 | 1327 | ||
1328 | printf (" %s\n", "--ignore-mib-parsing-errors"); | ||
1329 | printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); | ||
1330 | |||
1310 | printf (UT_VERBOSE); | 1331 | printf (UT_VERBOSE); |
1311 | 1332 | ||
1312 | printf ("\n"); | 1333 | printf ("\n"); |