summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_tcp.c4
-rw-r--r--plugins/netutils.c23
2 files changed, 18 insertions, 9 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 7bd48d1a..55ce8984 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -206,6 +206,7 @@ main (int argc, char **argv)
206 server_port = PORT; 206 server_port = PORT;
207 server_send = SEND; 207 server_send = SEND;
208 server_quit = QUIT; 208 server_quit = QUIT;
209 status = strdup ("");
209 210
210 if (process_arguments (argc, argv) == ERROR) 211 if (process_arguments (argc, argv) == ERROR)
211 usage (_("Could not parse arguments\n")); 212 usage (_("Could not parse arguments\n"));
@@ -259,7 +260,6 @@ main (int argc, char **argv)
259 260
260 buffer = malloc (MAXBUF); 261 buffer = malloc (MAXBUF);
261 memset (buffer, '\0', MAXBUF); 262 memset (buffer, '\0', MAXBUF);
262 status = strdup ("");
263 /* watch for the expect string */ 263 /* watch for the expect string */
264 while ((i = my_recv ()) > 0) { 264 while ((i = my_recv ()) > 0) {
265 buffer[i] = '\0'; 265 buffer[i] = '\0';
@@ -271,7 +271,7 @@ main (int argc, char **argv)
271 } 271 }
272 272
273 /* return a CRITICAL status if we couldn't read any data */ 273 /* return a CRITICAL status if we couldn't read any data */
274 if (status == NULL) 274 if (strlen(status) == 0)
275 die (STATE_CRITICAL, _("No data received from host\n")); 275 die (STATE_CRITICAL, _("No data received from host\n"));
276 276
277 strip (status); 277 strip (status);
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 5017eb9e..1fa69a35 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -252,11 +252,7 @@ my_connect (const char *host_name, int port, int *sd, int proto)
252 if (result < 0) { 252 if (result < 0) {
253 switch (errno) { 253 switch (errno) {
254 case ECONNREFUSED: 254 case ECONNREFUSED:
255 switch (econn_refuse_state) { 255 was_refused = TRUE;
256 case STATE_OK:
257 case STATE_WARNING:
258 was_refused = TRUE;
259 }
260 break; 256 break;
261 } 257 }
262 } 258 }
@@ -269,8 +265,21 @@ my_connect (const char *host_name, int port, int *sd, int proto)
269 265
270 if (result == 0) 266 if (result == 0)
271 return STATE_OK; 267 return STATE_OK;
272 else if (was_refused) 268 else if (was_refused) {
273 return econn_refuse_state; 269 switch (econn_refuse_state) { /* a user-defined expected outcome */
270 case STATE_OK:
271 case STATE_WARNING: /* user wants WARN or OK on refusal */
272 return econn_refuse_state;
273 break;
274 case STATE_CRITICAL: /* user did not set econn_refuse_state */
275 printf ("%s\n", strerror(errno));
276 return econn_refuse_state;
277 break;
278 default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
279 return STATE_UNKNOWN;
280 break;
281 }
282 }
274 else { 283 else {
275 printf ("%s\n", strerror(errno)); 284 printf ("%s\n", strerror(errno));
276 return STATE_CRITICAL; 285 return STATE_CRITICAL;