diff options
author | Jan Wagner <waja@cyconet.org> | 2023-10-17 13:39:37 +0200 |
---|---|---|
committer | Jan Wagner <waja@cyconet.org> | 2023-10-17 13:39:37 +0200 |
commit | 2a047014385022c8dc06dad4da0428db14898689 (patch) | |
tree | 00abea46325decf0c72870ee8f9ec1472e8e5344 /plugins/check_snmp.c | |
parent | f39211c26408af582121f519d89c8abf70e6d437 (diff) | |
parent | e23a75d954311b3be429a9020e4d317b89615ee7 (diff) | |
download | monitoring-plugins-2a04701.tar.gz |
Merge branch 'master' of github.com:monitoring-plugins/monitoring-plugins
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 04dc6c6f..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 */ |
@@ -158,7 +159,9 @@ int perf_labels = 1; | |||
158 | char* ip_version = ""; | 159 | char* ip_version = ""; |
159 | double multiplier = 1.0; | 160 | double multiplier = 1.0; |
160 | char *fmtstr = ""; | 161 | char *fmtstr = ""; |
162 | bool fmtstr_set = false; | ||
161 | char buffer[DEFAULT_BUFFER_SIZE]; | 163 | char buffer[DEFAULT_BUFFER_SIZE]; |
164 | bool ignore_mib_parsing_errors = false; | ||
162 | 165 | ||
163 | static char *fix_snmp_range(char *th) | 166 | static char *fix_snmp_range(char *th) |
164 | { | 167 | { |
@@ -306,42 +309,55 @@ main (int argc, char **argv) | |||
306 | } | 309 | } |
307 | 310 | ||
308 | /* 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 */ |
309 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 312 | |
310 | command_line[0] = snmpcmd; | 313 | unsigned index = 0; |
311 | command_line[1] = strdup ("-Le"); | 314 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
312 | command_line[2] = strdup ("-t"); | 315 | |
313 | xasprintf (&command_line[3], "%d", timeout_interval); | 316 | command_line[index++] = snmpcmd; |
314 | command_line[4] = strdup ("-r"); | 317 | command_line[index++] = strdup ("-Le"); |
315 | xasprintf (&command_line[5], "%d", retries); | 318 | command_line[index++] = strdup ("-t"); |
316 | command_line[6] = strdup ("-m"); | 319 | xasprintf (&command_line[index++], "%d", timeout_interval); |
317 | command_line[7] = strdup (miblist); | 320 | command_line[index++] = strdup ("-r"); |
318 | command_line[8] = "-v"; | 321 | xasprintf (&command_line[index++], "%d", retries); |
319 | 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 | |||
320 | 335 | ||
321 | for (i = 0; i < numcontext; i++) { | 336 | for (i = 0; i < numcontext; i++) { |
322 | command_line[10 + i] = contextargs[i]; | 337 | command_line[index++] = contextargs[i]; |
323 | } | 338 | } |
324 | 339 | ||
325 | for (i = 0; i < numauthpriv; i++) { | 340 | for (i = 0; i < numauthpriv; i++) { |
326 | command_line[10 + numcontext + i] = authpriv[i]; | 341 | command_line[index++] = authpriv[i]; |
327 | } | 342 | } |
328 | 343 | ||
329 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 344 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
330 | 345 | ||
331 | /* This is just for display purposes, so it can remain a string */ | 346 | 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", | 347 | cl_hidden_auth, |
333 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 348 | server_address, |
334 | server_address, port); | 349 | port); |
335 | 350 | ||
336 | for (i = 0; i < numoids; i++) { | 351 | for (i = 0; i < numoids; i++) { |
337 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 352 | command_line[index++] = oids[i]; |
338 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 353 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
339 | } | 354 | } |
340 | 355 | ||
341 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 356 | command_line[index++] = NULL; |
342 | 357 | ||
343 | if (verbose) | 358 | if (verbose) { |
344 | printf ("%s\n", cl_hidden_auth); | 359 | printf ("%s\n", cl_hidden_auth); |
360 | } | ||
345 | 361 | ||
346 | /* Set signal handling and alarm */ | 362 | /* Set signal handling and alarm */ |
347 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 363 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
@@ -422,7 +438,8 @@ main (int argc, char **argv) | |||
422 | } | 438 | } |
423 | else if (strstr (response, "INTEGER: ")) { | 439 | else if (strstr (response, "INTEGER: ")) { |
424 | show = multiply (strstr (response, "INTEGER: ") + 9); | 440 | show = multiply (strstr (response, "INTEGER: ") + 9); |
425 | if (fmtstr != "") { | 441 | |
442 | if (fmtstr_set) { | ||
426 | conv = fmtstr; | 443 | conv = fmtstr; |
427 | } | 444 | } |
428 | } | 445 | } |
@@ -596,8 +613,9 @@ main (int argc, char **argv) | |||
596 | len = sizeof(perfstr)-strlen(perfstr)-1; | 613 | len = sizeof(perfstr)-strlen(perfstr)-1; |
597 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 614 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
598 | 615 | ||
599 | if (type) | 616 | if (strcmp(type, "") != 0) { |
600 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | 617 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); |
618 | } | ||
601 | 619 | ||
602 | if (warning_thresholds) { | 620 | if (warning_thresholds) { |
603 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 621 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -708,6 +726,7 @@ process_arguments (int argc, char **argv) | |||
708 | {"ipv6", no_argument, 0, '6'}, | 726 | {"ipv6", no_argument, 0, '6'}, |
709 | {"multiplier", required_argument, 0, 'M'}, | 727 | {"multiplier", required_argument, 0, 'M'}, |
710 | {"fmtstr", required_argument, 0, 'f'}, | 728 | {"fmtstr", required_argument, 0, 'f'}, |
729 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
711 | {0, 0, 0, 0} | 730 | {0, 0, 0, 0} |
712 | }; | 731 | }; |
713 | 732 | ||
@@ -972,8 +991,11 @@ process_arguments (int argc, char **argv) | |||
972 | case 'f': | 991 | case 'f': |
973 | if (multiplier != 1.0) { | 992 | if (multiplier != 1.0) { |
974 | fmtstr=optarg; | 993 | fmtstr=optarg; |
994 | fmtstr_set = true; | ||
975 | } | 995 | } |
976 | break; | 996 | break; |
997 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
998 | ignore_mib_parsing_errors = true; | ||
977 | } | 999 | } |
978 | } | 1000 | } |
979 | 1001 | ||
@@ -1186,7 +1208,7 @@ multiply (char *str) | |||
1186 | if(verbose>2) | 1208 | if(verbose>2) |
1187 | printf(" multiply extracted double: %f\n", val); | 1209 | printf(" multiply extracted double: %f\n", val); |
1188 | val *= multiplier; | 1210 | val *= multiplier; |
1189 | if (fmtstr != "") { | 1211 | if (fmtstr_set) { |
1190 | conv = fmtstr; | 1212 | conv = fmtstr; |
1191 | } | 1213 | } |
1192 | if (val == (int)val) { | 1214 | if (val == (int)val) { |
@@ -1307,6 +1329,9 @@ print_help (void) | |||
1307 | printf (" %s\n", "-O, --perf-oids"); | 1329 | printf (" %s\n", "-O, --perf-oids"); |
1308 | 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")); |
1309 | 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 | |||
1310 | printf (UT_VERBOSE); | 1335 | printf (UT_VERBOSE); |
1311 | 1336 | ||
1312 | printf ("\n"); | 1337 | printf ("\n"); |