summaryrefslogtreecommitdiffstats
path: root/t/Monitoring-Plugin-04.t
diff options
context:
space:
mode:
Diffstat (limited to 't/Monitoring-Plugin-04.t')
-rw-r--r--t/Monitoring-Plugin-04.t99
1 files changed, 99 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-04.t b/t/Monitoring-Plugin-04.t
new file mode 100644
index 0000000..41027f7
--- /dev/null
+++ b/t/Monitoring-Plugin-04.t
@@ -0,0 +1,99 @@
1
2# tests for toplevel access to Threshold and GetOpts stuff
3
4use strict;
5#use Test::More 'no_plan';
6use Test::More tests=>30;
7
8BEGIN { use_ok('Monitoring::Plugin') };
9use Monitoring::Plugin::Functions;
10Monitoring::Plugin::Functions::_fake_exit(1);
11
12
13eval { Monitoring::Plugin->new(); };
14ok(! $@, "constructor DOESN'T die without usage");
15
16my $p = Monitoring::Plugin->new();
17eval { $p->add_arg('warning', 'warning') };
18ok($@, "add_arg() dies if you haven't instantiated with usage");
19eval { $p->getopts };
20ok($@, "getopts() dies if you haven't instantiated with usage");
21
22$p = Monitoring::Plugin->new( usage => "dummy usage statement" );
23
24# option accessors work
25can_ok $p, 'opts';
26isa_ok $p->opts, 'Monitoring::Plugin::Getopt', "Getopt object is defined";
27
28$p->add_arg('warning|w=s', "warning");
29$p->add_arg('critical|c=s', "critical");
30
31@ARGV = qw(-w 5 -c 10);
32$p->getopts;
33is $p->opts->warning, "5", "warning opt is accessible";
34is $p->opts->critical, "10", "critical opt is accessible";
35
36
37can_ok $p, 'perfdata';
38#isa_ok $p->perfdata, 'Monitoring::Plugin::Performance', "perfdata object is defined";
39
40
41can_ok $p, 'threshold';
42#isa_ok $p->threshold, 'Monitoring::Plugin::Threshold', "threshold object is defined";
43
44
45eval { $p->check_threshold() };
46ok($@, "check_threshold dies if called with no args");
47
48
49# thresholds set implicitly
50is $p->check_threshold(2), OK, "check_threshold OK when called implicitly";
51is $p->check_threshold(6), WARNING, "check_threshold WARNING";
52is $p->check_threshold(11), CRITICAL, "check_threshold CRITICAL";
53is $p->check_threshold(check=>11), CRITICAL, "check_threshold CRITICAL with hash param";
54
55# Check that arrays allowed
56is $p->check_threshold([2,1]), OK, "check_threshold OK when called implicitly";
57is $p->check_threshold([6,2]), WARNING, "check_threshold WARNING";
58is $p->check_threshold([1,2,6,11]), CRITICAL, "check_threshold CRITICAL";
59is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL with hash param";
60
61# thresholds set explicitly
62is $p->check_threshold(
63 check => 2,
64 warning => 50,
65 critical => 100
66), OK, "check_threshold explicit OK";
67
68is $p->check_threshold(
69 check => 66,
70 warning => 50,
71 critical => 100
72), WARNING, "check_threshold explicit WARNING";
73
74
75is $p->check_threshold(
76 check => -1,
77 warning => 5,
78 critical => '0:5',
79), CRITICAL, "check_threshold explicit CRITICAL";
80
81
82
83# what happens if you forget to define warning or critical thresholds?
84$p = undef;
85$p = Monitoring::Plugin->new();
86
87is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN";
88is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN";
89is $p->check_threshold(134098.3124), UNKNOWN, "everything is now UNKNOWN";
90is $p->check_threshold("foo bar baz"), UNKNOWN, "everything is now UNKNOWN";
91
92
93# how about when you define just one?
94
95$p->set_thresholds(warning => "10:25");
96is $p->check_threshold(2), WARNING, "check_threshold works (WARNING) after explicit set_thresholds";
97is $p->check_threshold(-200), WARNING, "and again";
98is $p->check_threshold(25.5), WARNING, "and again";
99is $p->check_threshold(11), OK, "now OK";