New upstream version 2.3.4

This commit is contained in:
Jan Wagner 2023-10-18 07:29:37 +00:00
parent e7bdd1c6c6
commit de72f6f588
556 changed files with 90432 additions and 53391 deletions

View file

@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
#define DEFAULT_PRIV_PROTOCOL "DES"
#define DEFAULT_DELIMITER "="
#define DEFAULT_OUTPUT_DELIMITER " "
#define DEFAULT_BUFFER_SIZE 100
#define mark(a) ((a)!=0?"*":"")
@ -64,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 */
@ -157,6 +159,9 @@ int perf_labels = 1;
char* ip_version = "";
double multiplier = 1.0;
char *fmtstr = "";
bool fmtstr_set = false;
char buffer[DEFAULT_BUFFER_SIZE];
bool ignore_mib_parsing_errors = false;
static char *fix_snmp_range(char *th)
{
@ -304,42 +309,55 @@ 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);
/* 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);
xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s",
cl_hidden_auth,
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) {
@ -420,7 +438,8 @@ main (int argc, char **argv)
}
else if (strstr (response, "INTEGER: ")) {
show = multiply (strstr (response, "INTEGER: ") + 9);
if (fmtstr != "") {
if (fmtstr_set) {
conv = fmtstr;
}
}
@ -594,8 +613,9 @@ main (int argc, char **argv)
len = sizeof(perfstr)-strlen(perfstr)-1;
strncat(perfstr, show, len>ptr-show ? ptr-show : len);
if (type)
if (strcmp(type, "") != 0) {
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
}
if (warning_thresholds) {
strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
@ -706,6 +726,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}
};
@ -853,6 +874,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);
@ -969,8 +991,11 @@ process_arguments (int argc, char **argv)
case 'f':
if (multiplier != 1.0) {
fmtstr=optarg;
fmtstr_set = true;
}
break;
case L_IGNORE_MIB_PARSING_ERRORS:
ignore_mib_parsing_errors = true;
}
}
@ -1169,33 +1194,33 @@ multiply (char *str)
double val;
char *conv = "%f";
if(multiplier == 1)
return(str);
if(verbose>2)
printf(" multiply input: %s\n", str);
val = strtod (str, &endptr);
if ((val == 0.0) && (endptr == str)) {
if(multiplier != 1) {
die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
}
return str;
die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
}
if(verbose>2)
printf(" multiply extracted double: %f\n", val);
val *= multiplier;
if (fmtstr != "") {
if (fmtstr_set) {
conv = fmtstr;
}
if (val == (int)val) {
sprintf(str, "%.0f", val);
snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
} else {
if(verbose>2)
printf(" multiply using format: %s\n", conv);
sprintf(str, conv, val);
snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
}
if(verbose>2)
printf(" multiply result: %s\n", str);
return str;
printf(" multiply result: %s\n", buffer);
return buffer;
}
@ -1272,7 +1297,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");
@ -1304,6 +1329,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");