aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2004-03-01 06:15:59 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2004-03-01 06:15:59 +0000
commitf7c1eca1c45f77df548e426281569e0c7c0a6480 (patch)
treed2495e34c4f1958cff0813e8baa0a52b0dc35b82 /plugins/check_smtp.c
parentdc8f5c0f658b5e060fc17a4beb4a0a2b195ba470 (diff)
downloadmonitoring-plugins-f7c1eca1c45f77df548e426281569e0c7c0a6480.tar.gz
allow regex for ecpect checks
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@832 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r--plugins/check_smtp.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 09f8f143..8f9ec8bb 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -37,6 +37,18 @@ int validate_arguments (void);
void print_help (void);
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;
char *server_expect = NULL;
@@ -160,9 +172,36 @@ main (int argc, char **argv)
if (verbose)
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]);
+ 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++;
}