[Nagiosplug-checkins] CVS: nagiosplug/plugins check_smtp.c,1.23,1.24
Karl DeBisschop
kdebisschop at users.sourceforge.net
Sun Feb 29 22:27:05 CET 2004
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26454/plugins
Modified Files:
check_smtp.c
Log Message:
allow regex for ecpect checks
Index: check_smtp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_smtp.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** check_smtp.c 28 Feb 2004 06:51:43 -0000 1.23
--- check_smtp.c 1 Mar 2004 06:15:59 -0000 1.24
***************
*** 38,41 ****
--- 38,53 ----
void print_usage (void);
+ #ifdef HAVE_REGEX_H
+ #include <regex.h>
+ char regex_expect[MAX_INPUT_BUFFER] = "";
+ regex_t preg;
+ regmatch_t pmatch[10];
+ char timestamp[10] = "";
+ char errbuf[MAX_INPUT_BUFFER];
+ int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
+ int eflags = 0;
+ int errcode, excode;
+ #endif
+
int server_port = SMTP_PORT;
char *server_address = NULL;
***************
*** 161,167 ****
printf("%s", buffer);
strip (buffer);
! if (n < nresponses && strstr(buffer, responses[n])!=buffer) {
! result = STATE_WARNING;
! printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
}
n++;
--- 173,206 ----
printf("%s", buffer);
strip (buffer);
! if (n < nresponses) {
! #ifdef HAVE_REGEX_H
! cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
! //strncpy (regex_expect, responses[n], sizeof (regex_expect) - 1);
! //regex_expect[sizeof (regex_expect) - 1] = '\0';
! errcode = regcomp (&preg, responses[n], cflags);
! if (errcode != 0) {
! regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
! printf (_("Could Not Compile Regular Expression"));
! return ERROR;
! }
! excode = regexec (&preg, buffer, 10, pmatch, eflags);
! if (excode == 0) {
! result = STATE_OK;
! }
! else if (excode == REG_NOMATCH) {
! result = STATE_WARNING;
! printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
! }
! else {
! regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
! printf (_("Execute Error: %s\n"), errbuf);
! result = STATE_UNKNOWN;
! }
! #else
! if (strstr(buffer, responses[n])!=buffer) {
! result = STATE_WARNING;
! printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
! }
! #endif
}
n++;
More information about the Commits
mailing list