summaryrefslogtreecommitdiffstats
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2004-03-01 06:15:59 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2004-03-01 06:15:59 (GMT)
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 09f8f14..8f9ec8b 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -37,6 +37,18 @@ int validate_arguments (void);
37void print_help (void); 37void print_help (void);
38void print_usage (void); 38void print_usage (void);
39 39
40#ifdef HAVE_REGEX_H
41#include <regex.h>
42char regex_expect[MAX_INPUT_BUFFER] = "";
43regex_t preg;
44regmatch_t pmatch[10];
45char timestamp[10] = "";
46char errbuf[MAX_INPUT_BUFFER];
47int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
48int eflags = 0;
49int errcode, excode;
50#endif
51
40int server_port = SMTP_PORT; 52int server_port = SMTP_PORT;
41char *server_address = NULL; 53char *server_address = NULL;
42char *server_expect = NULL; 54char *server_expect = NULL;
@@ -160,9 +172,36 @@ main (int argc, char **argv)
160 if (verbose) 172 if (verbose)
161 printf("%s", buffer); 173 printf("%s", buffer);
162 strip (buffer); 174 strip (buffer);
163 if (n < nresponses && strstr(buffer, responses[n])!=buffer) { 175 if (n < nresponses) {
164 result = STATE_WARNING; 176#ifdef HAVE_REGEX_H
165 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]); 177 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
178 //strncpy (regex_expect, responses[n], sizeof (regex_expect) - 1);
179 //regex_expect[sizeof (regex_expect) - 1] = '\0';
180 errcode = regcomp (&preg, responses[n], cflags);
181 if (errcode != 0) {
182 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
183 printf (_("Could Not Compile Regular Expression"));
184 return ERROR;
185 }
186 excode = regexec (&preg, buffer, 10, pmatch, eflags);
187 if (excode == 0) {
188 result = STATE_OK;
189 }
190 else if (excode == REG_NOMATCH) {
191 result = STATE_WARNING;
192 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
193 }
194 else {
195 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
196 printf (_("Execute Error: %s\n"), errbuf);
197 result = STATE_UNKNOWN;
198 }
199#else
200 if (strstr(buffer, responses[n])!=buffer) {
201 result = STATE_WARNING;
202 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
203 }
204#endif
166 } 205 }
167 n++; 206 n++;
168 } 207 }