summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-03-07 07:17:26 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-03-07 07:17:26 (GMT)
commit259bf73dd93d79a3e81cc4f54e38b687371d40d3 (patch)
tree3b62783cfdac67a1b2dbf1499f54c9d5fb2ef5d1 /plugins
parent266ca0944bfb0e1de865dab85a9b7e58f2f3af37 (diff)
downloadmonitoring-plugins-259bf73dd93d79a3e81cc4f54e38b687371d40d3.tar.gz
whole timer loop was on the wrong side of connection close code
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/branches/release-1.3.0@373 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_smtp.c51
1 files changed, 18 insertions, 33 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index de382ac..8c0a246 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -79,7 +79,7 @@ int
79main (int argc, char **argv) 79main (int argc, char **argv)
80{ 80{
81 int sd; 81 int sd;
82 int result; 82 int result = STATE_UNKNOWN;
83 char buffer[MAX_INPUT_BUFFER] = ""; 83 char buffer[MAX_INPUT_BUFFER] = "";
84 char *from_str = NULL; 84 char *from_str = NULL;
85 char *helocmd = NULL; 85 char *helocmd = NULL;
@@ -114,20 +114,15 @@ main (int argc, char **argv)
114 /* we connected, so close connection before exiting */ 114 /* we connected, so close connection before exiting */
115 if (result == STATE_OK) { 115 if (result == STATE_OK) {
116 116
117 /* watch for the SMTP connection string */ 117 /* watch for the SMTP connection string and */
118 result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);
119
120 /* strip the buffer of carriage returns */
121 strip (buffer);
122
123 /* return a WARNING status if we couldn't read any data */ 118 /* return a WARNING status if we couldn't read any data */
124 if (result == -1) { 119 if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) {
125 printf ("recv() failed\n"); 120 printf ("recv() failed\n");
126 result = STATE_WARNING; 121 result = STATE_WARNING;
127 } 122 }
128
129 else { 123 else {
130 124 /* strip the buffer of carriage returns */
125 strip (buffer);
131 /* make sure we find the response we are looking for */ 126 /* make sure we find the response we are looking for */
132 if (!strstr (buffer, server_expect)) { 127 if (!strstr (buffer, server_expect)) {
133 if (server_port == SMTP_PORT) 128 if (server_port == SMTP_PORT)
@@ -137,30 +132,9 @@ main (int argc, char **argv)
137 server_port); 132 server_port);
138 result = STATE_WARNING; 133 result = STATE_WARNING;
139 } 134 }
140
141 else {
142
143 time (&end_time);
144
145 result = STATE_OK;
146
147 if (check_critical_time == TRUE
148 && (end_time - start_time) > critical_time) result =
149 STATE_CRITICAL;
150 else if (check_warning_time == TRUE
151 && (end_time - start_time) > warning_time) result =
152 STATE_WARNING;
153
154 if (verbose == TRUE)
155 printf ("SMTP %s - %d sec. response time, %s\n",
156 state_text (result), (int) (end_time - start_time), buffer);
157
158 }
159 } 135 }
160 136
161 /* close the connection */ 137 /* send the HELO command */
162
163 /* first send the HELO command */
164 send(sd, helocmd, strlen(helocmd), 0); 138 send(sd, helocmd, strlen(helocmd), 0);
165 139
166 /* allow for response to helo command to reach us */ 140 /* allow for response to helo command to reach us */
@@ -186,7 +160,18 @@ main (int argc, char **argv)
186 /* reset the alarm */ 160 /* reset the alarm */
187 alarm (0); 161 alarm (0);
188 162
189 printf ("SMTP %s - %d second response time\n", state_text (result), (int) (end_time - start_time)); 163 time (&end_time);
164
165 if (check_critical_time == TRUE && (end_time - start_time) > critical_time)
166 result = STATE_CRITICAL;
167 else if (check_warning_time == TRUE && (end_time - start_time) > warning_time)
168 result = STATE_WARNING;
169
170 if (verbose == TRUE)
171 printf ("SMTP %s - %d sec. response time, %s\n",
172 state_text (result), (int) (end_time - start_time), buffer);
173 else
174 printf ("SMTP %s - %d second response time\n", state_text (result), (int) (end_time - start_time));
190 175
191 return result; 176 return result;
192} 177}