summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_ldap.t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2015-04-22 09:43:51 (GMT)
committerSven Nierlein <sven@nierlein.de>2015-04-22 10:51:29 (GMT)
commitd309b1d2e90fecdf243952fbb0cf819be38b9c8b (patch)
tree363264a87014b37589d5d1ab76dcf1cbb1206f06 /plugins/t/check_ldap.t
parent003103c09d039bae0a46d9d6cae4d88dd61ed42f (diff)
downloadmonitoring-plugins-d309b1d2e90fecdf243952fbb0cf819be38b9c8b.tar.gz
add check_ldap test
install openldap on travis and grep base dn from slapcat. Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'plugins/t/check_ldap.t')
-rw-r--r--plugins/t/check_ldap.t80
1 files changed, 80 insertions, 0 deletions
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t
new file mode 100644
index 0000000..a0f0672
--- /dev/null
+++ b/plugins/t/check_ldap.t
@@ -0,0 +1,80 @@
1#!/usr/bin/env perl -I ..
2#
3# Lightweight Directory Access Protocol (LDAP) Test via check_ldap
4#
5#
6
7use strict;
8use warnings;
9use Test::More;
10use NPTest;
11
12my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP",
13 "A host providing the LDAP Service",
14 "localhost" );
15
16my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN",
17 "A base dn for the LDAP Service",
18 "cn=admin" );
19
20my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
21 "The hostname of system not responsive to network requests" );
22
23my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
24 "An invalid (not known to DNS) hostname" );
25
26my($result, $cmd);
27my $command = './check_ldap';
28
29plan tests => 16;
30
31SKIP: {
32 skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive;
33
34 $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1");
35 is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" );
36 is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" );
37};
38
39SKIP: {
40 skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid;
41
42 $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5");
43 is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" );
44 is( $result->output, 'Could not bind to the LDAP server', "output ok" );
45};
46
47SKIP: {
48 skip "NP_HOST_TCP_LDAP not set", 2 if ! $host_tcp_ldap;
49 skip "NP_LDAP_BASE_DN not set", 2 if ! $ldap_base_dn;
50
51 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3";
52 $result = NPTest->testCmd($cmd);
53 is( $result->return_code, 0, $cmd );
54 like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" );
55
56 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001";
57 $result = NPTest->testCmd($cmd);
58 is( $result->return_code, 0, $cmd );
59 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" );
60
61 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:";
62 $result = NPTest->testCmd($cmd);
63 is( $result->return_code, 2, $cmd );
64 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" );
65
66 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0";
67 $result = NPTest->testCmd($cmd);
68 is( $result->return_code, 2, $cmd );
69 like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" );
70
71 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001";
72 $result = NPTest->testCmd($cmd);
73 is( $result->return_code, 1, $cmd );
74 like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" );
75
76 $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001";
77 $result = NPTest->testCmd($cmd);
78 is( $result->return_code, 0, $cmd );
79 like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" );
80};