diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_tcp.c | 25 | ||||
| -rw-r--r-- | plugins/netutils.c | 20 | ||||
| -rw-r--r-- | plugins/netutils.h | 2 | 
3 files changed, 41 insertions, 6 deletions
| diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 7d115513..5bec2915 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
| @@ -28,7 +28,7 @@ This plugin tests %s connections with the specified host.\n"; | |||
| 28 | 28 | ||
| 29 | const char *option_summary = "\ | 29 | const char *option_summary = "\ | 
| 30 | -H host -p port [-w warn_time] [-c crit_time] [-s send]\n\ | 30 | -H host -p port [-w warn_time] [-c crit_time] [-s send]\n\ | 
| 31 | [-e expect] [-W wait] [-t to_sec] [-v]\n"; | 31 | [-e expect] [-W wait] [-t to_sec] [-r refuse_state] [-v]\n"; | 
| 32 | 32 | ||
| 33 | const char *options = "\ | 33 | const char *options = "\ | 
| 34 | -H, --hostname=ADDRESS\n\ | 34 | -H, --hostname=ADDRESS\n\ | 
| @@ -48,6 +48,8 @@ const char *options = "\ | |||
| 48 | Response time to result in critical status (seconds)\n\ | 48 | Response time to result in critical status (seconds)\n\ | 
| 49 | -t, --timeout=INTEGER\n\ | 49 | -t, --timeout=INTEGER\n\ | 
| 50 | Seconds before connection times out (default: %d)\n\ | 50 | Seconds before connection times out (default: %d)\n\ | 
| 51 | -r, --refuse=ok|warn|crit\n\ | ||
| 52 | Accept tcp refusals with states ok, warn, crit (default: crit)\n\ | ||
| 51 | -v\n\ | 53 | -v\n\ | 
| 52 | Show details for command-line debugging (do not use with nagios server)\n\ | 54 | Show details for command-line debugging (do not use with nagios server)\n\ | 
| 53 | -h, --help\n\ | 55 | -h, --help\n\ | 
| @@ -337,9 +339,11 @@ main (int argc, char **argv) | |||
| 337 | alarm (0); | 339 | alarm (0); | 
| 338 | 340 | ||
| 339 | printf | 341 | printf | 
| 340 | ("%s %s - %.3f second response time on port %d", | 342 | ("%s %s%s - %.3f second response time on port %d", | 
| 341 | SERVICE, | 343 | SERVICE, | 
| 342 | state_text (result), elapsed_time, server_port); | 344 | state_text (result), | 
| 345 | (was_refused) ? " (refused)" : "", | ||
| 346 | elapsed_time, server_port); | ||
| 343 | 347 | ||
| 344 | if (status && strlen(status) > 0) | 348 | if (status && strlen(status) > 0) | 
| 345 | printf (" [%s]", status); | 349 | printf (" [%s]", status); | 
| @@ -375,6 +379,7 @@ process_arguments (int argc, char **argv) | |||
| 375 | {"expect", required_argument, 0, 'e'}, | 379 | {"expect", required_argument, 0, 'e'}, | 
| 376 | {"quit", required_argument, 0, 'q'}, | 380 | {"quit", required_argument, 0, 'q'}, | 
| 377 | {"delay", required_argument, 0, 'd'}, | 381 | {"delay", required_argument, 0, 'd'}, | 
| 382 | {"refuse", required_argument, 0, 'r'}, | ||
| 378 | {"verbose", no_argument, 0, 'v'}, | 383 | {"verbose", no_argument, 0, 'v'}, | 
| 379 | {"version", no_argument, 0, 'V'}, | 384 | {"version", no_argument, 0, 'V'}, | 
| 380 | {"help", no_argument, 0, 'h'}, | 385 | {"help", no_argument, 0, 'h'}, | 
| @@ -402,7 +407,7 @@ process_arguments (int argc, char **argv) | |||
| 402 | } | 407 | } | 
| 403 | 408 | ||
| 404 | while (1) { | 409 | while (1) { | 
| 405 | c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S", long_options, | 410 | c = getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:Sr:", long_options, | 
| 406 | &option_index); | 411 | &option_index); | 
| 407 | 412 | ||
| 408 | if (c == -1 || c == EOF || c == 1) | 413 | if (c == -1 || c == EOF || c == 1) | 
| @@ -471,6 +476,16 @@ process_arguments (int argc, char **argv) | |||
| 471 | case 'q': | 476 | case 'q': | 
| 472 | server_quit = optarg; | 477 | server_quit = optarg; | 
| 473 | break; | 478 | break; | 
| 479 | case 'r': | ||
| 480 | if (!strncmp(optarg,"ok",2)) | ||
| 481 | econn_refuse_state = STATE_OK; | ||
| 482 | else if (!strncmp(optarg,"warn",4)) | ||
| 483 | econn_refuse_state = STATE_WARNING; | ||
| 484 | else if (!strncmp(optarg,"crit",4)) | ||
| 485 | econn_refuse_state = STATE_CRITICAL; | ||
| 486 | else | ||
| 487 | usage ("Refuse mut be one of ok, warn, crit\n"); | ||
| 488 | break; | ||
| 474 | case 'd': | 489 | case 'd': | 
| 475 | if (is_intpos (optarg)) | 490 | if (is_intpos (optarg)) | 
| 476 | delay = atoi (optarg); | 491 | delay = atoi (optarg); | 
| @@ -541,7 +556,7 @@ connect_SSL (void) | |||
| 541 | time (&start_time); | 556 | time (&start_time); | 
| 542 | 557 | ||
| 543 | /* Make TCP connection */ | 558 | /* Make TCP connection */ | 
| 544 | if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK) | 559 | if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK && was_refused == FALSE) | 
| 545 | { | 560 | { | 
| 546 | /* Do the SSL handshake */ | 561 | /* Do the SSL handshake */ | 
| 547 | if ((ssl = SSL_new (ctx)) != NULL) | 562 | if ((ssl = SSL_new (ctx)) != NULL) | 
| diff --git a/plugins/netutils.c b/plugins/netutils.c index 4234c436..b3348d6e 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
| @@ -32,6 +32,8 @@ | |||
| 32 | #include "netutils.h" | 32 | #include "netutils.h" | 
| 33 | 33 | ||
| 34 | int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | 34 | int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | 
| 35 | int econn_refuse_state = STATE_CRITICAL; | ||
| 36 | int was_refused = FALSE; | ||
| 35 | 37 | ||
| 36 | /* handles socket timeouts */ | 38 | /* handles socket timeouts */ | 
| 37 | void | 39 | void | 
| @@ -275,8 +277,22 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
| 275 | /* attempt to open a connection */ | 277 | /* attempt to open a connection */ | 
| 276 | result = connect (*sd, res->ai_addr, res->ai_addrlen); | 278 | result = connect (*sd, res->ai_addr, res->ai_addrlen); | 
| 277 | 279 | ||
| 278 | if (result == 0) | 280 | if (result == 0) { | 
| 281 | was_refused = FALSE; | ||
| 279 | break; | 282 | break; | 
| 283 | } | ||
| 284 | |||
| 285 | if (result < 0) { | ||
| 286 | switch (errno) { | ||
| 287 | case ECONNREFUSED: | ||
| 288 | switch (econn_refuse_state) { | ||
| 289 | case STATE_OK: | ||
| 290 | case STATE_WARNING: | ||
| 291 | was_refused = TRUE; | ||
| 292 | } | ||
| 293 | break; | ||
| 294 | } | ||
| 295 | } | ||
| 280 | 296 | ||
| 281 | close (*sd); | 297 | close (*sd); | 
| 282 | res = res->ai_next; | 298 | res = res->ai_next; | 
| @@ -286,6 +302,8 @@ my_connect (char *host_name, int port, int *sd, int proto) | |||
| 286 | 302 | ||
| 287 | if (result == 0) | 303 | if (result == 0) | 
| 288 | return STATE_OK; | 304 | return STATE_OK; | 
| 305 | else if (was_refused) | ||
| 306 | return econn_refuse_state; | ||
| 289 | else { | 307 | else { | 
| 290 | printf ("%s\n", strerror(errno)); | 308 | printf ("%s\n", strerror(errno)); | 
| 291 | return STATE_CRITICAL; | 309 | return STATE_CRITICAL; | 
| diff --git a/plugins/netutils.h b/plugins/netutils.h index 6c8eed36..22542a77 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
| @@ -60,3 +60,5 @@ int is_inet6_addr (char *); | |||
| 60 | int is_hostname (char *); | 60 | int is_hostname (char *); | 
| 61 | 61 | ||
| 62 | extern int socket_timeout; | 62 | extern int socket_timeout; | 
| 63 | extern int econn_refuse_state; | ||
| 64 | extern int was_refused; | ||
