diff options
author | Sven Nierlein <sven@nierlein.de> | 2013-02-10 22:57:55 +0100 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2013-02-10 23:09:49 +0100 |
commit | 5fce5ceaeb316a1701c49a9c966d60b602101ed9 (patch) | |
tree | 5a370106e96fc075ecfe7a36795cc9badf393006 /plugins | |
parent | f4bbd88a9f91bfbfbe590b3252043392e7248988 (diff) | |
download | monitoring-plugins-5fce5ceaeb316a1701c49a9c966d60b602101ed9.tar.gz |
check_tcp: don't ignore trailing options
"./check_tcp -6 -p 80 host" leads to an error:
TCP CRITICAL - Invalid hostname, address or socket: 127.0.0.1
because 127.0.0.1 is the fallback host, the tailing hostname
was ignored.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_tcp.c | 25 | ||||
-rw-r--r-- | plugins/t/check_tcp.t | 4 |
2 files changed, 18 insertions, 11 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index af3ae241..ce966c38 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -1,30 +1,30 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios check_tcp plugin | 3 | * Nagios check_tcp plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2008 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2008 Nagios Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_tcp plugin | 10 | * This file contains the check_tcp plugin |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * $Id$ | 26 | * $Id$ |
27 | * | 27 | * |
28 | *****************************************************************************/ | 28 | *****************************************************************************/ |
29 | 29 | ||
30 | /* progname "check_tcp" changes depending on symlink called */ | 30 | /* progname "check_tcp" changes depending on symlink called */ |
@@ -61,6 +61,7 @@ static int PORT = 0; | |||
61 | 61 | ||
62 | static int server_port = 0; | 62 | static int server_port = 0; |
63 | static char *server_address = NULL; | 63 | static char *server_address = NULL; |
64 | static int host_specified = FALSE; | ||
64 | static char *server_send = NULL; | 65 | static char *server_send = NULL; |
65 | static char *server_quit = NULL; | 66 | static char *server_quit = NULL; |
66 | static char **server_expect; | 67 | static char **server_expect; |
@@ -462,6 +463,7 @@ process_arguments (int argc, char **argv) | |||
462 | #endif | 463 | #endif |
463 | break; | 464 | break; |
464 | case 'H': /* hostname */ | 465 | case 'H': /* hostname */ |
466 | host_specified = TRUE; | ||
465 | server_address = optarg; | 467 | server_address = optarg; |
466 | break; | 468 | break; |
467 | case 'c': /* critical */ | 469 | case 'c': /* critical */ |
@@ -588,6 +590,10 @@ process_arguments (int argc, char **argv) | |||
588 | } | 590 | } |
589 | } | 591 | } |
590 | 592 | ||
593 | c = optind; | ||
594 | if(host_specified == FALSE && c < argc) | ||
595 | server_address = strdup (argv[c++]); | ||
596 | |||
591 | if (server_address == NULL) | 597 | if (server_address == NULL) |
592 | usage4 (_("You must provide a server address")); | 598 | usage4 (_("You must provide a server address")); |
593 | else if (server_address[0] != '/' && is_host (server_address) == FALSE) | 599 | else if (server_address[0] != '/' && is_host (server_address) == FALSE) |
@@ -666,4 +672,3 @@ print_usage (void) | |||
666 | printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); | 672 | printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n"); |
667 | printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n"); | 673 | printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n"); |
668 | } | 674 | } |
669 | |||
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index 75c1e5fb..d6808bf2 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
@@ -9,7 +9,7 @@ use Test; | |||
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | use vars qw($tests); | 11 | use vars qw($tests); |
12 | BEGIN {$tests = 7; plan tests => $tests} | 12 | BEGIN {$tests = 14; plan tests => $tests} |
13 | 13 | ||
14 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", | 14 | my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", |
15 | "A host providing the HTTP Service (a web server)" ); | 15 | "A host providing the HTTP Service (a web server)" ); |
@@ -27,6 +27,7 @@ my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on po | |||
27 | my $t; | 27 | my $t; |
28 | 28 | ||
29 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); | 29 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); |
30 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput ); | ||
30 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test | 31 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test |
31 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); | 32 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); |
32 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); | 33 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); |
@@ -34,6 +35,7 @@ $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 | |||
34 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); | 35 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); |
35 | $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); | 36 | $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); |
36 | $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); | 37 | $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); |
38 | $t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 ); | ||
37 | 39 | ||
38 | # Need the \r\n to make it more standards compliant with web servers. Need the various quotes | 40 | # Need the \r\n to make it more standards compliant with web servers. Need the various quotes |
39 | # so that perl doesn't interpret the \r\n and is passed onto command line correctly | 41 | # so that perl doesn't interpret the \r\n and is passed onto command line correctly |