1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
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;
|