summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-08-27 21:13:17 (GMT)
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-08-27 21:13:17 (GMT)
commit90cb539595bcc94bf2a7a0036d7ecf781518eb81 (patch)
tree1170eabc352d300ddc20dcc2f30a316f29739eb9 /plugins
parent43131b73d69e77a3faee69814dac1bbc88162887 (diff)
downloadmonitoring-plugins-90cb539595bcc94bf2a7a0036d7ecf781518eb81.tar.gz
Implement option to ignore mib file parsing errors
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c64
1 files changed, 47 insertions, 17 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 04dc6c6..43e79a1 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 = "";
159double multiplier = 1.0; 160double multiplier = 1.0;
160char *fmtstr = ""; 161char *fmtstr = "";
161char buffer[DEFAULT_BUFFER_SIZE]; 162char buffer[DEFAULT_BUFFER_SIZE];
163bool ignore_mib_parsing_errors = false;
162 164
163static char *fix_snmp_range(char *th) 165static char *fix_snmp_range(char *th)
164{ 166{
@@ -306,42 +308,64 @@ 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);
344
345 xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s",
346 cl_hidden_auth,
347 server_address,
348 port);
349
350
330 351
331 /* This is just for display purposes, so it can remain a string */ 352 /* This is just for display purposes, so it can remain a string */
353 /*
332 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", 354 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s",
333 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", 355 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]",
334 server_address, port); 356 server_address, port);
357 */
335 358
336 for (i = 0; i < numoids; i++) { 359 for (i = 0; i < numoids; i++) {
337 command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; 360 command_line[index++] = oids[i];
338 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 361 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
339 } 362 }
340 363
341 command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; 364 command_line[index++] = NULL;
342 365
343 if (verbose) 366 if (verbose) {
344 printf ("%s\n", cl_hidden_auth); 367 printf ("%s\n", cl_hidden_auth);
368 }
345 369
346 /* Set signal handling and alarm */ 370 /* Set signal handling and alarm */
347 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { 371 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
@@ -708,6 +732,7 @@ process_arguments (int argc, char **argv)
708 {"ipv6", no_argument, 0, '6'}, 732 {"ipv6", no_argument, 0, '6'},
709 {"multiplier", required_argument, 0, 'M'}, 733 {"multiplier", required_argument, 0, 'M'},
710 {"fmtstr", required_argument, 0, 'f'}, 734 {"fmtstr", required_argument, 0, 'f'},
735 {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS},
711 {0, 0, 0, 0} 736 {0, 0, 0, 0}
712 }; 737 };
713 738
@@ -974,6 +999,8 @@ process_arguments (int argc, char **argv)
974 fmtstr=optarg; 999 fmtstr=optarg;
975 } 1000 }
976 break; 1001 break;
1002 case L_IGNORE_MIB_PARSING_ERRORS:
1003 ignore_mib_parsing_errors = true;
977 } 1004 }
978 } 1005 }
979 1006
@@ -1307,6 +1334,9 @@ print_help (void)
1307 printf (" %s\n", "-O, --perf-oids"); 1334 printf (" %s\n", "-O, --perf-oids");
1308 printf (" %s\n", _("Label performance data with OIDs instead of --label's")); 1335 printf (" %s\n", _("Label performance data with OIDs instead of --label's"));
1309 1336
1337 printf (" %s\n", "--ignore-mib-parsing-errors");
1338 printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files"));
1339
1310 printf (UT_VERBOSE); 1340 printf (UT_VERBOSE);
1311 1341
1312 printf ("\n"); 1342 printf ("\n");