diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 9096cdadcadaad29ffc7574cfb706ad61963d670..f04ca85fa2e9fb76f93b8550495c680909b55c50 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
int
main (int argc, char **argv)
{
int
main (int argc, char **argv)
{
- int i;
+ int i, len;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
}else{
snmpcmd = strdup (PATH_TO_SNMPGET);
}
}else{
snmpcmd = strdup (PATH_TO_SNMPGET);
}
-
+
/* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *));
command_line[0] = snmpcmd;
/* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *));
command_line[0] = snmpcmd;
/* This is just for display purposes, so it can remain a string */
asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s",
/* This is just for display purposes, so it can remain a string */
asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s",
- snmpcmd, timeout_interval, retries, miblist, proto, "[authpriv]",
+ snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
server_address, port);
for (i = 0; i < numoids; i++) {
server_address, port);
for (i = 0; i < numoids; i++) {
ptr = chld_out.line[i];
oidname = strpcpy (oidname, ptr, delimiter);
response = strstr (ptr, delimiter);
ptr = chld_out.line[i];
oidname = strpcpy (oidname, ptr, delimiter);
response = strstr (ptr, delimiter);
+ if (response == NULL)
+ break;
+
if (verbose > 2) {
if (verbose > 2) {
- printf("Processing line %i\n line: %s\n oidname: %s\n response: %s\n", i+1, ptr, oidname, response);
+ printf("Processing line %i\n oidname: %s\n response: %s\n", i+1, oidname, response);
}
}
- /* We strip out the datatype indicator for PHBs */
-
/* Clean up type array - Sol10 does not necessarily zero it out */
bzero(type, sizeof(type));
/* Clean up type array - Sol10 does not necessarily zero it out */
bzero(type, sizeof(type));
+ /* We strip out the datatype indicator for PHBs */
if (strstr (response, "Gauge: "))
show = strstr (response, "Gauge: ") + 7;
else if (strstr (response, "Gauge32: "))
if (strstr (response, "Gauge: "))
show = strstr (response, "Gauge: ") + 7;
else if (strstr (response, "Gauge32: "))
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
- if (is_numeric(show)) {
+ /* Write perfdata with whatever can be parsed by strtod, if possible */
+ ptr = NULL;
+ strtod(show, &ptr);
+ if (ptr > show) {
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, show, sizeof(perfstr)-strlen(perfstr)-1);
+ len = sizeof(perfstr)-strlen(perfstr)-1;
+ strncat(perfstr, show, len>ptr-show ? ptr-show : len);
if (type)
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
if (type)
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
*/
needmibs = TRUE;
}
*/
needmibs = TRUE;
}
- oids = calloc(MAX_OIDS, sizeof (char *));
+ if (!oids) oids = calloc(MAX_OIDS, sizeof (char *));
for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) {
oids[j] = strdup(ptr);
}
for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) {
oids[j] = strdup(ptr);
}
if ( needmibs == TRUE ) {
miblist = strdup (DEFAULT_MIBLIST);
}else{
if ( needmibs == TRUE ) {
miblist = strdup (DEFAULT_MIBLIST);
}else{
- miblist = "''"; /* don't read any mib files for numeric oids */
+ miblist = ""; /* don't read any mib files for numeric oids */
}
}
}
}
print_usage ();
print_usage ();
- printf (_(UT_HELP_VRSN));
- printf (_(UT_EXTRA_OPTS));
+ printf (UT_HELP_VRSN);
+ printf (UT_EXTRA_OPTS);
- printf (_(UT_HOST_PORT), 'p', DEFAULT_PORT);
+ printf (UT_HOST_PORT, 'p', DEFAULT_PORT);
/* SNMP and Authentication Protocol */
printf (" %s\n", "-n, --next");
/* SNMP and Authentication Protocol */
printf (" %s\n", "-n, --next");
printf (" %s\n", "-D, --output-delimiter=STRING");
printf (" %s\n", _("Separates output on multiple OID requests"));
printf (" %s\n", "-D, --output-delimiter=STRING");
printf (" %s\n", _("Separates output on multiple OID requests"));
- printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+ printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-e, --retries=INTEGER");
printf (" %s\n", _("Number of retries to be used in the requests"));
printf (" %s\n", "-e, --retries=INTEGER");
printf (" %s\n", _("Number of retries to be used in the requests"));
- printf (_(UT_VERBOSE));
+ printf (UT_VERBOSE);
printf ("\n");
printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
printf ("\n");
printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
printf (" %s\n", _("- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with"));
printf (" %s\n", _("internal spaces must be quoted) [max 8 OIDs]"));
printf (" %s\n", _("- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with"));
printf (" %s\n", _("internal spaces must be quoted) [max 8 OIDs]"));
- printf(" -%s", _(UT_THRESHOLDS_NOTES));
+ printf(" -%s", UT_THRESHOLDS_NOTES);
printf (" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
printf (" %s\n", _("- Note that only one string and one regex may be checked at present"));
printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
printf (" %s\n", _("returned from the SNMP query is an unsigned integer."));
#ifdef NP_EXTRA_OPTS
printf (" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
printf (" %s\n", _("- Note that only one string and one regex may be checked at present"));
printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
printf (" %s\n", _("returned from the SNMP query is an unsigned integer."));
#ifdef NP_EXTRA_OPTS
- printf (" -%s", _(UT_EXTRA_OPTS_NOTES));
+ printf (" -%s", UT_EXTRA_OPTS_NOTES);
#endif
#endif
- printf (_(UT_SUPPORT));
+ printf (UT_SUPPORT);
}
}