summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_disk.t4
-rw-r--r--plugins/t/check_dns.t2
-rw-r--r--plugins/t/check_http.t24
-rw-r--r--plugins/t/check_mysql.t32
-rw-r--r--plugins/t/check_procs.t7
-rw-r--r--plugins/t/check_tcp.t18
-rw-r--r--plugins/t/negate.t2
7 files changed, 52 insertions, 37 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 39b4ca9..7e0f74b 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -4,7 +4,7 @@
4# 4#
5# 5#
6 6
7# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc 7# TODO: Add in tests for perf data. Need to beef up Monitoring::Plugin::Performance to cater for max, min, etc
8 8
9use strict; 9use strict;
10use Test::More; 10use Test::More;
@@ -37,7 +37,7 @@ cmp_ok( $c, '==', 2, "Got two mountpoints in output");
37 37
38 38
39# Get perf data 39# Get perf data
40# Should use Nagios::Plugin 40# Should use Monitoring::Plugin
41my @perf_data = sort(split(/ /, $result->perf_output)); 41my @perf_data = sort(split(/ /, $result->perf_output));
42 42
43 43
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 64aaf0c..2c903db 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -17,7 +17,7 @@ my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
17my $hostname_valid = getTestParameter( 17my $hostname_valid = getTestParameter(
18 "NP_HOSTNAME_VALID", 18 "NP_HOSTNAME_VALID",
19 "A valid (known to DNS) hostname", 19 "A valid (known to DNS) hostname",
20 "nagios.com" 20 "monitoring-plugins.org"
21 ); 21 );
22 22
23my $hostname_valid_ip = getTestParameter( 23my $hostname_valid_ip = getTestParameter(
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 2908673..2539a28 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -31,8 +31,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
31 "yes"); 31 "yes");
32 32
33my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", 33my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
34 "A host providing an index page containing the string 'nagios'", 34 "A host providing an index page containing the string 'monitoring'",
35 "nagios.org" ); 35 "test.monitoring-plugins.org" );
36 36
37 37
38$res = NPTest->testCmd( 38$res = NPTest->testCmd(
@@ -62,27 +62,27 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
62like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); 62like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK");
63 63
64SKIP: { 64SKIP: {
65 skip "No host serving nagios in index file", 7 unless $host_tcp_http2; 65 skip "No host serving monitoring in index file", 7 unless $host_tcp_http2;
66 66
67 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nagios'" ); 67 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring'" );
68 cmp_ok( $res->return_code, "==", 0, "Got a reference to 'nagios'"); 68 cmp_ok( $res->return_code, "==", 0, "Got a reference to 'monitoring'");
69 69
70 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nAGiOs'" ); 70 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing'" );
71 cmp_ok( $res->return_code, "==", 2, "Not got 'nAGiOs'"); 71 cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'");
72 like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); 72 like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'");
73 73
74 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -R 'nAGiOs'" ); 74 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -R 'mONiTORing'" );
75 cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'nAGiOs'"); 75 cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'");
76 76
77 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nagios' --invert-regex" ); 77 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'monitoring' --invert-regex" );
78 cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); 78 cmp_ok( $res->return_code, "==", 2, "Invert results work when found");
79 like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); 79 like ( $res->output, "/pattern found/", "Error message says 'pattern found'");
80 80
81 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'nAGiOs' --invert-regex" ); 81 $res = NPTest->testCmd( "./check_http -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" );
82 cmp_ok( $res->return_code, "==", 0, "And also when not found"); 82 cmp_ok( $res->return_code, "==", 0, "And also when not found");
83} 83}
84SKIP: { 84SKIP: {
85 skip "No internet access", 11 if $internet_access eq "no"; 85 skip "No internet access", 16 if $internet_access eq "no";
86 86
87 $res = NPTest->testCmd( 87 $res = NPTest->testCmd(
88 "./check_http --ssl www.verisign.com" 88 "./check_http --ssl www.verisign.com"
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t
index d971645..28cd4cd 100644
--- a/plugins/t/check_mysql.t
+++ b/plugins/t/check_mysql.t
@@ -21,27 +21,29 @@ plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
21plan tests => 15; 21plan tests => 15;
22 22
23my $bad_login_output = '/Access denied for user /'; 23my $bad_login_output = '/Access denied for user /';
24my $mysqlserver = getTestParameter( 24my $mysqlserver = getTestParameter(
25 "NP_MYSQL_SERVER", 25 "NP_MYSQL_SERVER",
26 "A MySQL Server hostname or IP with no slaves setup" 26 "A MySQL Server hostname or IP with no slaves setup"
27 ); 27 );
28my $mysqlsocket = getTestParameter( 28my $mysqlsocket = getTestParameter(
29 "NP_MYSQL_SOCKET", 29 "NP_MYSQL_SOCKET",
30 "A MySQL Server socket with no slaves setup" 30 "Full path to a MySQL Server socket with no slaves setup"
31 ); 31 );
32my $mysql_login_details = getTestParameter( 32my $mysql_login_details = getTestParameter(
33 "MYSQL_LOGIN_DETAILS", 33 "MYSQL_LOGIN_DETAILS",
34 "Command line parameters to specify login access", 34 "Command line parameters to specify login access (requires " .
35 "-u user -ppw -d db", 35 "REPLICATION CLIENT privleges)",
36 "-u test -ptest",
36 ); 37 );
37my $with_slave = getTestParameter( 38my $with_slave = getTestParameter(
38 "NP_MYSQL_WITH_SLAVE", 39 "NP_MYSQL_WITH_SLAVE",
39 "MySQL server with slaves setup" 40 "MySQL server with slaves setup"
40 ); 41 );
41my $with_slave_login = getTestParameter( 42my $with_slave_login = getTestParameter(
42 "NP_MYSQL_WITH_SLAVE_LOGIN", 43 "NP_MYSQL_WITH_SLAVE_LOGIN",
43 "Login details for server with slave", 44 "Login details for server with slave (requires REPLICATION CLIENT " .
44 "-uroot -ppw" 45 "privleges)",
46 $mysql_login_details || "-u test -ptest"
45 ); 47 );
46 48
47my $result; 49my $result;
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t
index 1dea564..ca4acdd 100644
--- a/plugins/t/check_procs.t
+++ b/plugins/t/check_procs.t
@@ -13,7 +13,7 @@ my $t;
13if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") { 13if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") {
14 plan skip_all => "Ignoring tests on solaris because of pst3"; 14 plan skip_all => "Ignoring tests on solaris because of pst3";
15} else { 15} else {
16 plan tests => 12; 16 plan tests => 14;
17} 17}
18 18
19my $result; 19my $result;
@@ -26,6 +26,11 @@ $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
26is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); 26is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
27like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" ); 27like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
28 28
29if(fork() == 0) { exec("sleep 7"); } # fork a test process
30$result = NPTest->testCmd( "./check_procs -a 'sleep 7'" );
31is( $result->return_code, 0, "Parent process is ignored" );
32like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );
33
29$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" ); 34$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
30is( $result->return_code, 1, "Checking warning if processes > 0" ); 35is( $result->return_code, 1, "Checking warning if processes > 0" );
31like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" ); 36like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index abb16ae..f996685 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -12,7 +12,6 @@ BEGIN {
12 use NPTest; 12 use NPTest;
13 $has_ipv6 = NPTest::has_ipv6(); 13 $has_ipv6 = NPTest::has_ipv6();
14 $tests = $has_ipv6 ? 14 : 11; 14 $tests = $has_ipv6 ? 14 : 11;
15 plan tests => $tests;
16} 15}
17 16
18 17
@@ -25,20 +24,29 @@ my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRES
25my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 24my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
26 "An invalid (not known to DNS) hostname" ); 25 "An invalid (not known to DNS) hostname" );
27 26
27my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
28 "Is this system directly connected to the internet?",
29 "yes");
30
28my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; 31my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/';
29 32
30my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/'; 33my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/';
31 34
32my $t; 35my $t;
33 36
37$tests = $tests - 4 if $internet_access eq "no";
38plan tests => $tests;
39
34$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); 40$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput );
35$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test 41$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
36$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); 42$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
37$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); 43$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
38$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 ); 44if($internet_access ne "no") {
39$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 ); 45 $t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
40$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); 46 $t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
41$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); 47 $t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
48 $t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
49}
42 50
43# Need the \r\n to make it more standards compliant with web servers. Need the various quotes 51# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
44# so that perl doesn't interpret the \r\n and is passed onto command line correctly 52# so that perl doesn't interpret the \r\n and is passed onto command line correctly
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index 0afe3ae..f18acc3 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -78,7 +78,7 @@ foreach my $current_state (keys(%state)) {
78 } 78 }
79} 79}
80 80
81# Same as aboce with substitute 81# Same as above with substitute
82foreach my $current_state (keys(%state)) { 82foreach my $current_state (keys(%state)) {
83 foreach my $new_state (keys(%state)) { 83 foreach my $new_state (keys(%state)) {
84 $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); 84 $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );