summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: df6b077)
raw | patch | inline | side by side (parent: df6b077)
author | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Sun, 16 Mar 2003 23:28:49 +0000 (23:28 +0000) | ||
committer | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Sun, 16 Mar 2003 23:28:49 +0000 (23:28 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@426 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_tcp.c | patch | blob | history | |
plugins/netutils.c | patch | blob | history | |
plugins/netutils.h | patch | blob | history |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 7d1155136c74f95f43e81313ad6512ff54d33809..5bec2915108cb52f66a44cc5b954791cce462a63 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
const char *option_summary = "\
-H host -p port [-w warn_time] [-c crit_time] [-s send]\n\
- [-e expect] [-W wait] [-t to_sec] [-v]\n";
+ [-e expect] [-W wait] [-t to_sec] [-r refuse_state] [-v]\n";
const char *options = "\
-H, --hostname=ADDRESS\n\
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\n\
Show details for command-line debugging (do not use with nagios server)\n\
-h, --help\n\
alarm (0);
printf
- ("%s %s - %.3f second response time on port %d",
+ ("%s %s%s - %.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);
{"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'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S", long_options,
+ c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:Sr:", long_options,
&option_index);
if (c == -1 || c == EOF || c == 1)
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);
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)
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 4234c4364d333f1cb00b39ad2954a60fed09da62..b3348d6ede0ad5c38e27f75697a0dedba5dc0c2d 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
#include "netutils.h"
int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
+int econn_refuse_state = STATE_CRITICAL;
+int was_refused = FALSE;
/* handles socket timeouts */
void
/* attempt to open a connection */
result = connect (*sd, res->ai_addr, res->ai_addrlen);
- if (result == 0)
+ if (result == 0) {
+ was_refused = FALSE;
break;
+ }
+
+ if (result < 0) {
+ switch (errno) {
+ case ECONNREFUSED:
+ switch (econn_refuse_state) {
+ case STATE_OK:
+ case STATE_WARNING:
+ was_refused = TRUE;
+ }
+ break;
+ }
+ }
close (*sd);
res = res->ai_next;
if (result == 0)
return STATE_OK;
+ else if (was_refused)
+ return econn_refuse_state;
else {
printf ("%s\n", strerror(errno));
return STATE_CRITICAL;
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 6c8eed36bf0e5be451367802840e585af399c02c..22542a77ac16cf15c2f032d3d3108d946c6d1786 100644 (file)
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
int is_hostname (char *);
extern int socket_timeout;
+extern int econn_refuse_state;
+extern int was_refused;