diff options
author | Sven Nierlein <sven@nierlein.de> | 2015-04-22 11:43:51 +0200 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2015-04-22 12:51:29 +0200 |
commit | d309b1d2e90fecdf243952fbb0cf819be38b9c8b (patch) | |
tree | 363264a87014b37589d5d1ab76dcf1cbb1206f06 | |
parent | 003103c09d039bae0a46d9d6cae4d88dd61ed42f (diff) | |
download | monitoring-plugins-d309b1d.tar.gz |
add check_ldap test
install openldap on travis and grep base dn from slapcat.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | plugins/t/NPTest.cache.travis | 2 | ||||
-rw-r--r-- | plugins/t/check_ldap.t | 80 |
3 files changed, 83 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml index 21a1713c..11cc0611 100644 --- a/.travis.yml +++ b/.travis.yml | |||
@@ -11,6 +11,7 @@ install: | |||
11 | - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libfreeradius-client-dev libkrb5-dev libnet-snmp-perl procps | 11 | - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libfreeradius-client-dev libkrb5-dev libnet-snmp-perl procps |
12 | - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd | 12 | - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd |
13 | - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 postfix libhttp-daemon-ssl-perl | 13 | - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 postfix libhttp-daemon-ssl-perl |
14 | - sudo apt-get install -qq --no-install-recommends slapd ldap-utils | ||
14 | - sudo apt-get install -qq --no-install-recommends autoconf automake | 15 | - sudo apt-get install -qq --no-install-recommends autoconf automake |
15 | 16 | ||
16 | before_script: | 17 | before_script: |
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index 4ebfb90e..17ecf86c 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
@@ -19,11 +19,13 @@ | |||
19 | 'NP_HOST_TCP_HTTP' => 'localhost', | 19 | 'NP_HOST_TCP_HTTP' => 'localhost', |
20 | 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', | 20 | 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', |
21 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', | 21 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', |
22 | 'NP_HOST_TCP_LDAP' => 'localhost', | ||
22 | 'NP_HOST_TCP_POP' => 'pop.web.de', | 23 | 'NP_HOST_TCP_POP' => 'pop.web.de', |
23 | 'NP_HOST_TCP_SMTP' => 'localhost', | 24 | 'NP_HOST_TCP_SMTP' => 'localhost', |
24 | 'NP_HOST_TCP_SMTP_NOTLS' => '', | 25 | 'NP_HOST_TCP_SMTP_NOTLS' => '', |
25 | 'NP_HOST_TCP_SMTP_TLS' => '', | 26 | 'NP_HOST_TCP_SMTP_TLS' => '', |
26 | 'NP_INTERNET_ACCESS' => 'yes', | 27 | 'NP_INTERNET_ACCESS' => 'yes', |
28 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', | ||
27 | 'NP_MOUNTPOINT2_VALID' => '', | 29 | 'NP_MOUNTPOINT2_VALID' => '', |
28 | 'NP_MOUNTPOINT_VALID' => '/', | 30 | 'NP_MOUNTPOINT_VALID' => '/', |
29 | 'NP_MYSQL_SERVER' => 'localhost', | 31 | 'NP_MYSQL_SERVER' => 'localhost', |
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t new file mode 100644 index 00000000..a0f06722 --- /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 | |||
7 | use strict; | ||
8 | use warnings; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", | ||
13 | "A host providing the LDAP Service", | ||
14 | "localhost" ); | ||
15 | |||
16 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", | ||
17 | "A base dn for the LDAP Service", | ||
18 | "cn=admin" ); | ||
19 | |||
20 | my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
21 | "The hostname of system not responsive to network requests" ); | ||
22 | |||
23 | my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
24 | "An invalid (not known to DNS) hostname" ); | ||
25 | |||
26 | my($result, $cmd); | ||
27 | my $command = './check_ldap'; | ||
28 | |||
29 | plan tests => 16; | ||
30 | |||
31 | SKIP: { | ||
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 | |||
39 | SKIP: { | ||
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 | |||
47 | SKIP: { | ||
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 | }; | ||