From 0f3703e641f0f995a8abb40056cb5430b6c228c4 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 14 Apr 2023 14:37:47 +0000 Subject: Fix a lot of typos reported by codespell --- plugins/check_snmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index aefda3d2..c425df3c 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -1274,7 +1274,7 @@ print_help (void) printf (" %s\n", "--rate-multiplier"); printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); printf (" %s\n", "--offset=OFFSET"); - printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data")); + printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data")); /* Tests Against Strings */ printf (" %s\n", "-s, --string=STRING"); -- cgit v1.2.3-74-g34f1 From f7687d47cb0841d0bc12ef205fcbaef8bf2e3805 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 19:56:43 +0100 Subject: Fixes for -Wimplicit-fallthrough --- plugins/check_curl.c | 1 + plugins/check_dbi.c | 1 + plugins/check_fping.c | 1 + plugins/check_hpjd.c | 1 + plugins/check_http.c | 1 + plugins/check_smtp.c | 1 + plugins/check_snmp.c | 1 + 7 files changed, 7 insertions(+) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index be5740d7..b7137145 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1654,6 +1654,7 @@ process_arguments (int argc, char **argv) break; case 'R': /* regex */ cflags |= REG_ICASE; + // fall through case 'r': /* regex */ strncpy (regexp, optarg, MAX_RE_SIZE - 1); regexp[MAX_RE_SIZE - 1] = 0; diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index ced13d05..d73efbb2 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c @@ -426,6 +426,7 @@ process_arguments (int argc, char **argv) else timeout_interval = atoi (optarg); + break; case 'H': /* host */ if (!is_host (optarg)) usage2 (_("Invalid hostname/address"), optarg); diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 6f5656ef..23a9e990 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -354,6 +354,7 @@ process_arguments (int argc, char **argv) break; case 'I': /* sourceip */ sourceif = strscpy (sourceif, optarg); + break; case '4': /* IPv4 only */ address_family = AF_INET; break; diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index c4b44178..c34bb082 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -353,6 +353,7 @@ process_arguments (int argc, char **argv) usage2 (_("Port must be a positive short integer"), optarg); else port = atoi(optarg); + break; case 'D': /* disable paper out check*/ check_paper_out = 0; break; diff --git a/plugins/check_http.c b/plugins/check_http.c index 8c03bc8b..432a984b 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -498,6 +498,7 @@ bool process_arguments (int argc, char **argv) break; case 'R': /* regex */ cflags |= REG_ICASE; + // fall through case 'r': /* regex */ strncpy (regexp, optarg, MAX_RE_SIZE - 1); regexp[MAX_RE_SIZE - 1] = 0; diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index eaa7eeba..b035aab5 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -616,6 +616,7 @@ process_arguments (int argc, char **argv) #else usage (_("SSL support not available - install OpenSSL and recompile")); #endif + // fall through case 'S': /* starttls */ use_ssl = TRUE; diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c425df3c..04dc6c6f 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -855,6 +855,7 @@ process_arguments (int argc, char **argv) break; case 'R': /* regex */ cflags = REG_ICASE; + // fall through case 'r': /* regex */ cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); -- cgit v1.2.3-74-g34f1 From 90cb539595bcc94bf2a7a0036d7ecf781518eb81 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 27 Aug 2023 23:13:17 +0200 Subject: Implement option to ignore mib file parsing errors --- plugins/check_snmp.c | 64 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 17 deletions(-) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 04dc6c6f..43e79a1c 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -65,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; #define L_RATE_MULTIPLIER CHAR_MAX+2 #define L_INVERT_SEARCH CHAR_MAX+3 #define L_OFFSET CHAR_MAX+4 +#define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 /* Gobble to string - stop incrementing c when c[0] match one of the * characters in s */ @@ -159,6 +160,7 @@ char* ip_version = ""; double multiplier = 1.0; char *fmtstr = ""; char buffer[DEFAULT_BUFFER_SIZE]; +bool ignore_mib_parsing_errors = false; static char *fix_snmp_range(char *th) { @@ -306,42 +308,64 @@ main (int argc, char **argv) } /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ - command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); - command_line[0] = snmpcmd; - command_line[1] = strdup ("-Le"); - command_line[2] = strdup ("-t"); - xasprintf (&command_line[3], "%d", timeout_interval); - command_line[4] = strdup ("-r"); - xasprintf (&command_line[5], "%d", retries); - command_line[6] = strdup ("-m"); - command_line[7] = strdup (miblist); - command_line[8] = "-v"; - command_line[9] = strdup (proto); + + unsigned index = 0; + command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); + + command_line[index++] = snmpcmd; + command_line[index++] = strdup ("-Le"); + command_line[index++] = strdup ("-t"); + xasprintf (&command_line[index++], "%d", timeout_interval); + command_line[index++] = strdup ("-r"); + xasprintf (&command_line[index++], "%d", retries); + command_line[index++] = strdup ("-m"); + command_line[index++] = strdup (miblist); + command_line[index++] = "-v"; + command_line[index++] = strdup (proto); + + xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", + snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); + + if (ignore_mib_parsing_errors) { + command_line[index++] = "-Pe"; + xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); + } + for (i = 0; i < numcontext; i++) { - command_line[10 + i] = contextargs[i]; + command_line[index++] = contextargs[i]; } for (i = 0; i < numauthpriv; i++) { - command_line[10 + numcontext + i] = authpriv[i]; + command_line[index++] = authpriv[i]; } - xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); + xasprintf (&command_line[index++], "%s:%s", server_address, port); + + xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", + cl_hidden_auth, + server_address, + port); + + /* This is just for display purposes, so it can remain a string */ + /* xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", server_address, port); + */ for (i = 0; i < numoids; i++) { - command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; + command_line[index++] = oids[i]; xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); } - command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; + command_line[index++] = NULL; - if (verbose) + if (verbose) { printf ("%s\n", cl_hidden_auth); + } /* Set signal handling and alarm */ if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { @@ -708,6 +732,7 @@ process_arguments (int argc, char **argv) {"ipv6", no_argument, 0, '6'}, {"multiplier", required_argument, 0, 'M'}, {"fmtstr", required_argument, 0, 'f'}, + {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, {0, 0, 0, 0} }; @@ -974,6 +999,8 @@ process_arguments (int argc, char **argv) fmtstr=optarg; } break; + case L_IGNORE_MIB_PARSING_ERRORS: + ignore_mib_parsing_errors = true; } } @@ -1307,6 +1334,9 @@ print_help (void) printf (" %s\n", "-O, --perf-oids"); printf (" %s\n", _("Label performance data with OIDs instead of --label's")); + printf (" %s\n", "--ignore-mib-parsing-errors"); + printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); + printf (UT_VERBOSE); printf ("\n"); -- cgit v1.2.3-74-g34f1 From 9e32be80d673cb9bd7877cad8b6e24b99e79e8b0 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Mon, 28 Aug 2023 11:15:59 +0200 Subject: Remove dead, commented code --- plugins/check_snmp.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 43e79a1c..2acada22 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -347,15 +347,6 @@ main (int argc, char **argv) server_address, port); - - - /* This is just for display purposes, so it can remain a string */ - /* - xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", - snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", - server_address, port); - */ - for (i = 0; i < numoids; i++) { command_line[index++] = oids[i]; xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); -- cgit v1.2.3-74-g34f1