summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-08-30 09:36:53 +0200
committerGitHub <noreply@github.com>2023-08-30 09:36:53 +0200
commitaa76eece10aebfb9977614b0038fcdc742b3f104 (patch)
tree6461802dc9db220c11815ec2df6a2376ceeb1921 /plugins/check_snmp.c
parentc47f44d897680d09841f8e787964de40063ea34c (diff)
parent554c1433cf624cd0ed0565e4a8d06ea5e4bdf942 (diff)
downloadmonitoring-plugins-aa76eece10aebfb9977614b0038fcdc742b3f104.tar.gz
Merge branch 'master' into compiler_warning_part_5
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c63
1 files changed, 42 insertions, 21 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 4d8e6406..56a586ad 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 */
@@ -160,6 +161,7 @@ double multiplier = 1.0;
160char *fmtstr = ""; 161char *fmtstr = "";
161bool fmtstr_set = false; 162bool fmtstr_set = false;
162char buffer[DEFAULT_BUFFER_SIZE]; 163char buffer[DEFAULT_BUFFER_SIZE];
164bool ignore_mib_parsing_errors = false;
163 165
164static char *fix_snmp_range(char *th) 166static char *fix_snmp_range(char *th)
165{ 167{
@@ -307,42 +309,55 @@ main (int argc, char **argv)
307 } 309 }
308 310
309 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ 311 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */
310 command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); 312
311 command_line[0] = snmpcmd; 313 unsigned index = 0;
312 command_line[1] = strdup ("-Le"); 314 command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *));
313 command_line[2] = strdup ("-t"); 315
314 xasprintf (&command_line[3], "%d", timeout_interval); 316 command_line[index++] = snmpcmd;
315 command_line[4] = strdup ("-r"); 317 command_line[index++] = strdup ("-Le");
316 xasprintf (&command_line[5], "%d", retries); 318 command_line[index++] = strdup ("-t");
317 command_line[6] = strdup ("-m"); 319 xasprintf (&command_line[index++], "%d", timeout_interval);
318 command_line[7] = strdup (miblist); 320 command_line[index++] = strdup ("-r");
319 command_line[8] = "-v"; 321 xasprintf (&command_line[index++], "%d", retries);
320 command_line[9] = strdup (proto); 322 command_line[index++] = strdup ("-m");
323 command_line[index++] = strdup (miblist);
324 command_line[index++] = "-v";
325 command_line[index++] = strdup (proto);
326
327 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s",
328 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto);
329
330 if (ignore_mib_parsing_errors) {
331 command_line[index++] = "-Pe";
332 xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth);
333 }
334
321 335
322 for (i = 0; i < numcontext; i++) { 336 for (i = 0; i < numcontext; i++) {
323 command_line[10 + i] = contextargs[i]; 337 command_line[index++] = contextargs[i];
324 } 338 }
325 339
326 for (i = 0; i < numauthpriv; i++) { 340 for (i = 0; i < numauthpriv; i++) {
327 command_line[10 + numcontext + i] = authpriv[i]; 341 command_line[index++] = authpriv[i];
328 } 342 }
329 343
330 xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); 344 xasprintf (&command_line[index++], "%s:%s", server_address, port);
331 345
332 /* This is just for display purposes, so it can remain a string */ 346 xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s",
333 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", 347 cl_hidden_auth,
334 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", 348 server_address,
335 server_address, port); 349 port);
336 350
337 for (i = 0; i < numoids; i++) { 351 for (i = 0; i < numoids; i++) {
338 command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; 352 command_line[index++] = oids[i];
339 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 353 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
340 } 354 }
341 355
342 command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; 356 command_line[index++] = NULL;
343 357
344 if (verbose) 358 if (verbose) {
345 printf ("%s\n", cl_hidden_auth); 359 printf ("%s\n", cl_hidden_auth);
360 }
346 361
347 /* Set signal handling and alarm */ 362 /* Set signal handling and alarm */
348 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { 363 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
@@ -711,6 +726,7 @@ process_arguments (int argc, char **argv)
711 {"ipv6", no_argument, 0, '6'}, 726 {"ipv6", no_argument, 0, '6'},
712 {"multiplier", required_argument, 0, 'M'}, 727 {"multiplier", required_argument, 0, 'M'},
713 {"fmtstr", required_argument, 0, 'f'}, 728 {"fmtstr", required_argument, 0, 'f'},
729 {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS},
714 {0, 0, 0, 0} 730 {0, 0, 0, 0}
715 }; 731 };
716 732
@@ -978,6 +994,8 @@ process_arguments (int argc, char **argv)
978 fmtstr_set = true; 994 fmtstr_set = true;
979 } 995 }
980 break; 996 break;
997 case L_IGNORE_MIB_PARSING_ERRORS:
998 ignore_mib_parsing_errors = true;
981 } 999 }
982 } 1000 }
983 1001
@@ -1311,6 +1329,9 @@ print_help (void)
1311 printf (" %s\n", "-O, --perf-oids"); 1329 printf (" %s\n", "-O, --perf-oids");
1312 printf (" %s\n", _("Label performance data with OIDs instead of --label's")); 1330 printf (" %s\n", _("Label performance data with OIDs instead of --label's"));
1313 1331
1332 printf (" %s\n", "--ignore-mib-parsing-errors");
1333 printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files"));
1334
1314 printf (UT_VERBOSE); 1335 printf (UT_VERBOSE);
1315 1336
1316 printf ("\n"); 1337 printf ("\n");