summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2014-01-20 00:54:34 +0100
committerSven Nierlein <sven@nierlein.de>2014-01-20 00:54:34 +0100
commitb418181dfe80dd75169b6e8a619ac1932155dea2 (patch)
treecad9c0ae0eae8e800cfff60555ead06ad33c6856 /t
parent1cd8d1c52cbd47121f344c4074aec84653f412ce (diff)
downloadmonitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we also rename this module. Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 't')
-rw-r--r--t/Monitoring-Plugin-01.t (renamed from t/Nagios-Plugin-01.t)33
-rw-r--r--t/Monitoring-Plugin-02.t160
-rw-r--r--t/Monitoring-Plugin-03.t (renamed from t/Nagios-Plugin-03.t)53
-rw-r--r--t/Monitoring-Plugin-04.t (renamed from t/Nagios-Plugin-04.t)26
-rw-r--r--t/Monitoring-Plugin-05.t (renamed from t/Nagios-Plugin-05.t)7
-rw-r--r--t/Monitoring-Plugin-Functions-01.t161
-rw-r--r--t/Monitoring-Plugin-Functions-02.t (renamed from t/Nagios-Plugin-Functions-02.t)9
-rw-r--r--t/Monitoring-Plugin-Functions-03.t (renamed from t/Nagios-Plugin-Functions-03.t)2
-rw-r--r--t/Monitoring-Plugin-Functions-04.t (renamed from t/Nagios-Plugin-Functions-04.t)2
-rw-r--r--t/Monitoring-Plugin-Getopt-01.t (renamed from t/Nagios-Plugin-Getopt-01.t)17
-rw-r--r--t/Monitoring-Plugin-Getopt-02.t (renamed from t/Nagios-Plugin-Getopt-02.t)15
-rw-r--r--t/Monitoring-Plugin-Getopt-03.t (renamed from t/Nagios-Plugin-Getopt-03.t)29
-rw-r--r--t/Monitoring-Plugin-Getopt-04.t (renamed from t/Nagios-Plugin-Getopt-04.t)15
-rw-r--r--t/Monitoring-Plugin-Performance-02.t13
-rw-r--r--t/Monitoring-Plugin-Performance.t (renamed from t/Nagios-Plugin-Performance.t)104
-rw-r--r--t/Monitoring-Plugin-Range.t (renamed from t/Nagios-Plugin-Range.t)38
-rw-r--r--t/Monitoring-Plugin-Threshold.t (renamed from t/Nagios-Plugin-Threshold.t)58
-rw-r--r--t/Nagios-Plugin-02.t161
-rw-r--r--t/Nagios-Plugin-Functions-01.t161
-rw-r--r--t/Nagios-Plugin-Performance-02.t13
-rwxr-xr-xt/check_stuff.pl45
-rwxr-xr-xt/check_stuff.t10
-rw-r--r--t/npg03/README16
23 files changed, 564 insertions, 584 deletions
diff --git a/t/Nagios-Plugin-01.t b/t/Monitoring-Plugin-01.t
index 947a704..f5882a5 100644
--- a/t/Nagios-Plugin-01.t
+++ b/t/Monitoring-Plugin-01.t
@@ -1,32 +1,32 @@
1# Nagios::Plugin original test cases 1# Monitoring::Plugin original test cases
2 2
3use strict; 3use strict;
4use Test::More tests => 15; 4use Test::More tests => 15;
5 5
6BEGIN { use_ok('Nagios::Plugin') }; 6BEGIN { use_ok('Monitoring::Plugin') };
7 7
8use Nagios::Plugin::Functions; 8use Monitoring::Plugin::Functions;
9Nagios::Plugin::Functions::_fake_exit(1); 9Monitoring::Plugin::Functions::_fake_exit(1);
10 10
11diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n" 11diag "\nusing Monitoring::Plugin revision ". $Monitoring::Plugin::VERSION . "\n"
12 if $ENV{TEST_VERBOSE}; 12 if $ENV{TEST_VERBOSE};
13 13
14my $p = Nagios::Plugin->new(); 14my $p = Monitoring::Plugin->new();
15isa_ok( $p, "Nagios::Plugin"); 15isa_ok( $p, "Monitoring::Plugin");
16 16
17$p->shortname("PAGESIZE"); 17$p->shortname("PAGESIZE");
18is($p->shortname, "PAGESIZE", "shortname explicitly set correctly"); 18is($p->shortname, "PAGESIZE", "shortname explicitly set correctly");
19 19
20$p = Nagios::Plugin->new(); 20$p = Monitoring::Plugin->new();
21is($p->shortname, "NAGIOS-PLUGIN-01", "shortname should default on new"); 21is($p->shortname, "MONITORING-PLUGIN-01", "shortname should default on new");
22 22
23$p = Nagios::Plugin->new( shortname => "SIZE", () ); 23$p = Monitoring::Plugin->new( shortname => "SIZE", () );
24is($p->shortname, "SIZE", "shortname set correctly on new"); 24is($p->shortname, "SIZE", "shortname set correctly on new");
25 25
26$p = Nagios::Plugin->new( plugin => "check_stuff", () ); 26$p = Monitoring::Plugin->new( plugin => "check_stuff", () );
27is($p->shortname, "STUFF", "shortname uses plugin name as default"); 27is($p->shortname, "STUFF", "shortname uses plugin name as default");
28 28
29$p = Nagios::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () ); 29$p = Monitoring::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () );
30is($p->shortname, "SIZE", "shortname is not overriden by default"); 30is($p->shortname, "SIZE", "shortname is not overriden by default");
31 31
32diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; 32diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE};
@@ -37,10 +37,10 @@ use Data::Dumper;
37#diag "dumping perfdata: ". Dumper $p->perfdata; 37#diag "dumping perfdata: ". Dumper $p->perfdata;
38 38
39 39
40$p->add_perfdata( 40$p->add_perfdata(
41 label => "size", 41 label => "size",
42 value => 1, 42 value => 1,
43 uom => "kB", 43 uom => "kB",
44 threshold => $t, 44 threshold => $t,
45 ); 45 );
46 46
@@ -69,4 +69,3 @@ foreach (sort {$a<=>$b} keys %$expected) {
69 qr/$expected->{$_}/, 69 qr/$expected->{$_}/,
70 "Output okay. $_ = $expected->{$_}" ; 70 "Output okay. $_ = $expected->{$_}" ;
71} 71}
72
diff --git a/t/Monitoring-Plugin-02.t b/t/Monitoring-Plugin-02.t
new file mode 100644
index 0000000..6cc834d
--- /dev/null
+++ b/t/Monitoring-Plugin-02.t
@@ -0,0 +1,160 @@
1# Monitoring::Plugin test set 2, testing MP::Functions wrapping
2
3use strict;
4use Test::More tests => 103;
5
6BEGIN { use_ok("Monitoring::Plugin") }
7require Monitoring::Plugin::Functions;
8Monitoring::Plugin::Functions::_fake_exit(1);
9
10# Hardcoded checks of constants
11my %ERRORS = %Monitoring::Plugin::Functions::ERRORS;
12is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
13is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
14is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
15is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
16is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
17
18my $plugin = 'TEST_PLUGIN';
19my $np = Monitoring::Plugin->new( shortname => $plugin );
20is($np->shortname, $plugin, "shortname() is $plugin");
21
22# Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg )
23my $r;
24my @ok = (
25 [ OK, "OK", 'test the first', ],
26 [ WARNING, "WARNING", 'test the second', ],
27 [ CRITICAL, "CRITICAL", 'test the third', ],
28 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
29 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
30);
31for (@ok) {
32 # CONSTANT
33 $r = $np->plugin_exit($_->[0], $_->[2]);
34 is($r->return_code, $_->[0],
35 sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
36 like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
37 sprintf('plugin_exit(%s, $msg) output matched "%s"', $_->[1],
38 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
39
40 # $string
41 $r = $np->plugin_exit($_->[1], $_->[2]);
42 is($r->return_code, $_->[0],
43 sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
44 like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
45 sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1],
46 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
47 like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
48 sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1],
49 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
50}
51
52# plugin_exit code corner cases
53my @ugly1 = (
54 [ -1, 'testing code -1' ],
55 [ 7, 'testing code 7' ],
56 [ undef, 'testing code undef' ],
57 [ '', qq(testing code '') ],
58 [ 'string', qq(testing code 'string') ],
59);
60for (@ugly1) {
61 $r = $np->plugin_exit($_->[0], $_->[1]);
62 my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
63 is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN);
64 like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
65 sprintf('plugin_exit(%s, $msg) output matched "%s"',
66 $display, 'UNKNOWN.*' . $_->[1]));
67}
68
69# plugin_exit message corner cases
70my @ugly2 = (
71 [ '' ],
72 [ undef ],
73 [ UNKNOWN ],
74);
75for (@ugly2) {
76 $r = $np->plugin_exit(CRITICAL, $_->[0]);
77 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
78 my $display2 = defined $_->[0] ? $_->[0] : '';
79 like($r->message, qr/CRITICAL\b.*\b$display2$/,
80 sprintf('plugin_exit(%s, $msg) output matched "%s"',
81 $display1, "CRITICAL.*$display2"));
82}
83
84# Test plugin_die( $msg )
85my @msg = (
86 [ 'die you dog' ],
87 [ '' ],
88 [ undef ],
89);
90for (@msg) {
91 $r = $np->plugin_die($_->[0]);
92 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
93 my $display2 = defined $_->[0] ? $_->[0] : '';
94 is($r->return_code, UNKNOWN,
95 sprintf('plugin_die(%s) returned UNKNOWN', $display1));
96 like($r->message, qr/UNKNOWN\b.*\b$display2$/,
97 sprintf('plugin_die(%s) output matched "%s"', $display1,
98 "UNKNOWN.*$display2"));
99}
100
101# Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ),
102# plugin_die( $string, $msg ), and plugin_die( $msg, $string )
103@ok = (
104 [ OK, "OK", 'test the first', ],
105 [ WARNING, "WARNING", 'test the second', ],
106 [ CRITICAL, "CRITICAL", 'test the third', ],
107 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
108 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
109);
110for (@ok) {
111 # CONSTANT, $msg
112 $r = $np->plugin_die($_->[0], $_->[2]);
113 is($r->return_code, $_->[0],
114 sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0]));
115 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
116 sprintf('plugin_die(%s, $msg) output matched "%s"',
117 $_->[1], $_->[1] . '.*' . $_->[2]));
118
119 # $msg, CONSTANT
120 $r = $np->plugin_die($_->[2], $_->[0]);
121 is($r->return_code, $_->[0],
122 sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0]));
123 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
124 sprintf('plugin_die($msg, %s) output matched "%s"',
125 $_->[1], $_->[1] . '.*' . $_->[2]));
126
127 # $string, $msg
128 $r = $np->plugin_die($_->[1], $_->[2]);
129 is($r->return_code, $_->[0],
130 sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0]));
131 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
132 sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1],
133 $_->[1] . '.*' . $_->[2]));
134 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
135 sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1],
136 $_->[1] . '.*' . $_->[2]));
137
138 # $string, $msg
139 $r = $np->plugin_die($_->[2], $_->[1]);
140 is($r->return_code, $_->[0],
141 sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0]));
142 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
143 sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1],
144 $_->[1] . '.*' . $_->[2]));
145 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
146 sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1],
147 $_->[1] . '.*' . $_->[2]));
148}
149
150
151# shortname testing
152SKIP: {
153 skip "requires File::Basename", 2 unless eval { require File::Basename };
154 $np = Monitoring::Plugin->new( version => "1");
155 $plugin = uc File::Basename::basename($0);
156 $plugin =~ s/\..*$//;
157 is($np->shortname, $plugin, "shortname() is '$plugin'");
158 $r = $np->plugin_exit(OK, "foobar");
159 like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'");
160}
diff --git a/t/Nagios-Plugin-03.t b/t/Monitoring-Plugin-03.t
index bc4f5e3..d419342 100644
--- a/t/Nagios-Plugin-03.t
+++ b/t/Monitoring-Plugin-03.t
@@ -3,15 +3,15 @@
3use strict; 3use strict;
4use Test::More tests => 61; 4use Test::More tests => 61;
5 5
6BEGIN { 6BEGIN {
7 use_ok("Nagios::Plugin"); 7 use_ok("Monitoring::Plugin");
8 use_ok("Nagios::Plugin::Functions", ":all"); 8 use_ok("Monitoring::Plugin::Functions", ":all");
9} 9}
10Nagios::Plugin::Functions::_fake_exit(1); 10Monitoring::Plugin::Functions::_fake_exit(1);
11 11
12my $plugin = 'NP_CHECK_MESSAGES_03'; 12my $plugin = 'MP_CHECK_MESSAGES_03';
13my $np = Nagios::Plugin->new( shortname => $plugin, () ); 13my $np = Monitoring::Plugin->new( shortname => $plugin, () );
14is($np->shortname, $plugin, "shortname() is $plugin"); 14is($np->shortname, $plugin, "shortname() is $plugin");
15 15
16my ($code, $message); 16my ($code, $message);
17 17
@@ -113,11 +113,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message")
113# ------------------------------------------------------------------------- 113# -------------------------------------------------------------------------
114# join_all messages 114# join_all messages
115my $join_all = ' :: '; 115my $join_all = ' :: ';
116my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } 116my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
117 qw(critical warning ok)); 117 qw(critical warning ok));
118my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } 118my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
119 qw(critical warning)); 119 qw(critical warning));
120my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } 120my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
121 qw(warning ok)); 121 qw(warning ok));
122 122
123# critical, warning, ok 123# critical, warning, ok
@@ -172,33 +172,33 @@ is($message, 'D E F', "join_all '$join_all' (critical, warning) message is $mess
172# add_messages 172# add_messages
173 173
174# Constant codes 174# Constant codes
175$np = Nagios::Plugin->new(); 175$np = Monitoring::Plugin->new();
176$np->add_message( CRITICAL, "A B C" ); 176$np->add_message( CRITICAL, "A B C" );
177$np->add_message( WARNING, "D E F" ); 177$np->add_message( WARNING, "D E F" );
178($code, $message) = $np->check_messages(); 178($code, $message) = $np->check_messages();
179is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}"); 179is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}");
180is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message"); 180is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message");
181 181
182$np = Nagios::Plugin->new(); 182$np = Monitoring::Plugin->new();
183$np->add_message( CRITICAL, "A B C" ); 183$np->add_message( CRITICAL, "A B C" );
184($code, $message) = $np->check_messages(); 184($code, $message) = $np->check_messages();
185is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}"); 185is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}");
186is($message, $messages{critical}, "(CRITICAL) message is $message"); 186is($message, $messages{critical}, "(CRITICAL) message is $message");
187 187
188$np = Nagios::Plugin->new(); 188$np = Monitoring::Plugin->new();
189$np->add_message( WARNING, "D E F" ); 189$np->add_message( WARNING, "D E F" );
190($code, $message) = $np->check_messages(); 190($code, $message) = $np->check_messages();
191is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}"); 191is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}");
192is($message, $messages{warning}, "(WARNING) message is $message"); 192is($message, $messages{warning}, "(WARNING) message is $message");
193 193
194$np = Nagios::Plugin->new(); 194$np = Monitoring::Plugin->new();
195$np->add_message( WARNING, "D E F" ); 195$np->add_message( WARNING, "D E F" );
196$np->add_message( OK, "G H I" ); 196$np->add_message( OK, "G H I" );
197($code, $message) = $np->check_messages(); 197($code, $message) = $np->check_messages();
198is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}"); 198is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}");
199is($message, $messages{warning}, "(WARNING, OK) message is $message"); 199is($message, $messages{warning}, "(WARNING, OK) message is $message");
200 200
201$np = Nagios::Plugin->new(); 201$np = Monitoring::Plugin->new();
202$np->add_message( OK, "G H I" ); 202$np->add_message( OK, "G H I" );
203($code, $message) = $np->check_messages(); 203($code, $message) = $np->check_messages();
204is($code, OK, "(OK) code is $STATUS_TEXT{$code}"); 204is($code, OK, "(OK) code is $STATUS_TEXT{$code}");
@@ -206,33 +206,33 @@ is($message, $messages{ok}, "(OK) message is $message");
206 206
207 207
208# String codes 208# String codes
209$np = Nagios::Plugin->new(); 209$np = Monitoring::Plugin->new();
210$np->add_message( critical => "A B C" ); 210$np->add_message( critical => "A B C" );
211$np->add_message( warning => "D E F" ); 211$np->add_message( warning => "D E F" );
212($code, $message) = $np->check_messages(); 212($code, $message) = $np->check_messages();
213is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); 213is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}");
214is($message, $messages{critical}, "(critical, warning) message is $message"); 214is($message, $messages{critical}, "(critical, warning) message is $message");
215 215
216$np = Nagios::Plugin->new(); 216$np = Monitoring::Plugin->new();
217$np->add_message( critical => "A B C" ); 217$np->add_message( critical => "A B C" );
218($code, $message) = $np->check_messages(); 218($code, $message) = $np->check_messages();
219is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}"); 219is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}");
220is($message, $messages{critical}, "(critical) message is $message"); 220is($message, $messages{critical}, "(critical) message is $message");
221 221
222$np = Nagios::Plugin->new(); 222$np = Monitoring::Plugin->new();
223$np->add_message( warning => "D E F" ); 223$np->add_message( warning => "D E F" );
224($code, $message) = $np->check_messages(); 224($code, $message) = $np->check_messages();
225is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); 225is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}");
226is($message, $messages{warning}, "(warning) message is $message"); 226is($message, $messages{warning}, "(warning) message is $message");
227 227
228$np = Nagios::Plugin->new(); 228$np = Monitoring::Plugin->new();
229$np->add_message( warning => "D E F" ); 229$np->add_message( warning => "D E F" );
230$np->add_message( ok => "G H I" ); 230$np->add_message( ok => "G H I" );
231($code, $message) = $np->check_messages(); 231($code, $message) = $np->check_messages();
232is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); 232is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}");
233is($message, $messages{warning}, "(warning, ok) message is $message"); 233is($message, $messages{warning}, "(warning, ok) message is $message");
234 234
235$np = Nagios::Plugin->new(); 235$np = Monitoring::Plugin->new();
236$np->add_message( ok => "G H I" ); 236$np->add_message( ok => "G H I" );
237($code, $message) = $np->check_messages(); 237($code, $message) = $np->check_messages();
238is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); 238is($code, OK, "(ok) code is $STATUS_TEXT{$code}");
@@ -240,7 +240,7 @@ is($message, $messages{ok}, "(ok) message is $message");
240 240
241 241
242# No add_message 242# No add_message
243$np = Nagios::Plugin->new(); 243$np = Monitoring::Plugin->new();
244($code, $message) = $np->check_messages(); 244($code, $message) = $np->check_messages();
245is($code, OK, "() code is $STATUS_TEXT{$code}"); 245is($code, OK, "() code is $STATUS_TEXT{$code}");
246is($message, '', "() message is ''"); 246is($message, '', "() message is ''");
@@ -250,14 +250,13 @@ is($message, '', "() message is ''");
250# Error conditions 250# Error conditions
251 251
252# add_message errors 252# add_message errors
253$np = Nagios::Plugin->new(); 253$np = Monitoring::Plugin->new();
254ok(! defined eval { $np->add_message( foobar => 'hi mum' ) }, 254ok(! defined eval { $np->add_message( foobar => 'hi mum' ) },
255 'add_message dies on invalid code'); 255 'add_message dies on invalid code');
256ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) }, 256ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) },
257 'add_message dies on invalid code'); 257 'add_message dies on invalid code');
258# UNKNOWN and DEPENDENT error codes 258# UNKNOWN and DEPENDENT error codes
259ok(! defined eval { $np->add_message( unknown => 'hi mum' ) }, 259ok(! defined eval { $np->add_message( unknown => 'hi mum' ) },
260 'add_message dies on UNKNOWN code'); 260 'add_message dies on UNKNOWN code');
261ok(! defined eval { $np->add_message( dependent => 'hi mum' ) }, 261ok(! defined eval { $np->add_message( dependent => 'hi mum' ) },
262 'add_message dies on DEPENDENT code'); 262 'add_message dies on DEPENDENT code');
263
diff --git a/t/Nagios-Plugin-04.t b/t/Monitoring-Plugin-04.t
index e5eb3ab..41027f7 100644
--- a/t/Nagios-Plugin-04.t
+++ b/t/Monitoring-Plugin-04.t
@@ -5,25 +5,25 @@ use strict;
5#use Test::More 'no_plan'; 5#use Test::More 'no_plan';
6use Test::More tests=>30; 6use Test::More tests=>30;
7 7
8BEGIN { use_ok('Nagios::Plugin') }; 8BEGIN { use_ok('Monitoring::Plugin') };
9use Nagios::Plugin::Functions; 9use Monitoring::Plugin::Functions;
10Nagios::Plugin::Functions::_fake_exit(1); 10Monitoring::Plugin::Functions::_fake_exit(1);
11 11
12 12
13eval { Nagios::Plugin->new(); }; 13eval { Monitoring::Plugin->new(); };
14ok(! $@, "constructor DOESN'T die without usage"); 14ok(! $@, "constructor DOESN'T die without usage");
15 15
16my $p = Nagios::Plugin->new(); 16my $p = Monitoring::Plugin->new();
17eval { $p->add_arg('warning', 'warning') }; 17eval { $p->add_arg('warning', 'warning') };
18ok($@, "add_arg() dies if you haven't instantiated with usage"); 18ok($@, "add_arg() dies if you haven't instantiated with usage");
19eval { $p->getopts }; 19eval { $p->getopts };
20ok($@, "getopts() dies if you haven't instantiated with usage"); 20ok($@, "getopts() dies if you haven't instantiated with usage");
21 21
22$p = Nagios::Plugin->new( usage => "dummy usage statement" ); 22$p = Monitoring::Plugin->new( usage => "dummy usage statement" );
23 23
24# option accessors work 24# option accessors work
25can_ok $p, 'opts'; 25can_ok $p, 'opts';
26isa_ok $p->opts, 'Nagios::Plugin::Getopt', "Getopt object is defined"; 26isa_ok $p->opts, 'Monitoring::Plugin::Getopt', "Getopt object is defined";
27 27
28$p->add_arg('warning|w=s', "warning"); 28$p->add_arg('warning|w=s', "warning");
29$p->add_arg('critical|c=s', "critical"); 29$p->add_arg('critical|c=s', "critical");
@@ -35,11 +35,11 @@ is $p->opts->critical, "10", "critical opt is accessible";
35 35
36 36
37can_ok $p, 'perfdata'; 37can_ok $p, 'perfdata';
38#isa_ok $p->perfdata, 'Nagios::Plugin::Performance', "perfdata object is defined"; 38#isa_ok $p->perfdata, 'Monitoring::Plugin::Performance', "perfdata object is defined";
39 39
40 40
41can_ok $p, 'threshold'; 41can_ok $p, 'threshold';
42#isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined"; 42#isa_ok $p->threshold, 'Monitoring::Plugin::Threshold', "threshold object is defined";
43 43
44 44
45eval { $p->check_threshold() }; 45eval { $p->check_threshold() };
@@ -60,20 +60,20 @@ is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL w
60 60
61# thresholds set explicitly 61# thresholds set explicitly
62is $p->check_threshold( 62is $p->check_threshold(
63 check => 2, 63 check => 2,
64 warning => 50, 64 warning => 50,
65 critical => 100 65 critical => 100
66), OK, "check_threshold explicit OK"; 66), OK, "check_threshold explicit OK";
67 67
68is $p->check_threshold( 68is $p->check_threshold(
69 check => 66, 69 check => 66,
70 warning => 50, 70 warning => 50,
71 critical => 100 71 critical => 100
72), WARNING, "check_threshold explicit WARNING"; 72), WARNING, "check_threshold explicit WARNING";
73 73
74 74
75is $p->check_threshold( 75is $p->check_threshold(
76 check => -1, 76 check => -1,
77 warning => 5, 77 warning => 5,
78 critical => '0:5', 78 critical => '0:5',
79), CRITICAL, "check_threshold explicit CRITICAL"; 79), CRITICAL, "check_threshold explicit CRITICAL";
@@ -82,7 +82,7 @@ is $p->check_threshold(
82 82
83# what happens if you forget to define warning or critical thresholds? 83# what happens if you forget to define warning or critical thresholds?
84$p = undef; 84$p = undef;
85$p = Nagios::Plugin->new(); 85$p = Monitoring::Plugin->new();
86 86
87is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN"; 87is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN";
88is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN"; 88is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN";
diff --git a/t/Nagios-Plugin-05.t b/t/Monitoring-Plugin-05.t
index cc602cc..d17464f 100644
--- a/t/Nagios-Plugin-05.t
+++ b/t/Monitoring-Plugin-05.t
@@ -1,16 +1,15 @@
1# Check for exported vars 1# Check for exported vars
2# Can't include Nagios::Plugin::Functions because it also exports %STATUS_TEXT 2# Can't include Monitoring::Plugin::Functions because it also exports %STATUS_TEXT
3 3
4use strict; 4use strict;
5use Test::More tests=>4; 5use Test::More tests=>4;
6 6
7BEGIN { use_ok('Nagios::Plugin') }; 7BEGIN { use_ok('Monitoring::Plugin') };
8 8
9eval ' $_ = $STATUS_TEXT{0} '; 9eval ' $_ = $STATUS_TEXT{0} ';
10like( $@, '/Global symbol "%STATUS_TEXT" requires explicit package name/' ); 10like( $@, '/Global symbol "%STATUS_TEXT" requires explicit package name/' );
11 11
12use_ok("Nagios::Plugin", qw(%STATUS_TEXT)); 12use_ok("Monitoring::Plugin", qw(%STATUS_TEXT));
13 13
14eval ' $_ = $STATUS_TEXT{0} '; 14eval ' $_ = $STATUS_TEXT{0} ';
15is( $@, '' ); 15is( $@, '' );
16
diff --git a/t/Monitoring-Plugin-Functions-01.t b/t/Monitoring-Plugin-Functions-01.t
new file mode 100644
index 0000000..084ad28
--- /dev/null
+++ b/t/Monitoring-Plugin-Functions-01.t
@@ -0,0 +1,161 @@
1
2use strict;
3use Test::More tests => 113;
4
5BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); }
6Monitoring::Plugin::Functions::_fake_exit(1);
7
8my $this_version=$Monitoring::Plugin::Functions::VERSION;
9foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) {
10 my $mod = "Monitoring::Plugin$m";
11 use_ok($mod);
12 # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing
13 my $v = "$mod"."::VERSION";
14 my $a = eval "\$$v";
15 is($a, $this_version, "Version number for $mod the same as Functions: $this_version");
16}
17
18# check get_shortname
19is(get_shortname, "MONITORING-PLUGIN-FUNCTIONS-01", "get_shortname ok");
20
21# Hardcoded checks of constants
22ok(%ERRORS, '%ERRORS defined');
23is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
24is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
25is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
26is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
27is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
28
29# Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg )
30my $r;
31my @ok = (
32 [ OK, "OK", 'test the first', ],
33 [ WARNING, "WARNING", 'test the second', ],
34 [ CRITICAL, "CRITICAL", 'test the third', ],
35 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
36 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
37);
38for (@ok) {
39 # CONSTANT
40 $r = plugin_exit($_->[0], $_->[2]);
41 is($r->return_code, $_->[0],
42 sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
43 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
44 sprintf('plugin_exit(%s, $msg) output matched "%s"',
45 $_->[1], $_->[1] . '.*' . $_->[2]));
46
47 # $string
48 $r = plugin_exit($_->[1], $_->[2]);
49 is($r->return_code, $_->[0],
50 sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
51 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
52 sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1],
53 $_->[1] . '.*' . $_->[2]));
54 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
55 sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1],
56 $_->[1] . '.*' . $_->[2]));
57}
58
59# plugin_exit code corner cases
60my @ugly1 = (
61 [ -1, 'testing code -1' ],
62 [ 7, 'testing code 7' ],
63 [ undef, 'testing code undef' ],
64 [ '', qq(testing code '') ],
65 [ 'string', qq(testing code 'string') ],
66);
67for (@ugly1) {
68 $r = plugin_exit($_->[0], $_->[1]);
69 my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
70 is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN);
71 like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
72 sprintf('plugin_exit(%s, $msg) output matched "%s"',
73 $display, 'UNKNOWN.*' . $_->[1]));
74}
75
76# plugin_exit message corner cases
77my @ugly2 = (
78 [ '' ],
79 [ undef ],
80 [ UNKNOWN ],
81);
82for (@ugly2) {
83 $r = plugin_exit(CRITICAL, $_->[0]);
84 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
85 my $display2 = defined $_->[0] ? $_->[0] : '';
86 like($r->message, qr/CRITICAL\b.*\b$display2$/,
87 sprintf('plugin_exit(%s, $msg) output matched "%s"',
88 $display1, "CRITICAL.*$display2"));
89}
90
91# Test plugin_die( $msg )
92my @msg = (
93 [ 'die you dog' ],
94 [ '' ],
95 [ undef ],
96);
97for (@msg) {
98 $r = plugin_die($_->[0]);
99 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
100 my $display2 = defined $_->[0] ? $_->[0] : '';
101 is($r->return_code, UNKNOWN,
102 sprintf('plugin_die(%s) returned UNKNOWN', $display1));
103 like($r->message, qr/UNKNOWN\b.*\b$display2$/,
104 sprintf('plugin_die(%s) output matched "%s"', $display1,
105 "UNKNOWN.*$display2"));
106}
107
108# Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ),
109# plugin_die( $string, $msg ), and plugin_die( $msg, $string )
110@ok = (
111 [ OK, "OK", 'test the first', ],
112 [ WARNING, "WARNING", 'test the second', ],
113 [ CRITICAL, "CRITICAL", 'test the third', ],
114 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
115 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
116);
117for (@ok) {
118 # CONSTANT, $msg
119 $r = plugin_die($_->[0], $_->[2]);
120 is($r->return_code, $_->[0],
121 sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0]));
122 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
123 sprintf('plugin_die(%s, $msg) output matched "%s"',
124 $_->[1], $_->[1] . '.*' . $_->[2]));
125
126 # $msg, CONSTANT
127 $r = plugin_die($_->[2], $_->[0]);
128 is($r->return_code, $_->[0],
129 sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0]));
130 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
131 sprintf('plugin_die($msg, %s) output matched "%s"',
132 $_->[1], $_->[1] . '.*' . $_->[2]));
133
134 # $string, $msg
135 $r = plugin_die($_->[1], $_->[2]);
136 is($r->return_code, $_->[0],
137 sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0]));
138 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
139 sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1],
140 $_->[1] . '.*' . $_->[2]));
141 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
142 sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1],
143 $_->[1] . '.*' . $_->[2]));
144
145 # $string, $msg
146 $r = plugin_die($_->[2], $_->[1]);
147 is($r->return_code, $_->[0],
148 sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0]));
149 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
150 sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1],
151 $_->[1] . '.*' . $_->[2]));
152 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
153 sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1],
154 $_->[1] . '.*' . $_->[2]));
155}
156
157# Check that _use_die set to 1 will catch exceptions correctly
158Monitoring::Plugin::Functions::_fake_exit(0);
159Monitoring::Plugin::Functions::_use_die(1);
160eval { plugin_die("Using die") };
161is( $@, "MONITORING-PLUGIN-FUNCTIONS-01 UNKNOWN - Using die\n", "Caught exception");
diff --git a/t/Nagios-Plugin-Functions-02.t b/t/Monitoring-Plugin-Functions-02.t
index 1a9351b..3796210 100644
--- a/t/Nagios-Plugin-Functions-02.t
+++ b/t/Monitoring-Plugin-Functions-02.t
@@ -3,7 +3,7 @@
3use strict; 3use strict;
4use Test::More tests => 37; 4use Test::More tests => 37;
5 5
6BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } 6BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
7 7
8my ($code, $message); 8my ($code, $message);
9 9
@@ -105,11 +105,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message")
105# ------------------------------------------------------------------------- 105# -------------------------------------------------------------------------
106# join_all messages 106# join_all messages
107my $join_all = ' :: '; 107my $join_all = ' :: ';
108my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } 108my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
109 qw(critical warning ok)); 109 qw(critical warning ok));
110my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } 110my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
111 qw(critical warning)); 111 qw(critical warning));
112my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } 112my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
113 qw(warning ok)); 113 qw(warning ok));
114 114
115# critical, warning, ok 115# critical, warning, ok
@@ -175,4 +175,3 @@ ok(! defined eval { ($code, $message) = check_messages(critical => $arrays{criti
175 175
176ok(defined eval { ($code, $message) = check_messages(critical => $arrays{critical}, warning => $arrays{warning}) }, 176ok(defined eval { ($code, $message) = check_messages(critical => $arrays{critical}, warning => $arrays{warning}) },
177 "check_messages ok with 'critical' and 'warning' messages"); 177 "check_messages ok with 'critical' and 'warning' messages");
178
diff --git a/t/Nagios-Plugin-Functions-03.t b/t/Monitoring-Plugin-Functions-03.t
index 3706e4c..9f0a62c 100644
--- a/t/Nagios-Plugin-Functions-03.t
+++ b/t/Monitoring-Plugin-Functions-03.t
@@ -3,7 +3,7 @@
3use strict; 3use strict;
4use Test::More tests => 8; 4use Test::More tests => 8;
5 5
6BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } 6BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
7 7
8my $new_state = max_state( OK, WARNING ); 8my $new_state = max_state( OK, WARNING );
9 9
diff --git a/t/Nagios-Plugin-Functions-04.t b/t/Monitoring-Plugin-Functions-04.t
index d3ff05c..0a7c4e4 100644
--- a/t/Nagios-Plugin-Functions-04.t
+++ b/t/Monitoring-Plugin-Functions-04.t
@@ -3,7 +3,7 @@
3use strict; 3use strict;
4use Test::More tests => 8; 4use Test::More tests => 8;
5 5
6BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } 6BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
7 7
8my $new_state = max_state_alt( OK, WARNING ); 8my $new_state = max_state_alt( OK, WARNING );
9 9
diff --git a/t/Nagios-Plugin-Getopt-01.t b/t/Monitoring-Plugin-Getopt-01.t
index 7076d75..36f1f55 100644
--- a/t/Nagios-Plugin-Getopt-01.t
+++ b/t/Monitoring-Plugin-Getopt-01.t
@@ -1,33 +1,33 @@
1# Nagios::Plugin::Getopt basic tests 1# Monitoring::Plugin::Getopt basic tests
2 2
3use strict; 3use strict;
4 4
5use Test::More tests => 76; 5use Test::More tests => 76;
6BEGIN { use_ok('Nagios::Plugin::Getopt') }; 6BEGIN { use_ok('Monitoring::Plugin::Getopt') };
7 7
8# Needed to get evals to work in testing 8# Needed to get evals to work in testing
9Nagios::Plugin::Functions::_use_die(1); 9Monitoring::Plugin::Functions::_use_die(1);
10 10
11my %PARAM = ( 11my %PARAM = (
12 version => '0.01', 12 version => '0.01',
13 url => 'http://www.openfusion.com.au/labs/nagios/', 13 url => 'http://www.openfusion.com.au/labs/nagios/',
14 blurb => 'This plugin tests various stuff.', 14 blurb => 'This plugin tests various stuff.',
15 usage => "Usage: %s -H <host> -w <warning_threshold> 15 usage => "Usage: %s -H <host> -w <warning_threshold>
16 -c <critical threshold>", 16 -c <critical threshold>",
17 plugin => 'test_plugin', 17 plugin => 'test_plugin',
18); 18);
19 19
20sub setup 20sub setup
21{ 21{
22 # Instantiate object 22 # Instantiate object
23 my $ng = Nagios::Plugin::Getopt->new(%PARAM); 23 my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
24 ok($ng, 'constructor ok'); 24 ok($ng, 'constructor ok');
25 25
26 # Add argument - short form - arg spec, help text, default, required? 26 # Add argument - short form - arg spec, help text, default, required?
27 $ng->arg('warning|w=s' => 27 $ng->arg('warning|w=s' =>
28 qq(-w, --warning=INTEGER\n Exit with WARNING status if less than INTEGER foobars are free), 28 qq(-w, --warning=INTEGER\n Exit with WARNING status if less than INTEGER foobars are free),
29 5); 29 5);
30 30
31 # Add argument - named version 31 # Add argument - named version
32 $ng->arg( 32 $ng->arg(
33 spec => 'critical|c=i', 33 spec => 'critical|c=i',
@@ -147,4 +147,3 @@ like($@, qr/--verbose/, 'help includes default options 2');
147like($@, qr/--warning/, 'help includes custom option 1'); 147like($@, qr/--warning/, 'help includes custom option 1');
148like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args'); 148like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args');
149unlike($@, qr/Missing arg/, 'no missing arguments'); 149unlike($@, qr/Missing arg/, 'no missing arguments');
150
diff --git a/t/Nagios-Plugin-Getopt-02.t b/t/Monitoring-Plugin-Getopt-02.t
index f83b180..c6c563e 100644
--- a/t/Nagios-Plugin-Getopt-02.t
+++ b/t/Monitoring-Plugin-Getopt-02.t
@@ -1,27 +1,27 @@
1# Nagios::Plugin::Getopt timeout tests 1# Monitoring::Plugin::Getopt timeout tests
2 2
3use strict; 3use strict;
4 4
5use Test::More tests => 14; 5use Test::More tests => 14;
6BEGIN { use_ok('Nagios::Plugin::Getopt') }; 6BEGIN { use_ok('Monitoring::Plugin::Getopt') };
7 7
8# Needed to get evals to work in testing 8# Needed to get evals to work in testing
9Nagios::Plugin::Functions::_use_die(1); 9Monitoring::Plugin::Functions::_use_die(1);
10 10
11my %PARAM = ( 11my %PARAM = (
12 version => '0.01', 12 version => '0.01',
13 url => 'http://www.openfusion.com.au/labs/nagios/', 13 url => 'http://www.openfusion.com.au/labs/nagios/',
14 blurb => 'This plugin tests various stuff.', 14 blurb => 'This plugin tests various stuff.',
15 usage => "Usage: %s -H <host> -w <warning_threshold> 15 usage => "Usage: %s -H <host> -w <warning_threshold>
16 -c <critical threshold>", 16 -c <critical threshold>",
17 plugin => 'test_plugin', 17 plugin => 'test_plugin',
18 timeout => 18, 18 timeout => 18,
19); 19);
20 20
21sub setup 21sub setup
22{ 22{
23 # Instantiate object 23 # Instantiate object
24 my $ng = Nagios::Plugin::Getopt->new(%PARAM); 24 my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
25 ok($ng, 'constructor ok'); 25 ok($ng, 'constructor ok');
26 return $ng; 26 return $ng;
27} 27}
@@ -61,4 +61,3 @@ alarm($ng->timeout);
61# Loop 61# Loop
62ok(! defined eval { 1 while 1 }, 'loop timed out'); 62ok(! defined eval { 1 while 1 }, 'loop timed out');
63like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok'); 63like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok');
64
diff --git a/t/Nagios-Plugin-Getopt-03.t b/t/Monitoring-Plugin-Getopt-03.t
index 560b782..6490145 100644
--- a/t/Nagios-Plugin-Getopt-03.t
+++ b/t/Monitoring-Plugin-Getopt-03.t
@@ -1,4 +1,4 @@
1# Nagios::Plugin::Getopt --extra-opts tests 1# Monitoring::Plugin::Getopt --extra-opts tests
2 2
3use strict; 3use strict;
4use File::Spec; 4use File::Spec;
@@ -6,15 +6,15 @@ use File::Basename;
6use IO::File; 6use IO::File;
7 7
8use Test::More qw(no_plan); 8use Test::More qw(no_plan);
9BEGIN { use_ok('Nagios::Plugin::Getopt') }; 9BEGIN { use_ok('Monitoring::Plugin::Getopt') };
10 10
11# Needed to get evals to work in testing 11# Needed to get evals to work in testing
12Nagios::Plugin::Functions::_use_die(1); 12Monitoring::Plugin::Functions::_use_die(1);
13 13
14my $tdir = 'npg03'; 14my $tdir = 'npg03';
15if (! -d $tdir) { 15if (! -d $tdir) {
16 my $ttdir = File::Spec->catdir('t', $tdir); 16 my $ttdir = File::Spec->catdir('t', $tdir);
17 die "missing '$tdir' directory\n" unless -d $ttdir; 17 die "missing '$tdir' directory\n" unless -d $ttdir;
18 $tdir = $ttdir; 18 $tdir = $ttdir;
19} 19}
20 20
@@ -30,22 +30,22 @@ for my $efile (glob File::Spec->catfile($tdir, 'expected', '*')) {
30 } 30 }
31} 31}
32 32
33# Override NAGIOS_CONFIG_PATH to use our test plugins.ini file 33# Override MONITORING_CONFIG_PATH to use our test plugins.ini file
34$ENV{NAGIOS_CONFIG_PATH} = "/random/bogus/path:$tdir"; 34$ENV{MONITORING_CONFIG_PATH} = "/random/bogus/path:$tdir";
35 35
36my %PARAM = ( 36my %PARAM = (
37 version => '0.01', 37 version => '0.01',
38 blurb => 'This plugin tests various stuff.', 38 blurb => 'This plugin tests various stuff.',
39 usage => "Usage: %s -H <host> -w <warning_threshold> 39 usage => "Usage: %s -H <host> -w <warning_threshold>
40 -c <critical threshold>", 40 -c <critical threshold>",
41); 41);
42 42
43sub ng_setup 43sub ng_setup
44{ 44{
45 my $arg = shift; 45 my $arg = shift;
46 46
47 # Instantiate object 47 # Instantiate object
48 my $ng = Nagios::Plugin::Getopt->new(%PARAM); 48 my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
49 49
50 if (ref $arg eq 'ARRAY' && @$arg) { 50 if (ref $arg eq 'ARRAY' && @$arg) {
51 $ng->arg(%$_) foreach @$arg; 51 $ng->arg(%$_) foreach @$arg;
@@ -54,7 +54,7 @@ sub ng_setup
54 return $ng; 54 return $ng;
55} 55}
56 56
57# Setup our Nagios::Plugin::Getopt object 57# Setup our Monitoring::Plugin::Getopt object
58my $ng; 58my $ng;
59my $arg = [ 59my $arg = [
60 { spec => 'S', help => '-S' }, 60 { spec => 'S', help => '-S' },
@@ -85,9 +85,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) {
85 $cmd =~ s/^\s+//; 85 $cmd =~ s/^\s+//;
86 my ($plugin, @args) = split /\s+/, $cmd; 86 my ($plugin, @args) = split /\s+/, $cmd;
87 87
88 # Fake out the plugin name 88 # Fake out the plugin name
89 $ng->{_attr}->{plugin} = $plugin; 89 $ng->{_attr}->{plugin} = $plugin;
90 90
91 # Parse the options 91 # Parse the options
92 SKIP: { 92 SKIP: {
93 skip "Skipping ..." if $SKIP{$infile}; 93 skip "Skipping ..." if $SKIP{$infile};
@@ -99,10 +99,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) {
99 ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)"); 99 ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)");
100 is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/); 100 is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/);
101 } 101 }
102 else { 102 else {
103 is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile); 103 is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile);
104 } 104 }
105 } 105 }
106 } 106 }
107} 107}
108
diff --git a/t/Nagios-Plugin-Getopt-04.t b/t/Monitoring-Plugin-Getopt-04.t
index 115f2a2..b6345d0 100644
--- a/t/Nagios-Plugin-Getopt-04.t
+++ b/t/Monitoring-Plugin-Getopt-04.t
@@ -1,29 +1,29 @@
1# Nagios::Plugin::Getopt spec-to-help generation tests 1# Monitoring::Plugin::Getopt spec-to-help generation tests
2 2
3use strict; 3use strict;
4 4
5use Test::More tests => 11; 5use Test::More tests => 11;
6BEGIN { use_ok('Nagios::Plugin::Getopt') }; 6BEGIN { use_ok('Monitoring::Plugin::Getopt') };
7 7
8# Needed to get evals to work in testing 8# Needed to get evals to work in testing
9Nagios::Plugin::Functions::_use_die(1); 9Monitoring::Plugin::Functions::_use_die(1);
10 10
11my %PARAM = ( 11my %PARAM = (
12 version => '0.01', 12 version => '0.01',
13 usage => "Don't use this plugin!", 13 usage => "Don't use this plugin!",
14); 14);
15 15
16sub setup 16sub setup
17{ 17{
18 # Instantiate object 18 # Instantiate object
19 my $ng = Nagios::Plugin::Getopt->new(%PARAM); 19 my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
20 ok($ng, 'constructor ok'); 20 ok($ng, 'constructor ok');
21 21
22 # Positional args, no short arguments, INTEGER 22 # Positional args, no short arguments, INTEGER
23 $ng->arg('warning=i' => 23 $ng->arg('warning=i' =>
24 qq(Exit with WARNING status if less than INTEGER foobars are free), 24 qq(Exit with WARNING status if less than INTEGER foobars are free),
25 5); 25 5);
26 26
27 # Named args, long + short arguments, INTEGER 27 # Named args, long + short arguments, INTEGER
28 $ng->arg( 28 $ng->arg(
29 spec => 'critical|c=i', 29 spec => 'critical|c=i',
@@ -35,7 +35,7 @@ sub setup
35 $ng->arg( 35 $ng->arg(
36 spec => 'x|y|z=s', 36 spec => 'x|y|z=s',
37 help => qq(Foobar. Default: %s), 37 help => qq(Foobar. Default: %s),
38 default => "XYZ", 38 default => "XYZ",
39 ); 39 );
40 40
41 # Named args, multiple mixed, no label 41 # Named args, multiple mixed, no label
@@ -95,4 +95,3 @@ like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok');
95like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok'); 95like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok');
96like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok'); 96like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok');
97#print $@; 97#print $@;
98
diff --git a/t/Monitoring-Plugin-Performance-02.t b/t/Monitoring-Plugin-Performance-02.t
new file mode 100644
index 0000000..c024685
--- /dev/null
+++ b/t/Monitoring-Plugin-Performance-02.t
@@ -0,0 +1,13 @@
1
2use strict;
3use Test::More tests => 3;
4use_ok("Monitoring::Plugin::Performance", use_die => 1);
5
6eval { Monitoring::Plugin::Functions::plugin_die("Testing") };
7is( $@, "MONITORING-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
8
9
10use_ok("Monitoring::Plugin::Performance");
11eval { Monitoring::Plugin::Functions::plugin_die("Test OK exit", 0) };
12
13fail("Should not get here if code works correctly because prior plugin_die should have exited");
diff --git a/t/Nagios-Plugin-Performance.t b/t/Monitoring-Plugin-Performance.t
index 8dce336..bedb2e2 100644
--- a/t/Nagios-Plugin-Performance.t
+++ b/t/Monitoring-Plugin-Performance.t
@@ -2,61 +2,61 @@
2use warnings; 2use warnings;
3use strict; 3use strict;
4use Test::More; 4use Test::More;
5use Nagios::Plugin::Functions; 5use Monitoring::Plugin::Functions;
6Nagios::Plugin::Functions::_fake_exit(1); 6Monitoring::Plugin::Functions::_fake_exit(1);
7 7
8 8
9my (@p, $p); 9my (@p, $p);
10my @test = ( 10my @test = (
11 { 11 {
12 perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root", 12 perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root",
13 }, { 13 }, {
14 perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var", 14 perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var",
15 }, { 15 }, {
16 perfoutput => '/var/long@:-/filesystem/name/and/bad/chars=218MB;9443;9448', label => '/var/long@:-/filesystem/name/and/bad/chars', rrdlabel => 'var_long____filesys', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => 'var_long____filesystem_name_and_bad_chars', 16 perfoutput => '/var/long@:-/filesystem/name/and/bad/chars=218MB;9443;9448', label => '/var/long@:-/filesystem/name/and/bad/chars', rrdlabel => 'var_long____filesys', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => 'var_long____filesystem_name_and_bad_chars',
17 }, { 17 }, {
18 perfoutput => "'page file'=36%;80;90;", 18 perfoutput => "'page file'=36%;80;90;",
19 expected_perfoutput => "'page file'=36%;80;90", 19 expected_perfoutput => "'page file'=36%;80;90",
20 label => 'page file', 20 label => 'page file',
21 rrdlabel => 'page_file', 21 rrdlabel => 'page_file',
22 value => '36', 22 value => '36',
23 uom => '%', 23 uom => '%',
24 warning => 80, 24 warning => 80,
25 critical => 90, 25 critical => 90,
26 min => undef, 26 min => undef,
27 max => undef, 27 max => undef,
28 clean_label => 'page_file', 28 clean_label => 'page_file',
29 }, { 29 }, {
30 perfoutput => "'data'=5;;;;", 30 perfoutput => "'data'=5;;;;",
31 expected_perfoutput => "data=5;;", 31 expected_perfoutput => "data=5;;",
32 label => 'data', 32 label => 'data',
33 rrdlabel => 'data', 33 rrdlabel => 'data',
34 value => 5, 34 value => 5,
35 uom => "", 35 uom => "",
36 warning => undef, 36 warning => undef,
37 critical => undef, 37 critical => undef,
38 min => undef, 38 min => undef,
39 max => undef, 39 max => undef,
40 clean_label => 'data', 40 clean_label => 'data',
41 }, 41 },
42); 42);
43 43
44plan tests => (11 * scalar @test) + 176; 44plan tests => (11 * scalar @test) + 176;
45 45
46use_ok('Nagios::Plugin::Performance'); 46use_ok('Monitoring::Plugin::Performance');
47diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; 47diag "\nusing Monitoring::Plugin::Performance revision ". $Monitoring::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
48 48
49# Round-trip tests 49# Round-trip tests
50for my $t (@test) { 50for my $t (@test) {
51 # Parse to components 51 # Parse to components
52 ($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput}); 52 ($p) = Monitoring::Plugin::Performance->parse_perfstring($t->{perfoutput});
53 is ($p->value, $t->{value}, "value okay $t->{value}"); 53 is ($p->value, $t->{value}, "value okay $t->{value}");
54 is ($p->label, $t->{label}, "label okay $t->{label}"); 54 is ($p->label, $t->{label}, "label okay $t->{label}");
55 is ($p->uom, $t->{uom}, "uom okay $t->{uom}"); 55 is ($p->uom, $t->{uom}, "uom okay $t->{uom}");
56 56
57 # Construct from components 57 # Construct from components
58 my @construct = qw(label value uom warning critical min max); 58 my @construct = qw(label value uom warning critical min max);
59 $p = Nagios::Plugin::Performance->new(map { $_ => $t->{$_} } @construct); 59 $p = Monitoring::Plugin::Performance->new(map { $_ => $t->{$_} } @construct);
60 my $expected_perfoutput = $t->{perfoutput}; 60 my $expected_perfoutput = $t->{perfoutput};
61 if (exists $t->{expected_perfoutput}) { 61 if (exists $t->{expected_perfoutput}) {
62 $expected_perfoutput = $t->{expected_perfoutput}; 62 $expected_perfoutput = $t->{expected_perfoutput};
@@ -75,9 +75,9 @@ for my $t (@test) {
75 75
76 # Construct using threshold 76 # Construct using threshold
77 @construct = qw(label value uom min max); 77 @construct = qw(label value uom min max);
78 $p = Nagios::Plugin::Performance->new( 78 $p = Monitoring::Plugin::Performance->new(
79 map({ $_ => $t->{$_} } @construct), 79 map({ $_ => $t->{$_} } @construct),
80 threshold => Nagios::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}), 80 threshold => Monitoring::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}),
81 ); 81 );
82 is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)"); 82 is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)");
83 # Check warning/critical accessors 83 # Check warning/critical accessors
@@ -92,7 +92,7 @@ for my $t (@test) {
92 92
93 93
94# Test multiple parse_perfstrings 94# Test multiple parse_perfstrings
95@p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); 95@p = Monitoring::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
96cmp_ok( $p[0]->label, 'eq', "/", "label okay"); 96cmp_ok( $p[0]->label, 'eq', "/", "label okay");
97cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); 97cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay");
98cmp_ok( $p[0]->value, '==', 382, "value okay"); 98cmp_ok( $p[0]->value, '==', 382, "value okay");
@@ -109,14 +109,14 @@ cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay");
109cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); 109cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay");
110cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); 110cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay");
111 111
112@p = Nagios::Plugin::Performance->parse_perfstring("rubbish"); 112@p = Monitoring::Plugin::Performance->parse_perfstring("rubbish");
113ok( ! @p, "Errors correctly"); 113ok( ! @p, "Errors correctly");
114ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); 114ok( ! Monitoring::Plugin::Performance->parse_perfstring(""), "Errors on empty string");
115 115
116 116
117 117
118# Check 1 bad with 1 good format output 118# Check 1 bad with 1 good format output
119@p = Nagios::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); 119@p = Monitoring::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 ");
120is( scalar @p, 1, "One bad piece of data - only one returned" ); 120is( scalar @p, 1, "One bad piece of data - only one returned" );
121is( $p[0]->label, "pl", "label okay for different numeric"); 121is( $p[0]->label, "pl", "label okay for different numeric");
122is( $p[0]->value, 0, "value okay"); 122is( $p[0]->value, 0, "value okay");
@@ -127,7 +127,7 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
127is( $p[0]->threshold->critical, "60", "warn okay"); 127is( $p[0]->threshold->critical, "60", "warn okay");
128 128
129# Same as above, but order swapped 129# Same as above, but order swapped
130@p = Nagios::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); 130@p = Monitoring::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; ");
131is( scalar @p, 1, "One bad piece of data - only one returned" ); 131is( scalar @p, 1, "One bad piece of data - only one returned" );
132is( $p[0]->label, "pl", "label okay for different numeric"); 132is( $p[0]->label, "pl", "label okay for different numeric");
133is( $p[0]->value, 0, "value okay"); 133is( $p[0]->value, 0, "value okay");
@@ -140,7 +140,7 @@ is( $p[0]->threshold->critical, "60", "warn okay");
140 140
141 141
142 142
143@p = Nagios::Plugin::Performance->parse_perfstring( 143@p = Monitoring::Plugin::Performance->parse_perfstring(
144 "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); 144 "time=0.001229s;0.000000;0.000000;0.000000;10.000000");
145cmp_ok( $p[0]->label, "eq", "time", "label okay"); 145cmp_ok( $p[0]->label, "eq", "time", "label okay");
146cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); 146cmp_ok( $p[0]->value, "==", 0.001229, "value okay");
@@ -150,27 +150,27 @@ cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
150 150
151 151
152 152
153@p = Nagios::Plugin::Performance->parse_perfstring( 153@p = Monitoring::Plugin::Performance->parse_perfstring(
154 "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); 154 "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;");
155cmp_ok( $p[0]->label, "eq", "load1", "label okay"); 155cmp_ok( $p[0]->label, "eq", "load1", "label okay");
156cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); 156cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string");
157cmp_ok( $p[0]->uom, "eq", "", "uom empty"); 157cmp_ok( $p[0]->uom, "eq", "", "uom empty");
158cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); 158cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay");
159cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); 159cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay");
160cmp_ok( $p[1]->label, "eq", "load5", "label okay"); 160cmp_ok( $p[1]->label, "eq", "load5", "label okay");
161cmp_ok( $p[2]->label, "eq", "load15", "label okay"); 161cmp_ok( $p[2]->label, "eq", "load15", "label okay");
162 162
163@p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); 163@p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0" );
164cmp_ok( $p[0]->label, "eq", "users", "label okay"); 164cmp_ok( $p[0]->label, "eq", "users", "label okay");
165cmp_ok( $p[0]->value, "==", 4, "value okay"); 165cmp_ok( $p[0]->value, "==", 4, "value okay");
166cmp_ok( $p[0]->uom, "eq", "", "uom empty"); 166cmp_ok( $p[0]->uom, "eq", "", "uom empty");
167cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); 167cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay");
168cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); 168cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay");
169 169
170@p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" ); 170@p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" );
171 ok( @p, "parse correctly with linefeed at end (nagiosgraph)"); 171 ok( @p, "parse correctly with linefeed at end (nagiosgraph)");
172 172
173@p = Nagios::Plugin::Performance->parse_perfstring( 173@p = Monitoring::Plugin::Performance->parse_perfstring(
174 "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); 174 "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" );
175cmp_ok( $p[0]->label, "eq", "time", "label okay"); 175cmp_ok( $p[0]->label, "eq", "time", "label okay");
176cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); 176cmp_ok( $p[0]->value, "eq", "0.2153", "value okay");
@@ -184,21 +184,21 @@ cmp_ok( $p[1]->uom, "eq", "B", "uom okay");
184 ok( ! $p[1]->threshold->critical->is_set, "crit okay"); 184 ok( ! $p[1]->threshold->critical->is_set, "crit okay");
185 185
186# Edge cases 186# Edge cases
187@p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20"); 187@p = Monitoring::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20");
188cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); 188cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _");
189 ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); 189 ok( $p[0]->threshold->warning->is_set, "Warning range has been set");
190cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); 190cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters");
191cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); 191cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label");
192 192
193# turn off fake_exit and enable use_die so we pick up on errors via nagios_die 193# turn off fake_exit and enable use_die so we pick up on errors via plugin_die
194Nagios::Plugin::Functions::_use_die(1); 194Monitoring::Plugin::Functions::_use_die(1);
195Nagios::Plugin::Functions::_fake_exit(0); 195Monitoring::Plugin::Functions::_fake_exit(0);
196 196
197@p = Nagios::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000"); 197@p = Monitoring::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000");
198cmp_ok( $p[0]->label, "eq", "time", "label okay"); 198cmp_ok( $p[0]->label, "eq", "time", "label okay");
199cmp_ok( $p[0]->value, "eq", "0.002722", "value okay"); 199cmp_ok( $p[0]->value, "eq", "0.002722", "value okay");
200cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); 200cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
201 ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set"); 201 ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set");
202 ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set"); 202 ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set");
203# The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification 203# The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification
204# of 0. See http://rt.cpan.org/Ticket/Display.html?id=41109 204# of 0. See http://rt.cpan.org/Ticket/Display.html?id=41109
@@ -206,7 +206,7 @@ cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
206is( $p[0]->threshold->warning."", "0", "warn okay"); 206is( $p[0]->threshold->warning."", "0", "warn okay");
207is( $p[0]->threshold->critical."", "0", "crit okay"); 207is( $p[0]->threshold->critical."", "0", "crit okay");
208 208
209@p = Nagios::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95"); 209@p = Monitoring::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95");
210cmp_ok( $p[0]->label, "eq", "pct_used", "label okay"); 210cmp_ok( $p[0]->label, "eq", "pct_used", "label okay");
211cmp_ok( $p[0]->value, "eq", "73.7", "value okay"); 211cmp_ok( $p[0]->value, "eq", "73.7", "value okay");
212cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); 212cmp_ok( $p[0]->uom, "eq", "%", "uom okay");
@@ -216,7 +216,7 @@ cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay");
216cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); 216cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay");
217 217
218# Check ranges are parsed correctly 218# Check ranges are parsed correctly
219@p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); 219@p = Monitoring::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;");
220is( $p[0]->label, "availability", "label okay"); 220is( $p[0]->label, "availability", "label okay");
221is( $p[0]->value, "93.8", "value okay"); 221is( $p[0]->value, "93.8", "value okay");
222is( $p[0]->uom, "%", "uom okay"); 222is( $p[0]->uom, "%", "uom okay");
@@ -225,7 +225,7 @@ is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set");
225is( $p[0]->threshold->warning, "90:99", "warn okay"); 225is( $p[0]->threshold->warning, "90:99", "warn okay");
226 226
227# Check that negative values are parsed correctly in value and ranges 227# Check that negative values are parsed correctly in value and ranges
228@p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); 228@p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;");
229is( $p[0]->label, "offset", "label okay"); 229is( $p[0]->label, "offset", "label okay");
230is( $p[0]->value, "-0.004476", "value okay"); 230is( $p[0]->value, "-0.004476", "value okay");
231is( $p[0]->uom, "s", "uom okay"); 231is( $p[0]->uom, "s", "uom okay");
@@ -235,7 +235,7 @@ is( $p[0]->threshold->warning, "-60:-5", "warn okay");
235is( $p[0]->threshold->critical, "-120:-3", "crit okay"); 235is( $p[0]->threshold->critical, "-120:-3", "crit okay");
236 236
237# Check infinity values are okay 237# Check infinity values are okay
238@p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:"); 238@p = Monitoring::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:");
239is( $p[0]->label, "salary", "label okay"); 239is( $p[0]->label, "salary", "label okay");
240is( $p[0]->value, "52", "value okay"); 240is( $p[0]->value, "52", "value okay");
241is( $p[0]->uom, "GBP", "uom okay"); 241is( $p[0]->uom, "GBP", "uom okay");
@@ -245,7 +245,7 @@ is( $p[0]->threshold->warning, "~:23.5", "warn okay");
245is( $p[0]->threshold->critical, "45.2:", "warn okay"); 245is( $p[0]->threshold->critical, "45.2:", "warn okay");
246 246
247# Check scientific notation 247# Check scientific notation
248@p = Nagios::Plugin::Performance->parse_perfstring("offset=1.120567322e-05"); 248@p = Monitoring::Plugin::Performance->parse_perfstring("offset=1.120567322e-05");
249is( $p[0]->label, "offset", "label okay for scientific notation"); 249is( $p[0]->label, "offset", "label okay for scientific notation");
250is( $p[0]->value, 1.120567322e-05, "value okay"); 250is( $p[0]->value, 1.120567322e-05, "value okay");
251is( $p[0]->uom, "", "uom okay"); 251is( $p[0]->uom, "", "uom okay");
@@ -254,7 +254,7 @@ ok( ! $p[0]->threshold->critical->is_set, "Critical range has not been set");
254 254
255 255
256# Check scientific notation with warnings and criticals 256# Check scientific notation with warnings and criticals
257@p = Nagios::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25"); 257@p = Monitoring::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25");
258is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals"); 258is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals");
259is( $p[0]->value, -1.120567322e-05, "value okay"); 259is( $p[0]->value, -1.120567322e-05, "value okay");
260is( $p[0]->uom, "unit", "uom okay"); 260is( $p[0]->uom, "unit", "uom okay");
@@ -266,7 +266,7 @@ is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay");
266 266
267 267
268# Check different collation with commas instead of periods 268# Check different collation with commas instead of periods
269@p = Nagios::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); 269@p = Monitoring::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;");
270is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); 270is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods");
271is( $p[0]->value, 1.391, "value okay"); 271is( $p[0]->value, 1.391, "value okay");
272is( $p[0]->uom, "ms", "uom okay"); 272is( $p[0]->uom, "ms", "uom okay");
@@ -284,7 +284,7 @@ is( $p[1]->threshold->critical, "60", "warn okay");
284 284
285 285
286# Another set of comma separated stuff 286# Another set of comma separated stuff
287@p = Nagios::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;"); 287@p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;");
288is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods"); 288is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods");
289is( $p[0]->value, -0.023545, "value okay"); 289is( $p[0]->value, -0.023545, "value okay");
290is( $p[0]->uom, "s", "uom okay"); 290is( $p[0]->uom, "s", "uom okay");
@@ -294,14 +294,14 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
294is( $p[0]->threshold->critical, 120, "warn okay"); 294is( $p[0]->threshold->critical, 120, "warn okay");
295 295
296# Some values with funny commas 296# Some values with funny commas
297@p = Nagios::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6"); 297@p = Monitoring::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6");
298is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6"); 298is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6");
299is( $p[0]->value, 45.6, "value okay"); 299is( $p[0]->value, 45.6, "value okay");
300is( $p[0]->uom, "", "uom okay"); 300is( $p[0]->uom, "", "uom okay");
301 301
302 302
303# Test labels with spaces (returned by nsclient++) 303# Test labels with spaces (returned by nsclient++)
304@p = Nagios::Plugin::Performance->parse_perfstring("'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 'D:\ Label: Serial Number XA22aa2e'=8015MB;16388;18436;1;2048"); 304@p = Monitoring::Plugin::Performance->parse_perfstring("'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 'D:\ Label: Serial Number XA22aa2e'=8015MB;16388;18436;1;2048");
305is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e"); 305is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e");
306is( $p[0]->rrdlabel, "C__Label___Serial_N"); 306is( $p[0]->rrdlabel, "C__Label___Serial_N");
307is( $p[0]->value, 8015, "value okay"); 307is( $p[0]->value, 8015, "value okay");
@@ -322,7 +322,7 @@ is( $p[1]->max, 2048, "max ok");
322 322
323 323
324# Mix labels with and without quotes 324# Mix labels with and without quotes
325@p = Nagios::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 "); 325@p = Monitoring::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 ");
326is( $p[0]->label, "short" ); 326is( $p[0]->label, "short" );
327is( $p[0]->rrdlabel, "short"); 327is( $p[0]->rrdlabel, "short");
328is( $p[0]->value, 4, "value okay"); 328is( $p[0]->value, 4, "value okay");
@@ -351,7 +351,7 @@ is( $p[2]->min, undef, "min ok");
351is( $p[2]->max, undef, "max ok"); 351is( $p[2]->max, undef, "max ok");
352 352
353 353
354@p = Nagios::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9="); 354@p = Monitoring::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9=");
355is_deeply( \@p, [], "Fails parsing correctly"); 355is_deeply( \@p, [], "Fails parsing correctly");
356 356
357# add_perfdata tests in t/Nagios-Plugin-01.t 357# add_perfdata tests in t/Monitoring-Plugin-01.t
diff --git a/t/Nagios-Plugin-Range.t b/t/Monitoring-Plugin-Range.t
index 6fe080c..9a6e826 100644
--- a/t/Nagios-Plugin-Range.t
+++ b/t/Monitoring-Plugin-Range.t
@@ -1,15 +1,15 @@
1 1
2use strict; 2use strict;
3#use Test::More qw(no_plan); 3#use Test::More qw(no_plan);
4use Test::More tests => 151; 4use Test::More tests => 151;
5 5
6BEGIN { 6BEGIN {
7 use_ok('Nagios::Plugin::Range'); 7 use_ok('Monitoring::Plugin::Range');
8 # Silence warnings unless TEST_VERBOSE is set 8 # Silence warnings unless TEST_VERBOSE is set
9 $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; 9 $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} };
10}; 10};
11 11
12diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE}; 12diag "\nusing Monitoring::Plugin::Range revision ". $Monitoring::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE};
13 13
14my $r; 14my $r;
15 15
@@ -25,14 +25,14 @@ foreach (qw(
25 25
26), '1,10' # avoid warning about using , inside qw() 26), '1,10' # avoid warning about using , inside qw()
27) { 27) {
28 $r =Nagios::Plugin::Range->parse_range_string($_); 28 $r =Monitoring::Plugin::Range->parse_range_string($_);
29 is $r, undef, "'$_' should not be a valid range" ; 29 is $r, undef, "'$_' should not be a valid range" ;
30} 30}
31 31
32 32
33diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE}; 33diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE};
34$r = Nagios::Plugin::Range->parse_range_string("6"); 34$r = Monitoring::Plugin::Range->parse_range_string("6");
35isa_ok( $r, "Nagios::Plugin::Range"); 35isa_ok( $r, "Monitoring::Plugin::Range");
36ok( defined $r, "'6' is valid range"); 36ok( defined $r, "'6' is valid range");
37cmp_ok( $r->start, '==', 0, "Start correct"); 37cmp_ok( $r->start, '==', 0, "Start correct");
38cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 38cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -53,7 +53,7 @@ sub test_expected {
53 my $r = shift; 53 my $r = shift;
54 my $expected = shift; 54 my $expected = shift;
55 foreach (sort {$a<=>$b} keys %$expected) { 55 foreach (sort {$a<=>$b} keys %$expected) {
56 is $r->check_range($_), $expected->{$_}, 56 is $r->check_range($_), $expected->{$_},
57 " $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")"; 57 " $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")";
58 } 58 }
59} 59}
@@ -61,7 +61,7 @@ sub test_expected {
61test_expected( $r, $expected ); 61test_expected( $r, $expected );
62 62
63diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE}; 63diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE};
64$r = Nagios::Plugin::Range->parse_range_string("-7:23"); 64$r = Monitoring::Plugin::Range->parse_range_string("-7:23");
65ok( defined $r, "'-7:23' is valid range"); 65ok( defined $r, "'-7:23' is valid range");
66cmp_ok( $r->start, '==', -7, "Start correct"); 66cmp_ok( $r->start, '==', -7, "Start correct");
67cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 67cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -72,7 +72,7 @@ cmp_ok( $r, 'eq', "-7:23", "Stringification back to original");
72$expected = { 72$expected = {
73 -23 => 1, 73 -23 => 1,
74 -7 => 0, 74 -7 => 0,
75 -1 => 0, 75 -1 => 0,
76 0 => 0, 76 0 => 0,
77 4 => 0, 77 4 => 0,
78 23 => 0, 78 23 => 0,
@@ -83,7 +83,7 @@ test_expected( $r, $expected );
83 83
84 84
85diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE}; 85diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE};
86$r = Nagios::Plugin::Range->parse_range_string(":5.75"); 86$r = Monitoring::Plugin::Range->parse_range_string(":5.75");
87ok( defined $r, "':5.75' is valid range"); 87ok( defined $r, "':5.75' is valid range");
88cmp_ok( $r->start, '==', 0, "Start correct"); 88cmp_ok( $r->start, '==', 0, "Start correct");
89cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 89cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -105,7 +105,7 @@ test_expected( $r, $expected );
105 105
106 106
107diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE}; 107diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE};
108$r = Nagios::Plugin::Range->parse_range_string("~:-95.99"); 108$r = Monitoring::Plugin::Range->parse_range_string("~:-95.99");
109ok( defined $r, "'~:-95.99' is valid range"); 109ok( defined $r, "'~:-95.99' is valid range");
110cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); 110cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
111cmp_ok( $r->end, '==', -95.99, "End correct"); 111cmp_ok( $r->end, '==', -95.99, "End correct");
@@ -126,7 +126,7 @@ test_expected( $r, $expected );
126 126
127diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE}; 127diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE};
128test_expected( $r, $expected ); 128test_expected( $r, $expected );
129$r = Nagios::Plugin::Range->parse_range_string("10:"); 129$r = Monitoring::Plugin::Range->parse_range_string("10:");
130ok( defined $r, "'10:' is valid range"); 130ok( defined $r, "'10:' is valid range");
131cmp_ok( $r->start, '==', 10, "Start correct"); 131cmp_ok( $r->start, '==', 10, "Start correct");
132cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 132cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -147,7 +147,7 @@ test_expected( $r, $expected );
147 147
148diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE}; 148diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE};
149test_expected( $r, $expected ); 149test_expected( $r, $expected );
150$r = Nagios::Plugin::Range->parse_range_string("123456789012345:"); 150$r = Monitoring::Plugin::Range->parse_range_string("123456789012345:");
151ok( defined $r, "'123456789012345:' is valid range"); 151ok( defined $r, "'123456789012345:' is valid range");
152cmp_ok( $r->start, '==', 123456789012345, "Start correct"); 152cmp_ok( $r->start, '==', 123456789012345, "Start correct");
153cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 153cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -159,7 +159,7 @@ $expected = {
159 0 => 1, 159 0 => 1,
160 # The fractional values needs to be quoted, otherwise the hash rounds it up to ..345 160 # The fractional values needs to be quoted, otherwise the hash rounds it up to ..345
161 # and there is one less test run. 161 # and there is one less test run.
162 # I think some newer versions of perl use a higher precision value for the hash key. 162 # I think some newer versions of perl use a higher precision value for the hash key.
163 # This doesn't appear to affect the actual plugin though 163 # This doesn't appear to affect the actual plugin though
164 "123456789012344.91" => 1, 164 "123456789012344.91" => 1,
165 123456789012345 => 0, 165 123456789012345 => 0,
@@ -170,7 +170,7 @@ test_expected( $r, $expected );
170 170
171 171
172diag "range: <= zero " if $ENV{TEST_VERBOSE}; 172diag "range: <= zero " if $ENV{TEST_VERBOSE};
173$r = Nagios::Plugin::Range->parse_range_string("~:0"); 173$r = Monitoring::Plugin::Range->parse_range_string("~:0");
174ok( defined $r, "'~:0' is valid range"); 174ok( defined $r, "'~:0' is valid range");
175cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); 175cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
176cmp_ok( $r->end, '==', 0, "End correct"); 176cmp_ok( $r->end, '==', 0, "End correct");
@@ -191,7 +191,7 @@ test_expected( $r, $expected );
191 191
192 192
193diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE}; 193diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE};
194$r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567'); 194$r = Monitoring::Plugin::Range->parse_range_string('@0:657.8210567');
195ok( defined $r, '"@0:657.8210567" is a valid range'); 195ok( defined $r, '"@0:657.8210567" is a valid range');
196cmp_ok( $r->start, '==', 0, "Start correct"); 196cmp_ok( $r->start, '==', 0, "Start correct");
197cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 197cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -216,7 +216,7 @@ test_expected( $r, $expected );
216 216
217 217
218diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE}; 218diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE};
219$r = Nagios::Plugin::Range->parse_range_string('1:1'); 219$r = Monitoring::Plugin::Range->parse_range_string('1:1');
220ok( defined $r, '"1:1" is a valid range'); 220ok( defined $r, '"1:1" is a valid range');
221cmp_ok( $r->start, '==', 1, "Start correct"); 221cmp_ok( $r->start, '==', 1, "Start correct");
222cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); 222cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -237,7 +237,7 @@ $expected = {
237test_expected( $r, $expected ); 237test_expected( $r, $expected );
238 238
239 239
240$r = Nagios::Plugin::Range->parse_range_string('2:1'); 240$r = Monitoring::Plugin::Range->parse_range_string('2:1');
241ok( ! defined $r, '"2:1" is rejected'); 241ok( ! defined $r, '"2:1" is rejected');
242 242
243# TODO: Need more tests for invalid data 243# TODO: Need more tests for invalid data
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Monitoring-Plugin-Threshold.t
index 78d2189..8849464 100644
--- a/t/Nagios-Plugin-Threshold.t
+++ b/t/Monitoring-Plugin-Threshold.t
@@ -1,32 +1,32 @@
1 1
2use strict; 2use strict;
3use Test::More tests => 93; 3use Test::More tests => 93;
4BEGIN { 4BEGIN {
5 use_ok('Nagios::Plugin::Threshold'); 5 use_ok('Monitoring::Plugin::Threshold');
6 use_ok('Nagios::Plugin::Functions', ':all' ); 6 use_ok('Monitoring::Plugin::Functions', ':all' );
7 # Silence warnings unless TEST_VERBOSE is set 7 # Silence warnings unless TEST_VERBOSE is set
8 $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; 8 $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} };
9} 9}
10 10
11diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n" 11diag "\nusing Monitoring::Plugin::Threshold revision ". $Monitoring::Plugin::Threshold::VERSION . "\n"
12 if $ENV{TEST_VERBOSE}; 12 if $ENV{TEST_VERBOSE};
13 13
14Nagios::Plugin::Functions::_fake_exit(1); 14Monitoring::Plugin::Functions::_fake_exit(1);
15 15
16my $t; 16my $t;
17 17
18$t = Nagios::Plugin::Threshold->set_thresholds(warning => undef, critical => undef); 18$t = Monitoring::Plugin::Threshold->set_thresholds(warning => undef, critical => undef);
19ok( defined $t, "two undefs" ); 19ok( defined $t, "two undefs" );
20ok( ! $t->warning->is_set, "warning not set" ); 20ok( ! $t->warning->is_set, "warning not set" );
21ok( ! $t->critical->is_set, "critical not set" ); 21ok( ! $t->critical->is_set, "critical not set" );
22 22
23$t = Nagios::Plugin::Threshold->set_thresholds(warning => "", critical => ""); 23$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "", critical => "");
24ok( defined $t, "two empty strings" ); 24ok( defined $t, "two empty strings" );
25ok( ! $t->warning->is_set, "warning not set" ); 25ok( ! $t->warning->is_set, "warning not set" );
26ok( ! $t->critical->is_set, "critical not set" ); 26ok( ! $t->critical->is_set, "critical not set" );
27 27
28diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; 28diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE};
29my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); 29my $t = Monitoring::Plugin::Threshold->set_thresholds(critical => "80");
30ok( defined $t, "Threshold ('', '80') set"); 30ok( defined $t, "Threshold ('', '80') set");
31ok( ! $t->warning->is_set, "Warning not set"); 31ok( ! $t->warning->is_set, "Warning not set");
32cmp_ok( $t->critical->start, '==', 0, "Critical strat set correctly"); 32cmp_ok( $t->critical->start, '==', 0, "Critical strat set correctly");
@@ -59,11 +59,11 @@ sub test_expected_statuses {
59} 59}
60test_expected_statuses( $t, $expected ); 60test_expected_statuses( $t, $expected );
61 61
62# GMC: this test seems bogus to me - either we've died, in which case internal 62# GMC: this test seems bogus to me - either we've died, in which case internal
63# state is undefined (and untestable!), or we should be returning a non-fatal error 63# state is undefined (and untestable!), or we should be returning a non-fatal error
64if (0) { 64if (0) {
65 diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; 65 diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
66 eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; 66 eval { $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") };
67 ok( defined $t, "Threshold ('5:33', '') set"); 67 ok( defined $t, "Threshold ('5:33', '') set");
68 cmp_ok( $t->warning->start, '==', 5, "Warning start set"); 68 cmp_ok( $t->warning->start, '==', 5, "Warning start set");
69 cmp_ok( $t->warning->end, '==', 33, "Warning end set"); 69 cmp_ok( $t->warning->end, '==', 33, "Warning end set");
@@ -72,7 +72,7 @@ if (0) {
72 72
73# GC: same as previous test, except critical is undef instead of '' 73# GC: same as previous test, except critical is undef instead of ''
74diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; 74diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
75$t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef); 75$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef);
76ok( defined $t, "Threshold ('5:33', '') set"); 76ok( defined $t, "Threshold ('5:33', '') set");
77cmp_ok( $t->warning->start, '==', 5, "Warning start set"); 77cmp_ok( $t->warning->start, '==', 5, "Warning start set");
78cmp_ok( $t->warning->end, '==', 33, "Warning end set"); 78cmp_ok( $t->warning->end, '==', 33, "Warning end set");
@@ -91,7 +91,7 @@ $expected = { qw(
91test_expected_statuses( $t, $expected ); 91test_expected_statuses( $t, $expected );
92 92
93diag "threshold: warn if more than 30; critical if > 60" if $ENV{TEST_VERBOSE}; 93diag "threshold: warn if more than 30; critical if > 60" if $ENV{TEST_VERBOSE};
94$t = Nagios::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60"); 94$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60");
95ok( defined $t, "Threshold ('~:30', '~:60') set"); 95ok( defined $t, "Threshold ('~:30', '~:60') set");
96cmp_ok( $t->warning->end, '==', 30, "Warning end set"); 96cmp_ok( $t->warning->end, '==', 30, "Warning end set");
97cmp_ok( $t->critical->end, '==',60, "Critical end set"); 97cmp_ok( $t->critical->end, '==',60, "Critical end set");
@@ -118,23 +118,23 @@ test_expected_statuses( $t, $expected );
118goto SKIP_DEATH; 118goto SKIP_DEATH;
119diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; 119diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE};
120diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; 120diag "you should see one invalid range definition warning and an UNKNOWN line here:\n";
121Nagios::Plugin::Functions->print_on_die(1); 121Monitoring::Plugin::Functions->print_on_die(1);
122Nagios::Plugin::Functions->exit_on_die(1); 122Monitoring::Plugin::Functions->exit_on_die(1);
123 123
124dies_ok( sub { 124dies_ok( sub {
125 $t = Nagios::Plugin::Threshold->set_thresholds( 125 $t = Monitoring::Plugin::Threshold->set_thresholds(
126 warning => "total", 126 warning => "total",
127 critical => "rubbish" 127 critical => "rubbish"
128 ) 128 )
129 }, "bad thresholds cause death" 129 }, "bad thresholds cause death"
130); 130);
131Nagios::Plugin::Functions->print_on_die(0); 131Monitoring::Plugin::Functions->print_on_die(0);
132Nagios::Plugin::Functions->exit_on_die(0); 132Monitoring::Plugin::Functions->exit_on_die(0);
133SKIP_DEATH: 133SKIP_DEATH:
134 134
135 135
136diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE}; 136diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE};
137$t = Nagios::Plugin::Threshold->set_thresholds( critical => "~:25" ); 137$t = Monitoring::Plugin::Threshold->set_thresholds( critical => "~:25" );
138ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" ); 138ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" );
139ok( ! $t->warning->is_set, "Warning not set"); 139ok( ! $t->warning->is_set, "Warning not set");
140cmp_ok( $t->critical->end, '==',25, "Critical end set"); 140cmp_ok( $t->critical->end, '==',25, "Critical end set");
@@ -145,14 +145,14 @@ $expected = { qw(
145 4 OK 145 4 OK
146 10 OK 146 10 OK
147 14.21 OK 147 14.21 OK
148 25 OK 148 25 OK
149 25.01 CRITICAL 149 25.01 CRITICAL
150 31001 CRITICAL 150 31001 CRITICAL
151) }; 151) };
152test_expected_statuses( $t, $expected); 152test_expected_statuses( $t, $expected);
153 153
154diag "threshold: warn if OUTSIDE {10..25} , critical if > 25 " if $ENV{TEST_VERBOSE}; 154diag "threshold: warn if OUTSIDE {10..25} , critical if > 25 " if $ENV{TEST_VERBOSE};
155$t = Nagios::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25"); 155$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25");
156ok( defined $t, "Threshold ('10:25', '~:25') set"); 156ok( defined $t, "Threshold ('10:25', '~:25') set");
157cmp_ok( $t->warning->start, '==', 10, "Warning start set"); 157cmp_ok( $t->warning->start, '==', 10, "Warning start set");
158cmp_ok( $t->warning->end, '==', 25, "Warning end set"); 158cmp_ok( $t->warning->end, '==', 25, "Warning end set");
@@ -164,7 +164,7 @@ $expected = { qw(
164 9.999999 WARNING 164 9.999999 WARNING
165 10 OK 165 10 OK
166 14.21 OK 166 14.21 OK
167 25 OK 167 25 OK
168 25.01 CRITICAL 168 25.01 CRITICAL
169 31001 CRITICAL 169 31001 CRITICAL
170) }; 170) };
@@ -172,7 +172,7 @@ test_expected_statuses( $t, $expected );
172 172
173 173
174diag "warn if INSIDE {10..25} , critical if < 10 " if $ENV{TEST_VERBOSE}; 174diag "warn if INSIDE {10..25} , critical if < 10 " if $ENV{TEST_VERBOSE};
175$t = Nagios::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:"); 175$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:");
176$expected = { qw( 176$expected = { qw(
177 -1 CRITICAL 177 -1 CRITICAL
178 4 CRITICAL 178 4 CRITICAL
@@ -187,7 +187,7 @@ test_expected_statuses( $t, $expected );
187 187
188 188
189# GMC: as of 0.16, set_thresholds can also be called as a mutator 189# GMC: as of 0.16, set_thresholds can also be called as a mutator
190diag "threshold mutator: warn if more than 30; critical if > 60" 190diag "threshold mutator: warn if more than 30; critical if > 60"
191 if $ENV{TEST_VERBOSE}; 191 if $ENV{TEST_VERBOSE};
192my $t1 = $t; 192my $t1 = $t;
193$t->set_thresholds(warning => "0:45", critical => "0:90"); 193$t->set_thresholds(warning => "0:45", critical => "0:90");
@@ -200,16 +200,16 @@ is( $t->critical->end, 90, "Critical end ok");
200 200
201 201
202# Also as of 0.16, accepts N::P::Range objects as arguments 202# Also as of 0.16, accepts N::P::Range objects as arguments
203my $warning = Nagios::Plugin::Range->parse_range_string("50"); 203my $warning = Monitoring::Plugin::Range->parse_range_string("50");
204my $critical = Nagios::Plugin::Range->parse_range_string("70:90"); 204my $critical = Monitoring::Plugin::Range->parse_range_string("70:90");
205$t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical); 205$t = Monitoring::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
206ok( defined $t, "Threshold from ranges ('50', '70:90') set"); 206ok( defined $t, "Threshold from ranges ('50', '70:90') set");
207is( $t->warning->start, 0, "Warning start ok"); 207is( $t->warning->start, 0, "Warning start ok");
208is( $t->warning->end, 50, "Warning end ok"); 208is( $t->warning->end, 50, "Warning end ok");
209is( $t->critical->start, 70, "Critical start ok"); 209is( $t->critical->start, 70, "Critical start ok");
210is( $t->critical->end, 90, "Critical end ok"); 210is( $t->critical->end, 90, "Critical end ok");
211 211
212$critical = Nagios::Plugin::Range->parse_range_string("90:"); 212$critical = Monitoring::Plugin::Range->parse_range_string("90:");
213$t->set_thresholds(warning => "~:20", critical => $critical); 213$t->set_thresholds(warning => "~:20", critical => $critical);
214ok( defined $t, "Threshold from string + range ('~:20', '90:') set"); 214ok( defined $t, "Threshold from string + range ('~:20', '90:') set");
215ok( $t->warning->start_infinity, "Warning start ok (infinity)"); 215ok( $t->warning->start_infinity, "Warning start ok (infinity)");
diff --git a/t/Nagios-Plugin-02.t b/t/Nagios-Plugin-02.t
deleted file mode 100644
index f64fb6f..0000000
--- a/t/Nagios-Plugin-02.t
+++ /dev/null
@@ -1,161 +0,0 @@
1# Nagios::Plugin test set 2, testing NP::Functions wrapping
2
3use strict;
4use Test::More tests => 103;
5
6BEGIN { use_ok("Nagios::Plugin") }
7require Nagios::Plugin::Functions;
8Nagios::Plugin::Functions::_fake_exit(1);
9
10# Hardcoded checks of constants
11my %ERRORS = %Nagios::Plugin::Functions::ERRORS;
12is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
13is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
14is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
15is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
16is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
17
18my $plugin = 'TEST_PLUGIN';
19my $np = Nagios::Plugin->new( shortname => $plugin );
20is($np->shortname, $plugin, "shortname() is $plugin");
21
22# Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg )
23my $r;
24my @ok = (
25 [ OK, "OK", 'test the first', ],
26 [ WARNING, "WARNING", 'test the second', ],
27 [ CRITICAL, "CRITICAL", 'test the third', ],
28 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
29 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
30);
31for (@ok) {
32 # CONSTANT
33 $r = $np->nagios_exit($_->[0], $_->[2]);
34 is($r->return_code, $_->[0],
35 sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
36 like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
37 sprintf('nagios_exit(%s, $msg) output matched "%s"', $_->[1],
38 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
39
40 # $string
41 $r = $np->nagios_exit($_->[1], $_->[2]);
42 is($r->return_code, $_->[0],
43 sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
44 like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
45 sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1],
46 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
47 like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
48 sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1],
49 $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
50}
51
52# nagios_exit code corner cases
53my @ugly1 = (
54 [ -1, 'testing code -1' ],
55 [ 7, 'testing code 7' ],
56 [ undef, 'testing code undef' ],
57 [ '', qq(testing code '') ],
58 [ 'string', qq(testing code 'string') ],
59);
60for (@ugly1) {
61 $r = $np->nagios_exit($_->[0], $_->[1]);
62 my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
63 is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN);
64 like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
65 sprintf('nagios_exit(%s, $msg) output matched "%s"',
66 $display, 'UNKNOWN.*' . $_->[1]));
67}
68
69# nagios_exit message corner cases
70my @ugly2 = (
71 [ '' ],
72 [ undef ],
73 [ UNKNOWN ],
74);
75for (@ugly2) {
76 $r = $np->nagios_exit(CRITICAL, $_->[0]);
77 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
78 my $display2 = defined $_->[0] ? $_->[0] : '';
79 like($r->message, qr/CRITICAL\b.*\b$display2$/,
80 sprintf('nagios_exit(%s, $msg) output matched "%s"',
81 $display1, "CRITICAL.*$display2"));
82}
83
84# Test nagios_die( $msg )
85my @msg = (
86 [ 'die you dog' ],
87 [ '' ],
88 [ undef ],
89);
90for (@msg) {
91 $r = $np->nagios_die($_->[0]);
92 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
93 my $display2 = defined $_->[0] ? $_->[0] : '';
94 is($r->return_code, UNKNOWN,
95 sprintf('nagios_die(%s) returned UNKNOWN', $display1));
96 like($r->message, qr/UNKNOWN\b.*\b$display2$/,
97 sprintf('nagios_die(%s) output matched "%s"', $display1,
98 "UNKNOWN.*$display2"));
99}
100
101# Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ),
102# nagios_die( $string, $msg ), and nagios_die( $msg, $string )
103@ok = (
104 [ OK, "OK", 'test the first', ],
105 [ WARNING, "WARNING", 'test the second', ],
106 [ CRITICAL, "CRITICAL", 'test the third', ],
107 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
108 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
109);
110for (@ok) {
111 # CONSTANT, $msg
112 $r = $np->nagios_die($_->[0], $_->[2]);
113 is($r->return_code, $_->[0],
114 sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0]));
115 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
116 sprintf('nagios_die(%s, $msg) output matched "%s"',
117 $_->[1], $_->[1] . '.*' . $_->[2]));
118
119 # $msg, CONSTANT
120 $r = $np->nagios_die($_->[2], $_->[0]);
121 is($r->return_code, $_->[0],
122 sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0]));
123 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
124 sprintf('nagios_die($msg, %s) output matched "%s"',
125 $_->[1], $_->[1] . '.*' . $_->[2]));
126
127 # $string, $msg
128 $r = $np->nagios_die($_->[1], $_->[2]);
129 is($r->return_code, $_->[0],
130 sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0]));
131 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
132 sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1],
133 $_->[1] . '.*' . $_->[2]));
134 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
135 sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1],
136 $_->[1] . '.*' . $_->[2]));
137
138 # $string, $msg
139 $r = $np->nagios_die($_->[2], $_->[1]);
140 is($r->return_code, $_->[0],
141 sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0]));
142 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
143 sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1],
144 $_->[1] . '.*' . $_->[2]));
145 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
146 sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1],
147 $_->[1] . '.*' . $_->[2]));
148}
149
150
151# shortname testing
152SKIP: {
153 skip "requires File::Basename", 2 unless eval { require File::Basename };
154 $np = Nagios::Plugin->new( version => "1");
155 $plugin = uc File::Basename::basename($0);
156 $plugin =~ s/\..*$//;
157 is($np->shortname, $plugin, "shortname() is '$plugin'");
158 $r = $np->nagios_exit(OK, "foobar");
159 like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'");
160}
161
diff --git a/t/Nagios-Plugin-Functions-01.t b/t/Nagios-Plugin-Functions-01.t
deleted file mode 100644
index 5268255..0000000
--- a/t/Nagios-Plugin-Functions-01.t
+++ /dev/null
@@ -1,161 +0,0 @@
1
2use strict;
3use Test::More tests => 113;
4
5BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); }
6Nagios::Plugin::Functions::_fake_exit(1);
7
8my $this_version=$Nagios::Plugin::Functions::VERSION;
9foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) {
10 my $mod = "Nagios::Plugin$m";
11 use_ok($mod);
12 # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing
13 my $v = "$mod"."::VERSION";
14 my $a = eval "\$$v";
15 is($a, $this_version, "Version number for $mod the same as Functions: $this_version");
16}
17
18# check get_shortname
19is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok");
20
21# Hardcoded checks of constants
22ok(defined %ERRORS, '%ERRORS defined');
23is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
24is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
25is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
26is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
27is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
28
29# Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg )
30my $r;
31my @ok = (
32 [ OK, "OK", 'test the first', ],
33 [ WARNING, "WARNING", 'test the second', ],
34 [ CRITICAL, "CRITICAL", 'test the third', ],
35 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
36 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
37);
38for (@ok) {
39 # CONSTANT
40 $r = nagios_exit($_->[0], $_->[2]);
41 is($r->return_code, $_->[0],
42 sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
43 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
44 sprintf('nagios_exit(%s, $msg) output matched "%s"',
45 $_->[1], $_->[1] . '.*' . $_->[2]));
46
47 # $string
48 $r = nagios_exit($_->[1], $_->[2]);
49 is($r->return_code, $_->[0],
50 sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
51 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
52 sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1],
53 $_->[1] . '.*' . $_->[2]));
54 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
55 sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1],
56 $_->[1] . '.*' . $_->[2]));
57}
58
59# nagios_exit code corner cases
60my @ugly1 = (
61 [ -1, 'testing code -1' ],
62 [ 7, 'testing code 7' ],
63 [ undef, 'testing code undef' ],
64 [ '', qq(testing code '') ],
65 [ 'string', qq(testing code 'string') ],
66);
67for (@ugly1) {
68 $r = nagios_exit($_->[0], $_->[1]);
69 my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
70 is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN);
71 like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
72 sprintf('nagios_exit(%s, $msg) output matched "%s"',
73 $display, 'UNKNOWN.*' . $_->[1]));
74}
75
76# nagios_exit message corner cases
77my @ugly2 = (
78 [ '' ],
79 [ undef ],
80 [ UNKNOWN ],
81);
82for (@ugly2) {
83 $r = nagios_exit(CRITICAL, $_->[0]);
84 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
85 my $display2 = defined $_->[0] ? $_->[0] : '';
86 like($r->message, qr/CRITICAL\b.*\b$display2$/,
87 sprintf('nagios_exit(%s, $msg) output matched "%s"',
88 $display1, "CRITICAL.*$display2"));
89}
90
91# Test nagios_die( $msg )
92my @msg = (
93 [ 'die you dog' ],
94 [ '' ],
95 [ undef ],
96);
97for (@msg) {
98 $r = nagios_die($_->[0]);
99 my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
100 my $display2 = defined $_->[0] ? $_->[0] : '';
101 is($r->return_code, UNKNOWN,
102 sprintf('nagios_die(%s) returned UNKNOWN', $display1));
103 like($r->message, qr/UNKNOWN\b.*\b$display2$/,
104 sprintf('nagios_die(%s) output matched "%s"', $display1,
105 "UNKNOWN.*$display2"));
106}
107
108# Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ),
109# nagios_die( $string, $msg ), and nagios_die( $msg, $string )
110@ok = (
111 [ OK, "OK", 'test the first', ],
112 [ WARNING, "WARNING", 'test the second', ],
113 [ CRITICAL, "CRITICAL", 'test the third', ],
114 [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
115 [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
116);
117for (@ok) {
118 # CONSTANT, $msg
119 $r = nagios_die($_->[0], $_->[2]);
120 is($r->return_code, $_->[0],
121 sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0]));
122 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
123 sprintf('nagios_die(%s, $msg) output matched "%s"',
124 $_->[1], $_->[1] . '.*' . $_->[2]));
125
126 # $msg, CONSTANT
127 $r = nagios_die($_->[2], $_->[0]);
128 is($r->return_code, $_->[0],
129 sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0]));
130 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
131 sprintf('nagios_die($msg, %s) output matched "%s"',
132 $_->[1], $_->[1] . '.*' . $_->[2]));
133
134 # $string, $msg
135 $r = nagios_die($_->[1], $_->[2]);
136 is($r->return_code, $_->[0],
137 sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0]));
138 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
139 sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1],
140 $_->[1] . '.*' . $_->[2]));
141 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
142 sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1],
143 $_->[1] . '.*' . $_->[2]));
144
145 # $string, $msg
146 $r = nagios_die($_->[2], $_->[1]);
147 is($r->return_code, $_->[0],
148 sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0]));
149 like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
150 sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1],
151 $_->[1] . '.*' . $_->[2]));
152 like($r, qr/$_->[1]\b.*\b$_->[2]$/,
153 sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1],
154 $_->[1] . '.*' . $_->[2]));
155}
156
157# Check that _use_die set to 1 will catch exceptions correctly
158Nagios::Plugin::Functions::_fake_exit(0);
159Nagios::Plugin::Functions::_use_die(1);
160eval { nagios_die("Using die") };
161is( $@, "NAGIOS-PLUGIN-FUNCTIONS-01 UNKNOWN - Using die\n", "Caught exception");
diff --git a/t/Nagios-Plugin-Performance-02.t b/t/Nagios-Plugin-Performance-02.t
deleted file mode 100644
index c0c5a71..0000000
--- a/t/Nagios-Plugin-Performance-02.t
+++ /dev/null
@@ -1,13 +0,0 @@
1
2use strict;
3use Test::More tests => 3;
4use_ok("Nagios::Plugin::Performance", use_die => 1);
5
6eval { Nagios::Plugin::Functions::nagios_die("Testing") };
7is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
8
9
10use_ok("Nagios::Plugin::Performance");
11eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) };
12
13fail("Should not get here if code works correctly because prior nagios_die should have exited");
diff --git a/t/check_stuff.pl b/t/check_stuff.pl
index 112a18a..4fc125c 100755
--- a/t/check_stuff.pl
+++ b/t/check_stuff.pl
@@ -2,21 +2,21 @@
2 2
3### check_stuff.pl 3### check_stuff.pl
4 4
5# an example Nagios plugin using the Nagios::Plugin modules. 5# an example Monitoring plugin using the Monitoring::Plugin modules.
6 6
7# Originally by Nathan Vonnahme, n8v at users dot sourceforge 7# Originally by Nathan Vonnahme, n8v at users dot sourceforge
8# dot net, July 19 2006 8# dot net, July 19 2006
9 9
10# Please modify to your heart's content and use as the basis for all 10# Please modify to your heart's content and use as the basis for all
11# the really cool Nagios monitoring scripts you're going to create. 11# the really cool monitoring scripts you're going to create.
12# You rock. 12# You rock.
13 13
14############################################################################## 14##############################################################################
15# prologue 15# prologue
16use strict; 16use strict;
17use warnings; 17use warnings;
18 18
19use Nagios::Plugin ; 19use Monitoring::Plugin;
20 20
21use vars qw($VERSION $PROGNAME $verbose $warn $critical $timeout $result); 21use vars qw($VERSION $PROGNAME $verbose $warn $critical $timeout $result);
22$VERSION = '1.0'; 22$VERSION = '1.0';
@@ -28,18 +28,18 @@ $PROGNAME = basename($0);
28 28
29############################################################################## 29##############################################################################
30# define and get the command line options. 30# define and get the command line options.
31# see the command line option guidelines at 31# see the command line option guidelines at
32# http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS 32# https://www.monitoring-plugins.org/doc/guidelines.html#PLUGOPTIONS
33 33
34 34
35# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory) 35# Instantiate Monitoring::Plugin object (the 'usage' parameter is mandatory)
36my $p = Nagios::Plugin->new( 36my $p = Monitoring::Plugin->new(
37 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] 37 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>]
38 [ -c|--critical=<critical threshold> ] 38 [ -c|--critical=<critical threshold> ]
39 [ -w|--warning=<warning threshold> ] 39 [ -w|--warning=<warning threshold> ]
40 [ -r|--result = <INTEGER> ]", 40 [ -r|--result = <INTEGER> ]",
41 version => $VERSION, 41 version => $VERSION,
42 blurb => 'This plugin is an example of a Nagios plugin written in Perl using the Nagios::Plugin modules. It will generate a random integer between 1 and 20 (though you can specify the number with the -n option for testing), and will output OK, WARNING or CRITICAL if the resulting number is outside the specified thresholds.', 42 blurb => 'This plugin is an example of a monitoring plugin written in Perl using the Monitoring::Plugin modules. It will generate a random integer between 1 and 20 (though you can specify the number with the -n option for testing), and will output OK, WARNING or CRITICAL if the resulting number is outside the specified thresholds.',
43 43
44 extra => " 44 extra => "
45 45
@@ -47,11 +47,7 @@ THRESHOLDs for -w and -c are specified 'min:max' or 'min:' or ':max'
47(or 'max'). If specified '\@min:max', a warning status will be generated 47(or 'max'). If specified '\@min:max', a warning status will be generated
48if the count *is* inside the specified range. 48if the count *is* inside the specified range.
49 49
50See more threshold examples at http 50See more threshold examples at https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
51 : // nagiosplug
52 . sourceforge
53 . net / developer-guidelines
54 . html #THRESHOLDFORMAT
55 51
56 Examples: 52 Examples:
57 53
@@ -75,7 +71,7 @@ See more threshold examples at http
75$p->add_arg( 71$p->add_arg(
76 spec => 'warning|w=s', 72 spec => 'warning|w=s',
77 73
78 help => 74 help =>
79qq{-w, --warning=INTEGER:INTEGER 75qq{-w, --warning=INTEGER:INTEGER
80 Minimum and maximum number of allowable result, outside of which a 76 Minimum and maximum number of allowable result, outside of which a
81 warning will be generated. If omitted, no warning is generated.}, 77 warning will be generated. If omitted, no warning is generated.},
@@ -86,7 +82,7 @@ qq{-w, --warning=INTEGER:INTEGER
86 82
87$p->add_arg( 83$p->add_arg(
88 spec => 'critical|c=s', 84 spec => 'critical|c=s',
89 help => 85 help =>
90qq{-c, --critical=INTEGER:INTEGER 86qq{-c, --critical=INTEGER:INTEGER
91 Minimum and maximum number of the generated result, outside of 87 Minimum and maximum number of the generated result, outside of
92 which a critical will be generated. }, 88 which a critical will be generated. },
@@ -94,7 +90,7 @@ qq{-c, --critical=INTEGER:INTEGER
94 90
95$p->add_arg( 91$p->add_arg(
96 spec => 'result|r=f', 92 spec => 'result|r=f',
97 help => 93 help =>
98qq{-r, --result=INTEGER 94qq{-r, --result=INTEGER
99 Specify the result on the command line rather than generating a 95 Specify the result on the command line rather than generating a
100 random number. For testing.}, 96 random number. For testing.},
@@ -106,11 +102,11 @@ $p->getopts;
106 102
107# perform sanity checking on command line options 103# perform sanity checking on command line options
108if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { 104if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) {
109 $p->nagios_die( " invalid number supplied for the -r option " ); 105 $p->plugin_die( " invalid number supplied for the -r option " );
110} 106}
111 107
112unless ( defined $p->opts->warning || defined $p->opts->critical ) { 108unless ( defined $p->opts->warning || defined $p->opts->critical ) {
113 $p->nagios_die( " you didn't supply a threshold argument " ); 109 $p->plugin_die( " you didn't supply a threshold argument " );
114} 110}
115 111
116 112
@@ -135,8 +131,7 @@ else {
135############################################################################## 131##############################################################################
136# check the result against the defined warning and critical thresholds, 132# check the result against the defined warning and critical thresholds,
137# output the result and exit 133# output the result and exit
138$p->nagios_exit( 134$p->plugin_exit(
139 return_code => $p->check_threshold($result), 135 return_code => $p->check_threshold($result),
140 message => " sample result was $result" 136 message => " sample result was $result"
141); 137);
142
diff --git a/t/check_stuff.t b/t/check_stuff.t
index 2815b76..6a1d845 100755
--- a/t/check_stuff.t
+++ b/t/check_stuff.t
@@ -1,5 +1,5 @@
1#!/usr/local/bin/perl 1#!/usr/local/bin/perl
2# 2#
3use strict; use warnings; 3use strict; use warnings;
4#use Test::More qw(no_plan); 4#use Test::More qw(no_plan);
5use Test::More tests => 14; 5use Test::More tests => 14;
@@ -10,7 +10,7 @@ $s = "$^X -Ilib $s";
10 10
11my $n = 'STUFF'; 11my $n = 'STUFF';
12 12
13# Nagios status strings and exit codes 13# Monitoring status strings and exit codes
14my %e = qw( 14my %e = qw(
15 OK 0 15 OK 0
16 WARNING 1 16 WARNING 1
@@ -58,9 +58,3 @@ sub test_expected {
58 like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_"; 58 like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_";
59 } 59 }
60} 60}
61
62
63
64
65
66
diff --git a/t/npg03/README b/t/npg03/README
index 3dbdaf8..541ece7 100644
--- a/t/npg03/README
+++ b/t/npg03/README
@@ -1,15 +1,15 @@
1Nagios-Plugin-Getopt-03.t automatically tests all cases defined in 1Monitoring-Plugin-Getopt-03.t automatically tests all cases defined in
2the 'input' directory and expects the output to match the 2the 'input' directory and expects the output to match the
3corresponding file in the 'expected' directory. To define a new test 3corresponding file in the 'expected' directory. To define a new test
4case, just create a new file in the 'input' directory containing the 4case, just create a new file in the 'input' directory containing the
5input command line, and a corresponding file in the 'expected' 5input command line, and a corresponding file in the 'expected'
6directory containing what you think the expanded command line should 6directory containing what you think the expanded command line should
7be. Note that this expansion is normalised as follows: 7be. Note that this expansion is normalised as follows:
8 8
9- command line arguments are reported in alphabetical order 9- command line arguments are reported in alphabetical order
10- extraneous white space is removed 10- extraneous white space is removed
11 11
12Also, if you use a completely new argument than those currently 12Also, if you use a completely new argument than those currently
13defined in Nagios-Plugin-Getopt-03.t you will need to define it 13defined in Monitoring-Plugin-Getopt-03.t you will need to define it
14there as well. 14there as well.
15 15