Index: nagiosplug/plugins/check_tcp.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_tcp.c,v retrieving revision 1.10 diff -u -r1.10 check_tcp.c --- nagiosplug/plugins/check_tcp.c 19 Dec 2002 19:30:52 -0000 1.10 +++ nagiosplug/plugins/check_tcp.c 30 Dec 2002 23:07:44 -0000 @@ -307,9 +307,11 @@ alarm (0); printf - ("%s %s - %7.3f second response time on port %d", + ("%s %s%s - %7.3f second response time on port %d", SERVICE, - state_text (result), elapsed_time, server_port); + state_text (result), + (was_refused)?" (refused)":"", + elapsed_time, server_port); if (status && strlen(status) > 0) printf (" [%s]", status); @@ -346,6 +348,7 @@ {"expect", required_argument, 0, 'e'}, {"quit", required_argument, 0, 'q'}, {"delay", required_argument, 0, 'd'}, + {"refuse", required_argument, 0, 'r'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, @@ -376,10 +379,10 @@ while (1) { #ifdef HAVE_GETOPT_H c = - getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S", long_options, + getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:Sr:", long_options, &option_index); #else - c = getopt (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S"); + c = getopt (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:Sr:"); #endif if (c == -1 || c == EOF || c == 1) @@ -448,6 +451,16 @@ case 'q': server_quit = optarg; break; + case 'r': + if (!strncmp(optarg,"ok",2)) + econn_refuse_state = STATE_OK; + else if (!strncmp(optarg,"warn",4)) + econn_refuse_state = STATE_WARNING; + else if (!strncmp(optarg,"crit",4)) + econn_refuse_state = STATE_CRITICAL; + else + usage ("Refuse mut be one of ok, warn, crit\n"); + break; case 'd': if (is_intpos (optarg)) delay = atoi (optarg); @@ -479,7 +492,8 @@ { printf ("Usage: %s -H host -p port [-w warn_time] [-c crit_time] [-s send]\n" - " [-e expect] [-W wait] [-t to_sec] [-v]\n", PROGNAME); + " [-e expect] [-W wait] [-t to_sec] [-R refuse_state] [-v]\n", + PROGNAME); } @@ -514,6 +528,8 @@ " Response time to result in critical status (seconds)\n" " -t, --timeout=INTEGER\n" " Seconds before connection times out (default: %d)\n" + " -r, --refuse=ok|warn|crit\n" + " Accept tcp refusals with states ok,warn, crit (default: crit)\n" " -v" " Show details for command-line debugging (do not use with nagios server)\n" " -h, --help\n" @@ -549,7 +565,7 @@ time (&start_time); /* Make TCP connection */ - if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK) + if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK && was_refused == FALSE) { /* Do the SSL handshake */ if ((ssl = SSL_new (ctx)) != NULL) Index: nagiosplug/plugins/netutils.c =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 netutils.c --- nagiosplug/plugins/netutils.c 28 Feb 2002 06:42:59 -0000 1.1.1.1 +++ nagiosplug/plugins/netutils.c 30 Dec 2002 23:07:44 -0000 @@ -39,6 +39,9 @@ extern int socket_timeout; RETSIGTYPE socket_timeout_alarm_handler (int); +extern int econn_refuse_state; +extern int was_refused; + int process_tcp_request2 (char *, int, char *, char *, int); int process_tcp_request (char *, int, char *, char *, int); int process_udp_request (char *, int, char *, char *, int); @@ -307,7 +310,14 @@ if (result < 0) { switch (errno) { case ECONNREFUSED: - printf ("Connection refused by host\n"); + switch (econn_refuse_state) { + case STATE_OK: + case STATE_WARNING: + was_refused = TRUE; + return econn_refuse_state; + default: + printf ("Connection refused by host\n"); + } break; case ETIMEDOUT: printf ("Timeout while attempting connection\n"); @@ -316,7 +326,7 @@ printf ("Network is unreachable\n"); break; default: - printf ("Connection refused or timed out\n"); + printf ("Connection refused or timed out: %s\n",strerror (errno)); } return STATE_CRITICAL; Index: nagiosplug/plugins/netutils.h.in =================================================================== RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/netutils.h.in,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 netutils.h.in --- nagiosplug/plugins/netutils.h.in 28 Feb 2002 06:42:59 -0000 1.1.1.1 +++ nagiosplug/plugins/netutils.h.in 30 Dec 2002 23:07:44 -0000 @@ -61,3 +61,5 @@ #include "common.h" #endif int socket_timeout = DEFAULT_SOCKET_TIMEOUT; +int econn_refuse_state = STATE_CRITICAL; +int was_refused = FALSE;