New upstream version 2.3.3
This commit is contained in:
parent
21323d25dd
commit
e7bdd1c6c6
49 changed files with 13068 additions and 34075 deletions
|
@ -1,31 +1,31 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* Monitoring check_snmp plugin
|
||||
*
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 1999-2007 Monitoring Plugins Development Team
|
||||
*
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
*
|
||||
* This file contains the check_snmp plugin
|
||||
*
|
||||
*
|
||||
* Check status of remote machines and obtain system information via SNMP
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
const char *progname = "check_snmp";
|
||||
|
@ -90,6 +90,7 @@ char *thisarg (char *str);
|
|||
char *nextarg (char *str);
|
||||
void print_usage (void);
|
||||
void print_help (void);
|
||||
char *multiply (char *str);
|
||||
|
||||
#include "regex.h"
|
||||
char regex_expect[MAX_INPUT_BUFFER] = "";
|
||||
|
@ -154,6 +155,8 @@ double *previous_value;
|
|||
size_t previous_size = OID_COUNT_STEP;
|
||||
int perf_labels = 1;
|
||||
char* ip_version = "";
|
||||
double multiplier = 1.0;
|
||||
char *fmtstr = "";
|
||||
|
||||
static char *fix_snmp_range(char *th)
|
||||
{
|
||||
|
@ -316,7 +319,7 @@ main (int argc, char **argv)
|
|||
for (i = 0; i < numcontext; i++) {
|
||||
command_line[10 + i] = contextargs[i];
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < numauthpriv; i++) {
|
||||
command_line[10 + numcontext + i] = authpriv[i];
|
||||
}
|
||||
|
@ -330,7 +333,7 @@ main (int argc, char **argv)
|
|||
|
||||
for (i = 0; i < numoids; i++) {
|
||||
command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i];
|
||||
xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
|
||||
xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
|
||||
}
|
||||
|
||||
command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL;
|
||||
|
@ -398,15 +401,15 @@ main (int argc, char **argv)
|
|||
is_counter=0;
|
||||
/* We strip out the datatype indicator for PHBs */
|
||||
if (strstr (response, "Gauge: ")) {
|
||||
show = strstr (response, "Gauge: ") + 7;
|
||||
}
|
||||
show = multiply (strstr (response, "Gauge: ") + 7);
|
||||
}
|
||||
else if (strstr (response, "Gauge32: ")) {
|
||||
show = strstr (response, "Gauge32: ") + 9;
|
||||
}
|
||||
show = multiply (strstr (response, "Gauge32: ") + 9);
|
||||
}
|
||||
else if (strstr (response, "Counter32: ")) {
|
||||
show = strstr (response, "Counter32: ") + 11;
|
||||
is_counter=1;
|
||||
if(!calculate_rate)
|
||||
if(!calculate_rate)
|
||||
strcpy(type, "c");
|
||||
}
|
||||
else if (strstr (response, "Counter64: ")) {
|
||||
|
@ -416,7 +419,10 @@ main (int argc, char **argv)
|
|||
strcpy(type, "c");
|
||||
}
|
||||
else if (strstr (response, "INTEGER: ")) {
|
||||
show = strstr (response, "INTEGER: ") + 9;
|
||||
show = multiply (strstr (response, "INTEGER: ") + 9);
|
||||
if (fmtstr != "") {
|
||||
conv = fmtstr;
|
||||
}
|
||||
}
|
||||
else if (strstr (response, "OID: ")) {
|
||||
show = strstr (response, "OID: ") + 5;
|
||||
|
@ -616,7 +622,7 @@ main (int argc, char **argv)
|
|||
state_string=malloc(string_length);
|
||||
if(state_string==NULL)
|
||||
die(STATE_UNKNOWN, _("Cannot malloc"));
|
||||
|
||||
|
||||
current_length=0;
|
||||
for(i=0; i<total_oids; i++) {
|
||||
xasprintf(&temp_string,"%.0f",response_value[i]);
|
||||
|
@ -638,7 +644,7 @@ main (int argc, char **argv)
|
|||
state_string[--current_length]='\0';
|
||||
if (verbose > 2)
|
||||
printf("State string=%s\n",state_string);
|
||||
|
||||
|
||||
/* This is not strictly the same as time now, but any subtle variations will cancel out */
|
||||
np_state_write_string(current_time, state_string );
|
||||
if(previous_state==NULL) {
|
||||
|
@ -698,6 +704,8 @@ process_arguments (int argc, char **argv)
|
|||
{"perf-oids", no_argument, 0, 'O'},
|
||||
{"ipv4", no_argument, 0, '4'},
|
||||
{"ipv6", no_argument, 0, '6'},
|
||||
{"multiplier", required_argument, 0, 'M'},
|
||||
{"fmtstr", required_argument, 0, 'f'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -715,7 +723,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:z:",
|
||||
c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:",
|
||||
longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
|
@ -953,6 +961,16 @@ process_arguments (int argc, char **argv)
|
|||
if(verbose>2)
|
||||
printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n");
|
||||
break;
|
||||
case 'M':
|
||||
if ( strspn( optarg, "0123456789.," ) == strlen( optarg ) ) {
|
||||
multiplier=strtod(optarg,NULL);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (multiplier != 1.0) {
|
||||
fmtstr=optarg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,7 +1040,7 @@ validate_arguments ()
|
|||
contextargs[0] = strdup ("-n");
|
||||
contextargs[1] = strdup (context);
|
||||
}
|
||||
|
||||
|
||||
if (seclevel == NULL)
|
||||
xasprintf(&seclevel, "noAuthNoPriv");
|
||||
|
||||
|
@ -1143,6 +1161,44 @@ nextarg (char *str)
|
|||
|
||||
|
||||
|
||||
/* multiply result (values 0 < n < 1 work as divider) */
|
||||
char *
|
||||
multiply (char *str)
|
||||
{
|
||||
char *endptr;
|
||||
double val;
|
||||
char *conv = "%f";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(verbose>2)
|
||||
printf(" multiply extracted double: %f\n", val);
|
||||
val *= multiplier;
|
||||
if (fmtstr != "") {
|
||||
conv = fmtstr;
|
||||
}
|
||||
if (val == (int)val) {
|
||||
sprintf(str, "%.0f", val);
|
||||
} else {
|
||||
if(verbose>2)
|
||||
printf(" multiply using format: %s\n", conv);
|
||||
sprintf(str, conv, val);
|
||||
}
|
||||
if(verbose>2)
|
||||
printf(" multiply result: %s\n", str);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
print_help (void)
|
||||
{
|
||||
|
@ -1235,6 +1291,10 @@ print_help (void)
|
|||
printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
|
||||
printf (" %s\n", "-D, --output-delimiter=STRING");
|
||||
printf (" %s\n", _("Separates output on multiple OID requests"));
|
||||
printf (" %s\n", "-M, --multiplier=FLOAT");
|
||||
printf (" %s\n", _("Multiplies current value, 0 < n < 1 works as divider, defaults to 1"));
|
||||
printf (" %s\n", "-f, --fmtstr=STRING");
|
||||
printf (" %s\n", _("C-style format string for float values (see option -M)"));
|
||||
|
||||
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5"));
|
||||
|
@ -1287,4 +1347,5 @@ print_usage (void)
|
|||
printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
|
||||
printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
|
||||
printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n");
|
||||
printf ("[-M multiplier [-f format]]\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue