summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
authorSven Nierlein <Sven.Nierlein@consol.de>2013-09-15 20:15:21 (GMT)
committerSven Nierlein <sven@consol.de>2013-09-15 20:15:21 (GMT)
commit5d58592cfe75baae10c4722f4fa6c17ca1256d1e (patch)
tree784b4057d2209eebbf613b46ddda327205692d76 /plugins-root
parent3c958ac73844d877fb2f22c397a9fd4aa6c5c99c (diff)
downloadmonitoring-plugins-5d58592cfe75baae10c4722f4fa6c17ca1256d1e.tar.gz
check_dhcp: add test file
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/t/check_dhcp.t49
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
6use strict;
7use Test::More;
8use NPTest;
9
10my $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
14if ($allow_sudo eq "yes" or $> == 0) {
15 plan tests => 4;
16} else {
17 plan skip_all => "Need sudo to test check_dhcp";
18}
19my $sudo = $> == 0 ? '' : 'sudo';
20
21my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./';
22my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/';
23
24my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE",
25 "The hostname of system responsive to dhcp requests",
26 "localhost" );
27
28my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
29 "The hostname of system not responsive to dhcp requests",
30 "10.0.0.1" );
31
32my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
33 "An invalid (not known to DNS) hostname",
34 "nosuchhost" );
35
36my $res;
37
38$res = NPTest->testCmd(
39 "$sudo ./check_dhcp -s $host_responsive"
40 );
41is( $res->return_code, 0, "Syntax ok" );
42like( $res->output, $successOutput, "Output OK" );
43
44$res = NPTest->testCmd(
45 "$sudo ./check_dhcp -s $host_nonresponsive"
46 );
47is( $res->return_code, 2, "Timeout - host nonresponsive" );
48like( $res->output, $failureOutput, "Output OK" );
49