summaryrefslogtreecommitdiffstats
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)
commit2ab504386c324a382c83495c991cb60747d0950d (patch)
treed14d3785eb214310ff33cb0d684d697477e7a0fd
parent7f01b73f181d63350cd9634ff9ef022c1edb16a8 (diff)
downloadmonitoring-plugins-2ab504386c324a382c83495c991cb60747d0950d.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/trunk@373 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_smtp.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index d8b9059..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,32 +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 else
158 printf ("SMTP %s - %d second response time\n", state_text (result),
159 (int) (end_time - start_time));
160 }
161 } 135 }
162 136
163 /* close the connection */ 137 /* send the HELO command */
164
165 /* first send the HELO command */
166 send(sd, helocmd, strlen(helocmd), 0); 138 send(sd, helocmd, strlen(helocmd), 0);
167 139
168 /* allow for response to helo command to reach us */ 140 /* allow for response to helo command to reach us */
@@ -188,6 +160,19 @@ main (int argc, char **argv)
188 /* reset the alarm */ 160 /* reset the alarm */
189 alarm (0); 161 alarm (0);
190 162
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));
175
191 return result; 176 return result;
192} 177}
193 178