aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sven Nierlein <sven@consol.de> 2013-09-14 19:36:20 +0200
committerGravatar Sven Nierlein <sven@consol.de> 2013-09-14 19:36:20 +0200
commit7b122f13dbb0bd714b47e1181ba36bfbb3bd7658 (patch)
treee204afb0058a14c248dc9bcca1199b525cd2c706
parent32ec6265a4161790bc3a548b0d2c1237e30b0d1a (diff)
downloadmonitoring-plugins-7b122f13dbb0bd714b47e1181ba36bfbb3bd7658.tar.gz
tests: move ipv6 detection into NPTest module
-rw-r--r--NPTest.pm10
-rw-r--r--plugins/t/check_dig.t20
-rw-r--r--plugins/t/check_tcp.t16
3 files changed, 28 insertions, 18 deletions
diff --git a/NPTest.pm b/NPTest.pm
index c719776a..f14657c1 100644
--- a/NPTest.pm
+++ b/NPTest.pm
@@ -645,6 +645,16 @@ sub testCmd {
return $object;
}
+# do we have ipv6
+sub has_ipv6 {
+ # assume ipv6 if a ping6 to labs.consol.de works
+ `ping6 -c 1 2a03:3680:0:2::21 2>&1`;
+ if($? == 0) {
+ return 1;
+ }
+ return;
+}
+
1;
#
# End of File
diff --git a/plugins/t/check_dig.t b/plugins/t/check_dig.t
index 1ab4b426..d447f084 100644
--- a/plugins/t/check_dig.t
+++ b/plugins/t/check_dig.t
@@ -6,11 +6,16 @@
use strict;
use Test::More;
-use NPTest;
-plan skip_all => "check_dig not compiled" unless (-x "check_dig");
-plan tests => 16;
+use vars qw($tests $has_ipv6);
+BEGIN {
+ plan skip_all => "check_dig not compiled" unless (-x "check_dig");
+ use NPTest;
+ $has_ipv6 = NPTest::has_ipv6();
+ $tests = $has_ipv6 ? 16 : 14;
+ plan tests => $tests;
+}
my $successOutput = '/DNS OK - [\.0-9]+ seconds? response time/';
@@ -73,10 +78,6 @@ SKIP: {
cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
like ( $res->output, $successOutput, "Output OK for IPv4" );
- $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6");
- cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
- like ( $res->output, $successOutput, "Output OK for IPv6" );
-
$res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -a $hostname_valid_ip -t 5");
cmp_ok( $res->return_code, '==', 0, "Got expected address");
@@ -89,4 +90,9 @@ SKIP: {
cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
like ( $res->output, $successOutput, "Output OK");
+ if($has_ipv6) {
+ $res = NPTest->testCmd("./check_dig -H $dns_server -l $hostname_valid -t 5 -6");
+ cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server");
+ like ( $res->output, $successOutput, "Output OK for IPv6" );
+ }
}
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index 0e6a9641..abb16aec 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -6,19 +6,13 @@
use strict;
use Test;
-use NPTest;
-use vars qw($tests);
-my $has_ipv6;
+use vars qw($tests $has_ipv6);
BEGIN {
- $tests = 11;
- # do we have ipv6
- `ping6 -c 1 2a02:2e0:3fe:100::7 2>&1`;
- if($? == 0) {
- $has_ipv6 = 1;
- $tests += 3;
- }
- plan tests => $tests;
+ use NPTest;
+ $has_ipv6 = NPTest::has_ipv6();
+ $tests = $has_ipv6 ? 14 : 11;
+ plan tests => $tests;
}