[Nagiosplug-checkins] CVS: nagiosplug/plugins check_snmp.c,1.19,1.20
Karl DeBisschop
kdebisschop at users.sourceforge.net
Fri Nov 15 21:00:03 CET 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv27222/plugins
Modified Files:
check_snmp.c
Log Message:
my take on Subhendu's patches, plus a few comments for clarity
Index: check_snmp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_snmp.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** check_snmp.c 15 Nov 2002 17:47:03 -0000 1.19
--- check_snmp.c 16 Nov 2002 04:59:35 -0000 1.20
***************
*** 176,180 ****
char *server_address = NULL;
! char *community = NULL;
char *authpriv = NULL;
char *proto = NULL;
--- 176,180 ----
char *server_address = NULL;
! char *community = DEFAULT_COMMUNITY;
char *authpriv = NULL;
char *proto = NULL;
***************
*** 185,190 ****
char *privpasswd = NULL;
char *oid = "";
! char *label = NULL;
! char *units = NULL;
char *port = DEFAULT_PORT;
char string_value[MAX_INPUT_BUFFER] = "";
--- 185,190 ----
char *privpasswd = NULL;
char *oid = "";
! char *label = "SNMP";
! char *units = "";
char *port = DEFAULT_PORT;
char string_value[MAX_INPUT_BUFFER] = "";
***************
*** 204,210 ****
int check_critical_value = FALSE;
int eval_method[MAX_OIDS];
! char *delimiter = NULL;
! char *output_delim = NULL;
! char *miblist = NULL;
--- 204,210 ----
int check_critical_value = FALSE;
int eval_method[MAX_OIDS];
! char *delimiter = DEFAULT_DELIMITER;
! char *output_delim = DEFAULT_OUTPUT_DELIMITER;
! char *miblist = DEFAULT_MIBLIST;
***************
*** 220,224 ****
char *response = NULL;
char *outbuff = "";
! char *output = NULL;
char *ptr = NULL;
char *p2 = NULL;
--- 220,224 ----
char *response = NULL;
char *outbuff = "";
! char *output = "";
char *ptr = NULL;
char *p2 = NULL;
***************
*** 252,256 ****
}
- asprintf (&output, "");
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
asprintf (&output, "%s%s", output, input_buffer);
--- 252,255 ----
***************
*** 294,297 ****
--- 293,297 ----
}
+ /* We strip out the datatype indicator for PHBs */
if (strstr (response, "Gauge: "))
show = strstr (response, "Gauge: ") + 7;
***************
*** 306,315 ****
iresult = STATE_DEPENDENT;
! if (eval_method[i] & CRIT_PRESENT) {
! iresult = STATE_CRITICAL;
! } else if (eval_method[i] & WARN_PRESENT) {
! iresult = STATE_WARNING;
! }
!
if (eval_method[i] & CRIT_GT ||
eval_method[i] & CRIT_LT ||
--- 306,310 ----
iresult = STATE_DEPENDENT;
! /* Process this block for integer comparisons */
if (eval_method[i] & CRIT_GT ||
eval_method[i] & CRIT_LT ||
***************
*** 328,334 ****
iresult = check_num (i);
asprintf (&show, "%lu", response_value[i]);
- /*asprintf (&show, "%s", response); */
}
else if (eval_method[i] & CRIT_STRING) {
if (strcmp (response, string_value))
--- 323,329 ----
iresult = check_num (i);
asprintf (&show, "%lu", response_value[i]);
}
+ /* Process this block for string matching */
else if (eval_method[i] & CRIT_STRING) {
if (strcmp (response, string_value))
***************
*** 338,341 ****
--- 333,337 ----
}
+ /* Process this block for regex matching */
else if (eval_method[i] & CRIT_REGEX) {
#ifdef HAVE_REGEX_H
***************
*** 353,371 ****
}
#else
! printf ("SNMP UNKNOWN: call for regex which was not a compiled option");
exit (STATE_UNKNOWN);
#endif
}
else {
! if (response && iresult == STATE_DEPENDENT)
! iresult = STATE_OK;
! else if (eval_method[i] & CRIT_PRESENT)
iresult = STATE_CRITICAL;
else if (eval_method[i] & WARN_PRESENT)
iresult = STATE_WARNING;
}
result = max_state (result, iresult);
if (nlabels > 1 && i < nlabels && labels[i] != NULL)
asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
--- 349,371 ----
}
#else
! printf ("%s UNKNOWN: call for regex which was not a compiled option", label);
exit (STATE_UNKNOWN);
#endif
}
+
+ /* Process this block for existence-nonexistence checks */
else {
! if (eval_method[i] & CRIT_PRESENT)
iresult = STATE_CRITICAL;
else if (eval_method[i] & WARN_PRESENT)
iresult = STATE_WARNING;
+ else if (response && iresult == STATE_DEPENDENT)
+ iresult = STATE_OK;
}
+ /* Result is the worst outcome of all the OIDs tested */
result = max_state (result, iresult);
+ /* Prepend a label for this OID if there is one */
if (nlabels > 1 && i < nlabels && labels[i] != NULL)
asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
***************
*** 376,380 ****
mark (iresult), show, mark (iresult));
! if (nunits > 0 && i < nunits)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
--- 376,381 ----
mark (iresult), show, mark (iresult));
! /* Append a unit string for this OID if there is one */
! if (nunits > 0 && i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
***************
*** 414,418 ****
char *ptr;
int c = 1;
! int j = 0, jj = 0;
#ifdef HAVE_GETOPT_H
--- 415,419 ----
char *ptr;
int c = 1;
! int j = 0, jj = 0, ii = 0;
#ifdef HAVE_GETOPT_H
***************
*** 480,483 ****
--- 481,516 ----
verbose = TRUE;
break;
+
+ /* Connection info */
+ case 'C': /* group or community */
+ community = strscpy (community, optarg);
+ break;
+ case 'H': /* Host or server */
+ server_address = strscpy (server_address, optarg);
+ break;
+ case 'p': /* TCP port number */
+ port = strscpy(port, optarg);
+ break;
+ case 'm': /* List of MIBS */
+ miblist = strscpy(miblist, optarg);
+ break;
+ case 'P': /* SNMP protocol version */
+ proto = strscpy(proto, optarg);
+ break;
+ case 'L': /* security level */
+ seclevel = strscpy(seclevel,optarg);
+ break;
+ case 'U': /* security username */
+ secname = strscpy(secname, optarg);
+ break;
+ case 'a': /* auth protocol */
+ asprintf (&authproto, optarg);
+ break;
+ case 'A': /* auth passwd */
+ authpasswd = strscpy(authpasswd, optarg);
+ break;
+ case 'X': /* priv passwd */
+ privpasswd = strscpy(privpasswd, optarg);
+ break;
case 't': /* timeout period */
if (!is_integer (optarg))
***************
*** 485,504 ****
timeout_interval = atoi (optarg);
break;
! case 'e': /* PRELIMINARY - may change */
! eval_method[j] |= WARN_PRESENT;
! for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
! ptr[0] = ' '; /* relpace comma with space */
! for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
! eval_method[++j] |= WARN_PRESENT;
! asprintf (&oid, "%s %s", (oid?oid:""), optarg);
! break;
! case 'E': /* PRELIMINARY - may change */
! eval_method[j] |= WARN_PRESENT;
! for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
! ptr[0] = ' '; /* relpace comma with space */
! for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
! eval_method[++j] |= CRIT_PRESENT;
! asprintf (&oid, "%s %s", (oid?oid:""), optarg);
! break;
case 'c': /* critical time threshold */
if (strspn (optarg, "0123456789:,") < strlen (optarg)) {
--- 518,523 ----
timeout_interval = atoi (optarg);
break;
!
! /* Test parameters */
case 'c': /* critical time threshold */
if (strspn (optarg, "0123456789:,") < strlen (optarg)) {
***************
*** 507,511 ****
exit (STATE_UNKNOWN);
}
! for (ptr = optarg, jj = 0; ptr && jj < MAX_OIDS; jj++) {
if (lu_getll (&lower_crit_lim[jj], ptr) == 1)
eval_method[jj] |= CRIT_LT;
--- 526,530 ----
exit (STATE_UNKNOWN);
}
! for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) {
if (lu_getll (&lower_crit_lim[jj], ptr) == 1)
eval_method[jj] |= CRIT_LT;
***************
*** 521,539 ****
exit (STATE_UNKNOWN);
}
! for (ptr = optarg, jj = 0; ptr && jj < MAX_OIDS; jj++) {
! if (lu_getll (&lower_warn_lim[jj], ptr) == 1)
! eval_method[jj] |= WARN_LT;
! if (lu_getul (&upper_warn_lim[jj], ptr) == 1)
! eval_method[jj] |= WARN_GT;
(ptr = index (ptr, ',')) ? ptr++ : ptr;
}
break;
- case 'H': /* Host or server */
- server_address = strscpy (server_address, optarg);
- break;
- case 'C': /* group or community */
- community = strscpy (community, optarg);
- break;
case 'o': /* object identifier */
for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
ptr[0] = ' '; /* relpace comma with space */
--- 540,554 ----
exit (STATE_UNKNOWN);
}
! for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) {
! if (lu_getll (&lower_warn_lim[ii], ptr) == 1)
! eval_method[ii] |= WARN_LT;
! if (lu_getul (&upper_warn_lim[ii], ptr) == 1)
! eval_method[ii] |= WARN_GT;
(ptr = index (ptr, ',')) ? ptr++ : ptr;
}
break;
case 'o': /* object identifier */
+ case 'e': /* PRELIMINARY - may change */
+ case 'E': /* PRELIMINARY - may change */
for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
ptr[0] = ' '; /* relpace comma with space */
***************
*** 541,555 ****
j++; /* count OIDs */
asprintf (&oid, "%s %s", (oid?oid:""), optarg);
! break;
! case 'd': /* delimiter */
! delimiter = strscpy (delimiter, optarg);
! break;
! case 'D': /* output-delimiter */
! output_delim = strscpy (output_delim, optarg);
break;
case 's': /* string or substring */
strncpy (string_value, optarg, sizeof (string_value) - 1);
string_value[sizeof (string_value) - 1] = 0;
! eval_method[jj] = CRIT_STRING;
break;
case 'R': /* regex */
--- 556,573 ----
j++; /* count OIDs */
asprintf (&oid, "%s %s", (oid?oid:""), optarg);
! if (c == 'E' || c == 'e') {
! jj++;
! ii++;
! }
! if (c == 'E')
! eval_method[j+1] |= WARN_PRESENT;
! else if (c == 'e')
! eval_method[j+1] |= CRIT_PRESENT;
break;
case 's': /* string or substring */
strncpy (string_value, optarg, sizeof (string_value) - 1);
string_value[sizeof (string_value) - 1] = 0;
! eval_method[jj++] = CRIT_STRING;
! ii++;
break;
case 'R': /* regex */
***************
*** 568,577 ****
return ERROR;
}
! eval_method[jj] = CRIT_REGEX;
#else
! printf ("SNMP UNKNOWN: call for regex which was not a compiled option");
exit (STATE_UNKNOWN);
#endif
break;
case 'l': /* label */
label = optarg;
--- 586,604 ----
return ERROR;
}
! eval_method[jj++] = CRIT_REGEX;
! ii++;
#else
! printf ("%s UNKNOWN: call for regex which was not a compiled option", label);
exit (STATE_UNKNOWN);
#endif
break;
+
+ /* Format */
+ case 'd': /* delimiter */
+ delimiter = strscpy (delimiter, optarg);
+ break;
+ case 'D': /* output-delimiter */
+ output_delim = strscpy (output_delim, optarg);
+ break;
case 'l': /* label */
label = optarg;
***************
*** 636,663 ****
}
break;
- case 'p': /* TCP port number */
- port = strscpy(port, optarg);
- break;
- case 'm': /* List of MIBS */
- miblist = strscpy(miblist, optarg);
- break;
- case 'P': /* SNMP protocol version */
- proto = strscpy(proto, optarg);
- break;
- case 'L': /* security level */
- seclevel = strscpy(seclevel,optarg);
- break;
- case 'U': /* security username */
- secname = strscpy(secname, optarg);
- break;
- case 'a': /* auth protocol */
- asprintf (&authproto, optarg);
- break;
- case 'A': /* auth passwd */
- authpasswd = strscpy(authpasswd, optarg);
- break;
- case 'X': /* priv passwd */
- privpasswd = strscpy(privpasswd, optarg);
- break;
}
--- 663,666 ----
***************
*** 693,714 ****
validate_arguments ()
{
-
- if (community == NULL)
- asprintf (&community, DEFAULT_COMMUNITY);
-
- if (delimiter == NULL)
- asprintf (&delimiter, DEFAULT_DELIMITER);
-
- if (output_delim == NULL)
- asprintf (&output_delim, DEFAULT_OUTPUT_DELIMITER);
-
- if (miblist == NULL)
- asprintf (&miblist, DEFAULT_MIBLIST);
-
- if (label == NULL)
- asprintf (&label, "SNMP");
-
- if (units == NULL)
- asprintf (&units, "");
/* Need better checks to verify seclevel and authproto choices */
--- 696,699 ----
More information about the Commits
mailing list