diff options
author | Sven Nierlein <Sven.Nierlein@consol.de> | 2013-09-15 20:15:21 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@consol.de> | 2013-09-15 20:15:21 (GMT) |
commit | 5d58592cfe75baae10c4722f4fa6c17ca1256d1e (patch) | |
tree | 784b4057d2209eebbf613b46ddda327205692d76 /plugins-root/t | |
parent | 3c958ac73844d877fb2f22c397a9fd4aa6c5c99c (diff) | |
download | monitoring-plugins-5d58592cfe75baae10c4722f4fa6c17ca1256d1e.tar.gz |
check_dhcp: add test file
Diffstat (limited to 'plugins-root/t')
-rw-r--r-- | plugins-root/t/check_dhcp.t | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins-root/t/check_dhcp.t b/plugins-root/t/check_dhcp.t new file mode 100644 index 0000000..1f7c518 --- /dev/null +++ b/plugins-root/t/check_dhcp.t | |||
@@ -0,0 +1,49 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # DHCP Tests via check_dhcp | ||
4 | # | ||
5 | |||
6 | use strict; | ||
7 | use Test::More; | ||
8 | use NPTest; | ||
9 | |||
10 | my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", | ||
11 | "If sudo is setup for this user to run any command as root ('yes' to allow)", | ||
12 | "no" ); | ||
13 | |||
14 | if ($allow_sudo eq "yes" or $> == 0) { | ||
15 | plan tests => 4; | ||
16 | } else { | ||
17 | plan skip_all => "Need sudo to test check_dhcp"; | ||
18 | } | ||
19 | my $sudo = $> == 0 ? '' : 'sudo'; | ||
20 | |||
21 | my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; | ||
22 | my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/'; | ||
23 | |||
24 | my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE", | ||
25 | "The hostname of system responsive to dhcp requests", | ||
26 | "localhost" ); | ||
27 | |||
28 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | ||
29 | "The hostname of system not responsive to dhcp requests", | ||
30 | "10.0.0.1" ); | ||
31 | |||
32 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | ||
33 | "An invalid (not known to DNS) hostname", | ||
34 | "nosuchhost" ); | ||
35 | |||
36 | my $res; | ||
37 | |||
38 | $res = NPTest->testCmd( | ||
39 | "$sudo ./check_dhcp -s $host_responsive" | ||
40 | ); | ||
41 | is( $res->return_code, 0, "Syntax ok" ); | ||
42 | like( $res->output, $successOutput, "Output OK" ); | ||
43 | |||
44 | $res = NPTest->testCmd( | ||
45 | "$sudo ./check_dhcp -s $host_nonresponsive" | ||
46 | ); | ||
47 | is( $res->return_code, 2, "Timeout - host nonresponsive" ); | ||
48 | like( $res->output, $failureOutput, "Output OK" ); | ||
49 | |||