summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--Changes5
-rw-r--r--MANIFEST64
-rw-r--r--MANIFEST.SKIP21
-rw-r--r--Makefile.PL45
-rw-r--r--README23
-rw-r--r--lib/Monitoring/Plugin.pm (renamed from lib/Nagios/Plugin.pm)251
-rw-r--r--lib/Monitoring/Plugin/Config.pm (renamed from lib/Nagios/Plugin/Config.pm)53
-rw-r--r--lib/Monitoring/Plugin/ExitResult.pm71
-rw-r--r--lib/Monitoring/Plugin/Functions.pm (renamed from lib/Nagios/Plugin/Functions.pm)121
-rw-r--r--lib/Monitoring/Plugin/Getopt.pm (renamed from lib/Nagios/Plugin/Getopt.pm)138
-rw-r--r--lib/Monitoring/Plugin/Performance.pm (renamed from lib/Nagios/Plugin/Performance.pm)72
-rw-r--r--lib/Monitoring/Plugin/Range.pm (renamed from lib/Nagios/Plugin/Range.pm)32
-rw-r--r--lib/Monitoring/Plugin/Threshold.pm (renamed from lib/Nagios/Plugin/Threshold.pm)50
-rw-r--r--lib/Nagios/Plugin/ExitResult.pm67
-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
38 files changed, 1104 insertions, 1062 deletions
diff --git a/.gitignore b/.gitignore
index 6cf3bbc..93cc521 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,8 @@
5/pm_to_blib 5/pm_to_blib
6/.bzr 6/.bzr
7/.bzrignore 7/.bzrignore
8MYMETA.json
9MYMETA.yml
10Makefile.old
11inc/
12MANIFEST.bak
diff --git a/Changes b/Changes
index 2034b6c..b85c2ac 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,7 @@
1Revision history for Perl module Nagios::Plugin. 1Revision history for Perl module Monitoring::Plugin.
2
30.37 20nd January 2014
4 - renamed module due to trademark issues
2 5
30.36 22nd December 2011 60.36 22nd December 2011
4 - Updated check_threshold to allow multiple check values to be checked at once 7 - Updated check_threshold to allow multiple check values to be checked at once
diff --git a/MANIFEST b/MANIFEST
index 39be2c5..8ccb51c 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,33 +1,47 @@
1Changes 1Changes
2lib/Nagios/Plugin.pm 2inc/Module/AutoInstall.pm
3lib/Nagios/Plugin/Config.pm 3inc/Module/Install.pm
4lib/Nagios/Plugin/ExitResult.pm 4inc/Module/Install/AutoInstall.pm
5lib/Nagios/Plugin/Functions.pm 5inc/Module/Install/Base.pm
6lib/Nagios/Plugin/Getopt.pm 6inc/Module/Install/Can.pm
7lib/Nagios/Plugin/Performance.pm 7inc/Module/Install/Fetch.pm
8lib/Nagios/Plugin/Range.pm 8inc/Module/Install/Include.pm
9lib/Nagios/Plugin/Threshold.pm 9inc/Module/Install/Makefile.pm
10inc/Module/Install/Metadata.pm
11inc/Module/Install/Win32.pm
12inc/Module/Install/WriteAll.pm
13lib/Monitoring/Plugin.pm
14lib/Monitoring/Plugin/Config.pm
15lib/Monitoring/Plugin/ExitResult.pm
16lib/Monitoring/Plugin/Functions.pm
17lib/Monitoring/Plugin/Getopt.pm
18lib/Monitoring/Plugin/Performance.pm
19lib/Monitoring/Plugin/Range.pm
20lib/Monitoring/Plugin/Threshold.pm
10Makefile.PL 21Makefile.PL
11MANIFEST This list of files 22MANIFEST This list of files
12META.yml 23META.yml
24notes
13README 25README
14t/check_stuff.pl 26t/check_stuff.pl
15t/check_stuff.t 27t/check_stuff.t
16t/Nagios-Plugin-01.t 28t/Monitoring-Plugin-01.t
17t/Nagios-Plugin-02.t 29t/Monitoring-Plugin-02.t
18t/Nagios-Plugin-03.t 30t/Monitoring-Plugin-03.t
19t/Nagios-Plugin-04.t 31t/Monitoring-Plugin-04.t
20t/Nagios-Plugin-Functions-01.t 32t/Monitoring-Plugin-05.t
21t/Nagios-Plugin-Functions-02.t 33t/Monitoring-Plugin-Functions-01.t
22t/Nagios-Plugin-Functions-03.t 34t/Monitoring-Plugin-Functions-02.t
23t/Nagios-Plugin-Getopt-01.t 35t/Monitoring-Plugin-Functions-03.t
24t/Nagios-Plugin-Getopt-02.t 36t/Monitoring-Plugin-Functions-04.t
25t/Nagios-Plugin-Getopt-03.t 37t/Monitoring-Plugin-Getopt-01.t
26t/Nagios-Plugin-Getopt-04.t 38t/Monitoring-Plugin-Getopt-02.t
27t/Nagios-Plugin-Performance-02.t 39t/Monitoring-Plugin-Getopt-03.t
28t/Nagios-Plugin-Performance.t 40t/Monitoring-Plugin-Getopt-04.t
29t/Nagios-Plugin-Range.t 41t/Monitoring-Plugin-Performance-02.t
30t/Nagios-Plugin-Threshold.t 42t/Monitoring-Plugin-Performance.t
43t/Monitoring-Plugin-Range.t
44t/Monitoring-Plugin-Threshold.t
31t/npg03/expected/00_basic 45t/npg03/expected/00_basic
32t/npg03/expected/00_noextra 46t/npg03/expected/00_noextra
33t/npg03/expected/01_override1 47t/npg03/expected/01_override1
@@ -38,8 +52,10 @@ t/npg03/expected/05_disk3
38t/npg03/expected/05_disk4 52t/npg03/expected/05_disk4
39t/npg03/expected/05_disk5 53t/npg03/expected/05_disk5
40t/npg03/expected/05_disk6 54t/npg03/expected/05_disk6
55t/npg03/expected/05_disk7
41t/npg03/expected/09_funnystuff 56t/npg03/expected/09_funnystuff
42t/npg03/expected/12_nosection_implicit 57t/npg03/expected/12_nosection_implicit
58t/npg03/expected/15_badsection_catch
43t/npg03/input/00_basic 59t/npg03/input/00_basic
44t/npg03/input/00_noextra 60t/npg03/input/00_noextra
45t/npg03/input/01_override1 61t/npg03/input/01_override1
@@ -50,9 +66,11 @@ t/npg03/input/05_disk3
50t/npg03/input/05_disk4 66t/npg03/input/05_disk4
51t/npg03/input/05_disk5 67t/npg03/input/05_disk5
52t/npg03/input/05_disk6 68t/npg03/input/05_disk6
69t/npg03/input/05_disk7
53t/npg03/input/09_funnystuff 70t/npg03/input/09_funnystuff
54t/npg03/input/12_nosection_implicit 71t/npg03/input/12_nosection_implicit
55t/npg03/input/13_nosection_explicit_dies 72t/npg03/input/13_nosection_explicit_dies
56t/npg03/input/14_badsection_dies 73t/npg03/input/14_badsection_dies
74t/npg03/input/15_badsection_catch
57t/npg03/plugins.ini 75t/npg03/plugins.ini
58t/npg03/README 76t/npg03/README
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644
index 0000000..134a92b
--- /dev/null
+++ b/MANIFEST.SKIP
@@ -0,0 +1,21 @@
1.DS_Store
2\.swp
3blib
4tmp
5\.git
6^Makefile$
7Makefile.old
8MANIFEST.bak
9MANIFEST.SKIP
10MYMETA.yml
11MYMETA.json
12pm_to_blib
13.*\.gz
14# does not work for centos without F::C::R installed
15inc/File/Copy/Recursive.pm
16TODO
17build-stamp
18configure-stamp
19nytprof/
20nytprof.out
21.~ko-6.1.3-perllint~
diff --git a/Makefile.PL b/Makefile.PL
index c043edb..d1f0c2a 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,22 +1,23 @@
1use 5.006; 1use inc::Module::Install;
2use ExtUtils::MakeMaker; 2
3# See lib/ExtUtils/MakeMaker.pm for details of how to influence 3name 'Monitoring-Plugin';
4# the contents of the Makefile that is written. 4all_from 'lib/Monitoring/Plugin/Functions.pm';
5WriteMakefile( 5author q{Monitoring Plugin Team <devel@monitoring-plugins.org>};
6 NAME => 'Nagios::Plugin', 6license 'perl';
7 VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION 7repository 'https://github.com/monitoring-plugins/monitoring-plugin-perl';
8 PREREQ_PM => { 8
9 Params::Validate => 0, 9requires 'Params::Validate' => 0;
10 Class::Accessor => 0, 10requires 'Class::Accessor' => 0;
11 Test::More => 0.62, 11requires 'Carp' => 0;
12 Carp => 0, 12requires 'Config::Tiny' => 0;
13 Config::Tiny => 0, 13requires 'File::Spec' => 0;
14 File::Spec => 0, 14requires 'File::Basename' => 0;
15 File::Basename => 0, 15requires 'IO::File' => 0;
16 IO::File => 0, 16requires 'Math::Calc::Units' => 0; # used in M::P::Performance
17 Math::Calc::Units => 0, # used in N::P::Performance 17
18 }, # e.g., Module::Name => 1.1 18
19 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 19build_requires 'Test::More' => 0.62;
20 (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module 20
21 AUTHOR => 'Nagios Plugin Development Team <nagiosplug-devel@lists.sourceforge.net>') : ()), 21auto_install;
22); 22
23WriteAll;
diff --git a/README b/README
index 939cc36..b0550d6 100644
--- a/README
+++ b/README
@@ -1,13 +1,12 @@
1Nagios::Plugin 1Monitoring::Plugin
2============== 2==================
3 3
4These modules are meant for perl developers of plugins for Nagios 4These modules are meant for perl developers of plugins for Naemon, Nagios,
5(http://nagiosplug.sourceforge.net). It is meant to simplify a lot 5Icinga, Shinken and other compatible products. It is meant to
6of the common functions required to do checking of a particular 6simplify a lot of the common functions required to do checking of a
7service. 7particular service.
8 8This module is maintained by the Monitoring-Plugins team
9The modules are still in an experimental stage and will be considered 9(https:://monitoring-plugins.org)
10stable when it reaches version 1.0.
11 10
12INSTALLATION 11INSTALLATION
13 12
@@ -23,16 +22,14 @@ EXAMPLE SCRIPT
23 22
24"Enough talk! Show me where to start!" 23"Enough talk! Show me where to start!"
25 24
26See the file 'check_stuff.pl' in the 't' directory for a complete 25See the file 'check_stuff.pl' in the 't' directory for a complete
27working example of a plugin script. 26working example of a plugin script.
28 27
29 28
30COPYRIGHT AND LICENCE 29COPYRIGHT AND LICENCE
31 30
32Copyright (C) 2006 by Nagios Plugin Development Team 31Copyright (C) 2006-2014 by Monitoring Plugin Team
33 32
34This library is free software; you can redistribute it and/or modify 33This library is free software; you can redistribute it and/or modify
35it under the same terms as Perl itself, either Perl version 5.8.4 or, 34it under the same terms as Perl itself, either Perl version 5.8.4 or,
36at your option, any later version of Perl 5 you may have available. 35at your option, any later version of Perl 5 you may have available.
37
38
diff --git a/lib/Nagios/Plugin.pm b/lib/Monitoring/Plugin.pm
index d85d35a..f9eb49e 100644
--- a/lib/Nagios/Plugin.pm
+++ b/lib/Monitoring/Plugin.pm
@@ -1,7 +1,7 @@
1 1
2package Nagios::Plugin; 2package Monitoring::Plugin;
3 3
4use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); 4use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES);
5use Params::Validate qw(:all); 5use Params::Validate qw(:all);
6 6
7use strict; 7use strict;
@@ -10,10 +10,10 @@ use warnings;
10use Carp; 10use Carp;
11use base qw(Class::Accessor::Fast); 11use base qw(Class::Accessor::Fast);
12 12
13Nagios::Plugin->mk_accessors(qw( 13Monitoring::Plugin->mk_accessors(qw(
14 shortname 14 shortname
15 perfdata 15 perfdata
16 messages 16 messages
17 opts 17 opts
18 threshold 18 threshold
19 )); 19 ));
@@ -25,8 +25,8 @@ our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT);
25 25
26# CPAN stupidly won't index this module without a literal $VERSION here, 26# CPAN stupidly won't index this module without a literal $VERSION here,
27# so we're forced to duplicate it explicitly 27# so we're forced to duplicate it explicitly
28# Make sure you update $Nagios::Plugin::Functions::VERSION too 28# Make sure you update $Monitoring::Plugin::Functions::VERSION too
29our $VERSION = "0.36"; 29our $VERSION = "0.37";
30 30
31sub new { 31sub new {
32 my $class = shift; 32 my $class = shift;
@@ -46,7 +46,7 @@ sub new {
46 }, 46 },
47 ); 47 );
48 48
49 my $shortname = Nagios::Plugin::Functions::get_shortname(\%args); 49 my $shortname = Monitoring::Plugin::Functions::get_shortname(\%args);
50 delete $args{shortname} if (exists $args{shortname}); 50 delete $args{shortname} if (exists $args{shortname});
51 my $self = { 51 my $self = {
52 shortname => $shortname, 52 shortname => $shortname,
@@ -61,16 +61,16 @@ sub new {
61 }; 61 };
62 bless $self, $class; 62 bless $self, $class;
63 if (exists $args{usage}) { 63 if (exists $args{usage}) {
64 require Nagios::Plugin::Getopt; 64 require Monitoring::Plugin::Getopt;
65 $self->opts( new Nagios::Plugin::Getopt(%args) ); 65 $self->opts( new Monitoring::Plugin::Getopt(%args) );
66 } 66 }
67 return $self; 67 return $self;
68} 68}
69 69
70sub add_perfdata { 70sub add_perfdata {
71 my ($self, %args) = @_; 71 my ($self, %args) = @_;
72 require Nagios::Plugin::Performance; 72 require Monitoring::Plugin::Performance;
73 my $perf = Nagios::Plugin::Performance->new(%args); 73 my $perf = Monitoring::Plugin::Performance->new(%args);
74 push @{$self->perfdata}, $perf; 74 push @{$self->perfdata}, $perf;
75} 75}
76sub all_perfoutput { 76sub all_perfoutput {
@@ -78,33 +78,41 @@ sub all_perfoutput {
78 return join(" ", map {$_->perfoutput} (@{$self->perfdata})); 78 return join(" ", map {$_->perfoutput} (@{$self->perfdata}));
79} 79}
80 80
81sub set_thresholds { 81sub set_thresholds {
82 my $self = shift; 82 my $self = shift;
83 require Nagios::Plugin::Threshold; 83 require Monitoring::Plugin::Threshold;
84 return $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_)); 84 return $self->threshold( Monitoring::Plugin::Threshold->set_thresholds(@_));
85} 85}
86 86
87# NP::Functions wrappers 87# MP::Functions wrappers
88sub plugin_exit {
89 my $self = shift;
90 Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self });
91}
92sub plugin_die {
93 my $self = shift;
94 Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
95}
88sub nagios_exit { 96sub nagios_exit {
89 my $self = shift; 97 my $self = shift;
90 Nagios::Plugin::Functions::nagios_exit(@_, { plugin => $self }); 98 Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self });
91} 99}
92sub nagios_die { 100sub nagios_die {
93 my $self = shift; 101 my $self = shift;
94 Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); 102 Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
95} 103}
96sub die { 104sub die {
97 my $self = shift; 105 my $self = shift;
98 Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); 106 Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
99} 107}
100sub max_state { 108sub max_state {
101 Nagios::Plugin::Functions::max_state(@_); 109 Monitoring::Plugin::Functions::max_state(@_);
102} 110}
103sub max_state_alt { 111sub max_state_alt {
104 Nagios::Plugin::Functions::max_state_alt(@_); 112 Monitoring::Plugin::Functions::max_state_alt(@_);
105} 113}
106 114
107# top level interface to Nagios::Plugin::Threshold 115# top level interface to Monitoring::Plugin::Threshold
108sub check_threshold { 116sub check_threshold {
109 my $self = shift; 117 my $self = shift;
110 118
@@ -143,11 +151,11 @@ sub check_threshold {
143 else { 151 else {
144 return UNKNOWN; 152 return UNKNOWN;
145 } 153 }
146 154
147 return $self->threshold->get_status($args{check}); 155 return $self->threshold->get_status($args{check});
148} 156}
149 157
150# top level interface to my Nagios::Plugin::Getopt object 158# top level interface to my Monitoring::Plugin::Getopt object
151sub add_arg { 159sub add_arg {
152 my $self = shift; 160 my $self = shift;
153 $self->opts->arg(@_) if $self->_check_for_opts; 161 $self->opts->arg(@_) if $self->_check_for_opts;
@@ -160,15 +168,15 @@ sub getopts {
160sub _check_for_opts { 168sub _check_for_opts {
161 my $self = shift; 169 my $self = shift;
162 croak 170 croak
163 "You have to supply a 'usage' param to Nagios::Plugin::new() if you want to use Getopts from your Nagios::Plugin object." 171 "You have to supply a 'usage' param to Monitoring::Plugin::new() if you want to use Getopts from your Monitoring::Plugin object."
164 unless ref $self->opts() eq 'Nagios::Plugin::Getopt'; 172 unless ref $self->opts() eq 'Monitoring::Plugin::Getopt';
165 return $self; 173 return $self;
166} 174}
167 175
168 176
169 177
170# ------------------------------------------------------------------------- 178# -------------------------------------------------------------------------
171# NP::Functions::check_messages helpers and wrappers 179# MP::Functions::check_messages helpers and wrappers
172 180
173sub add_message { 181sub add_message {
174 my $self = shift; 182 my $self = shift;
@@ -179,7 +187,7 @@ sub add_message {
179 187
180 # Store messages using strings rather than numeric codes 188 # Store messages using strings rather than numeric codes
181 $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; 189 $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code};
182 $code = lc $code; 190 $code = lc $code;
183 croak "Error code '$code' not supported by add_message" 191 croak "Error code '$code' not supported by add_message"
184 if $code eq 'unknown' || $code eq 'dependent'; 192 if $code eq 'unknown' || $code eq 'dependent';
185 193
@@ -199,7 +207,7 @@ sub check_messages {
199 if ($code eq 'ok') { 207 if ($code eq 'ok') {
200 $args{$code} = [ $args{$code} ]; 208 $args{$code} = [ $args{$code} ];
201 } else { 209 } else {
202 croak "Invalid argument '$code'" 210 croak "Invalid argument '$code'"
203 } 211 }
204 } 212 }
205 push @{$args{$code}}, @$messages; 213 push @{$args{$code}}, @$messages;
@@ -209,7 +217,7 @@ sub check_messages {
209 } 217 }
210 } 218 }
211 219
212 Nagios::Plugin::Functions::check_messages(%args); 220 Monitoring::Plugin::Functions::check_messages(%args);
213} 221}
214 222
215# ------------------------------------------------------------------------- 223# -------------------------------------------------------------------------
@@ -222,23 +230,23 @@ __END__
222 230
223=head1 NAME 231=head1 NAME
224 232
225Nagios::Plugin - A family of perl modules to streamline writing Nagios 233Monitoring::Plugin - A family of perl modules to streamline writing Naemon, Nagios,
226plugins 234Icinga or Shinken (and compatible) plugins.
227 235
228=head1 SYNOPSIS 236=head1 SYNOPSIS
229 237
230 # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default 238 # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default
231 # See also Nagios::Plugin::Functions for a functional interface 239 # See also Monitoring::Plugin::Functions for a functional interface
232 use Nagios::Plugin; 240 use Monitoring::Plugin;
233 241
234 # Constructor 242 # Constructor
235 $np = Nagios::Plugin->new; # OR 243 $np = Monitoring::Plugin->new; # OR
236 $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); # OR 244 $np = Monitoring::Plugin->new( shortname => "PAGESIZE" ); # OR
237 245
238 246
239 # use Nagios::Plugin::Getopt to process the @ARGV command line options: 247 # use Monitoring::Plugin::Getopt to process the @ARGV command line options:
240 # --verbose, --help, --usage, --timeout and --host are defined automatically. 248 # --verbose, --help, --usage, --timeout and --host are defined automatically.
241 $np = Nagios::Plugin->new( 249 $np = Monitoring::Plugin->new(
242 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] " 250 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] "
243 . "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]", 251 . "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
244 ); 252 );
@@ -247,7 +255,7 @@ plugins
247 $np->add_arg( 255 $np->add_arg(
248 spec => 'warning|w=s', 256 spec => 'warning|w=s',
249 help => '-w, --warning=INTEGER:INTEGER . See ' 257 help => '-w, --warning=INTEGER:INTEGER . See '
250 . 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT ' 258 . 'https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT '
251 . 'for the threshold format. ', 259 . 'for the threshold format. ',
252 ); 260 );
253 261
@@ -255,29 +263,29 @@ plugins
255 $np->getopts; 263 $np->getopts;
256 264
257 265
258 # Exit/return value methods - nagios_exit( CODE, MESSAGE ), 266 # Exit/return value methods - plugin_exit( CODE, MESSAGE ),
259 # nagios_die( MESSAGE, [CODE]) 267 # plugin_die( MESSAGE, [CODE])
260 $page = retrieve_page($page1) 268 $page = retrieve_page($page1)
261 or $np->nagios_exit( UNKNOWN, "Could not retrieve page" ); 269 or $np->plugin_exit( UNKNOWN, "Could not retrieve page" );
262 # Return code: 3; 270 # Return code: 3;
263 # output: PAGESIZE UNKNOWN - Could not retrieve page 271 # output: PAGESIZE UNKNOWN - Could not retrieve page
264 test_page($page) 272 test_page($page)
265 or $np->nagios_exit( CRITICAL, "Bad page found" ); 273 or $np->plugin_exit( CRITICAL, "Bad page found" );
266 274
267 # nagios_die() is just like nagios_exit(), but return code defaults 275 # plugin_die() is just like plugin_exit(), but return code defaults
268 # to UNKNOWN 276 # to UNKNOWN
269 $page = retrieve_page($page2) 277 $page = retrieve_page($page2)
270 or $np->nagios_die( "Could not retrieve page" ); 278 or $np->plugin_die( "Could not retrieve page" );
271 # Return code: 3; 279 # Return code: 3;
272 # output: PAGESIZE UNKNOWN - Could not retrieve page 280 # output: PAGESIZE UNKNOWN - Could not retrieve page
273 281
274 # Threshold methods 282 # Threshold methods
275 $code = $np->check_threshold( 283 $code = $np->check_threshold(
276 check => $value, 284 check => $value,
277 warning => $warning_threshold, 285 warning => $warning_threshold,
278 critical => $critical_threshold, 286 critical => $critical_threshold,
279 ); 287 );
280 $np->nagios_exit( $code, "Threshold check failed" ) if $code != OK; 288 $np->plugin_exit( $code, "Threshold check failed" ) if $code != OK;
281 289
282 290
283 # Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) - 291 # Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) -
@@ -290,38 +298,38 @@ plugins
290 } 298 }
291 } 299 }
292 ($code, $message) = $np->check_messages(); 300 ($code, $message) = $np->check_messages();
293 nagios_exit( $code, $message ); 301 plugin_exit( $code, $message );
294 # If any items in collection matched m/Error/, returns CRITICAL and 302 # If any items in collection matched m/Error/, returns CRITICAL and
295 # the joined set of Error messages; otherwise returns OK and the 303 # the joined set of Error messages; otherwise returns OK and the
296 # joined set of ok messages 304 # joined set of ok messages
297 305
298 306
299 # Perfdata methods 307 # Perfdata methods
300 $np->add_perfdata( 308 $np->add_perfdata(
301 label => "size", 309 label => "size",
302 value => $value, 310 value => $value,
303 uom => "kB", 311 uom => "kB",
304 threshold => $threshold, 312 threshold => $threshold,
305 ); 313 );
306 $np->add_perfdata( label => "time", ... ); 314 $np->add_perfdata( label => "time", ... );
307 $np->nagios_exit( OK, "page size at http://... was ${value}kB" ); 315 $np->plugin_exit( OK, "page size at http://... was ${value}kB" );
308 # Return code: 0; 316 # Return code: 0;
309 # output: PAGESIZE OK - page size at http://... was 36kB \ 317 # output: PAGESIZE OK - page size at http://... was 36kB \
310 # | size=36kB;10:25;25: time=... 318 # | size=36kB;10:25;25: time=...
311 319
312 320
313=head1 DESCRIPTION 321=head1 DESCRIPTION
314 322
315Nagios::Plugin and its associated Nagios::Plugin::* modules are a 323Monitoring::Plugin and its associated Monitoring::Plugin::* modules are a
316family of perl modules to streamline writing Nagios plugins. The main 324family of perl modules to streamline writing Monitoring plugins. The main
317end user modules are Nagios::Plugin, providing an object-oriented 325end user modules are Monitoring::Plugin, providing an object-oriented
318interface to the entire Nagios::Plugin::* collection, and 326interface to the entire Monitoring::Plugin::* collection, and
319Nagios::Plugin::Functions, providing a simpler functional interface to 327Monitoring::Plugin::Functions, providing a simpler functional interface to
320a useful subset of the available functionality. 328a useful subset of the available functionality.
321 329
322The purpose of the collection is to make it as simple as possible for 330The purpose of the collection is to make it as simple as possible for
323developers to create plugins that conform the Nagios Plugin guidelines 331developers to create plugins that conform the Monitoring Plugin guidelines
324(http://nagiosplug.sourceforge.net/developer-guidelines.html). 332(https://www.monitoring-plugins.org/doc/guidelines.html).
325 333
326 334
327=head2 EXPORTS 335=head2 EXPORTS
@@ -346,7 +354,7 @@ corresponding status code.
346=item %STATUS_TEXT 354=item %STATUS_TEXT
347 355
348A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the 356A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the
349corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the 357corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the
350reverse of %ERRORS. 358reverse of %ERRORS.
351 359
352=back 360=back
@@ -354,11 +362,11 @@ reverse of %ERRORS.
354 362
355=head2 CONSTRUCTOR 363=head2 CONSTRUCTOR
356 364
357 Nagios::Plugin->new; 365 Monitoring::Plugin->new;
358 366
359 Nagios::Plugin->new( shortname => 'PAGESIZE' ); 367 Monitoring::Plugin->new( shortname => 'PAGESIZE' );
360 368
361 Nagios::Plugin->new( 369 Monitoring::Plugin->new(
362 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] 370 usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>]
363 [ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ", 371 [ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ",
364 version => $VERSION, 372 version => $VERSION,
@@ -370,7 +378,7 @@ reverse of %ERRORS.
370 timeout => 15, 378 timeout => 15,
371 ); 379 );
372 380
373Instantiates a new Nagios::Plugin object. Accepts the following named 381Instantiates a new Monitoring::Plugin object. Accepts the following named
374arguments: 382arguments:
375 383
376=over 4 384=over 4
@@ -382,10 +390,10 @@ output by the various exit methods. Default: uc basename $0.
382 390
383=item usage ("Usage: %s --foo --bar") 391=item usage ("Usage: %s --foo --bar")
384 392
385Passing a value for the usage() argument makes Nagios::Plugin 393Passing a value for the usage() argument makes Monitoring::Plugin
386instantiate its own C<Nagios::Plugin::Getopt> object so you can start 394instantiate its own C<Monitoring::Plugin::Getopt> object so you can start
387doing command line argument processing. See 395doing command line argument processing. See
388L<Nagios::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the 396L<Monitoring::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the
389following options: 397following options:
390 398
391=item version 399=item version
@@ -406,7 +414,7 @@ following options:
406 414
407=head2 OPTION HANDLING METHODS 415=head2 OPTION HANDLING METHODS
408 416
409C<Nagios::Plugin> provides these methods for accessing the functionality in C<Nagios::Plugin::Getopt>. 417C<Monitoring::Plugin> provides these methods for accessing the functionality in C<Monitoring::Plugin::Getopt>.
410 418
411=over 4 419=over 4
412 420
@@ -416,7 +424,7 @@ Examples:
416 424
417 # Define --hello argument (named parameters) 425 # Define --hello argument (named parameters)
418 $plugin->add_arg( 426 $plugin->add_arg(
419 spec => 'hello=s', 427 spec => 'hello=s',
420 help => "--hello\n Hello string", 428 help => "--hello\n Hello string",
421 required => 1, 429 required => 1,
422 ); 430 );
@@ -425,19 +433,19 @@ Examples:
425 # Parameter order is 'spec', 'help', 'default', 'required?' 433 # Parameter order is 'spec', 'help', 'default', 'required?'
426 $plugin->add_arg('hello=s', "--hello\n Hello string", undef, 1); 434 $plugin->add_arg('hello=s', "--hello\n Hello string", undef, 1);
427 435
428See L<Nagios::Plugin::Getopt/ARGUMENTS> for more details. 436See L<Monitoring::Plugin::Getopt/ARGUMENTS> for more details.
429 437
430=item getopts() 438=item getopts()
431 439
432Parses and processes the command line options you've defined, 440Parses and processes the command line options you've defined,
433automatically doing the right thing with help/usage/version arguments. 441automatically doing the right thing with help/usage/version arguments.
434 442
435See L<Nagios::Plugin::Getopt/GETOPTS> for more details. 443See L<Monitoring::Plugin::Getopt/GETOPTS> for more details.
436 444
437=item opts() 445=item opts()
438 446
439Assuming you've instantiated it by passing 'usage' to new(), opts() 447Assuming you've instantiated it by passing 'usage' to new(), opts()
440returns the Nagios::Plugin object's C<Nagios::Plugin::Getopt> object, 448returns the Monitoring::Plugin object's C<Monitoring::Plugin::Getopt> object,
441with which you can do lots of great things. 449with which you can do lots of great things.
442 450
443E.g. 451E.g.
@@ -456,7 +464,7 @@ E.g.
456 # $plugin->getopts; 464 # $plugin->getopts;
457 print $plugin->opts->my_argument; 465 print $plugin->opts->my_argument;
458 466
459Again, see L<Nagios::Plugin::Getopt>. 467Again, see L<Monitoring::Plugin::Getopt>.
460 468
461=back 469=back
462 470
@@ -464,33 +472,41 @@ Again, see L<Nagios::Plugin::Getopt>.
464 472
465=over 4 473=over 4
466 474
467=item nagios_exit( <CODE>, $message ) 475=item plugin_exit( <CODE>, $message )
468 476
469Exit with return code CODE, and a standard nagios message of the 477Exit with return code CODE, and a standard nagios message of the
470form "SHORTNAME CODE - $message". 478form "SHORTNAME CODE - $message".
471 479
472=item nagios_die( $message, [<CODE>] ) 480=item plugin_die( $message, [<CODE>] )
473 481
474Same as nagios_exit(), except that CODE is optional, defaulting 482Same as plugin_exit(), except that CODE is optional, defaulting
475to UNKNOWN. NOTE: exceptions are not raised by default to calling code. 483to UNKNOWN. NOTE: exceptions are not raised by default to calling code.
476Set C<$_use_die> flag if this functionality is required (see test code). 484Set C<$_use_die> flag if this functionality is required (see test code).
477 485
486=item nagios_exit( <CODE>, $message )
487
488Alias for plugin_die(). Deprecated.
489
490=item nagios_die( $message, [<CODE>] )
491
492Alias for plugin_die(). Deprecated.
493
478=item die( $message, [<CODE>] ) 494=item die( $message, [<CODE>] )
479 495
480Alias for nagios_die(). Deprecated. 496Alias for plugin_die(). Deprecated.
481 497
482=item max_state, max_state_alt 498=item max_state, max_state_alt
483 499
484These are wrapper function for Nagios::Plugin::Functions::max_state and 500These are wrapper function for Monitoring::Plugin::Functions::max_state and
485Nagios::Plugin::Functions::max_state_alt. 501Monitoring::Plugin::Functions::max_state_alt.
486 502
487=back 503=back
488 504
489=head2 THRESHOLD METHODS 505=head2 THRESHOLD METHODS
490 506
491These provide a top level interface to the 507These provide a top level interface to the
492C<Nagios::Plugin::Threshold> module; for more details, see 508C<Monitoring::Plugin::Threshold> module; for more details, see
493L<Nagios::Plugin::Threshold> and L<Nagios::Plugin::Range>. 509L<Monitoring::Plugin::Threshold> and L<Monitoring::Plugin::Range>.
494 510
495=over 4 511=over 4
496 512
@@ -512,9 +528,9 @@ WARNING constant. The thresholds may be:
512You can specify $value as an array of values and each will be checked against 528You can specify $value as an array of values and each will be checked against
513the thresholds. 529the thresholds.
514 530
515The return value is ready to pass to C <nagios_exit>, e . g ., 531The return value is ready to pass to C <plugin_exit>, e . g .,
516 532
517 $p->nagios_exit( 533 $p->plugin_exit(
518 return_code => $p->check_threshold($result), 534 return_code => $p->check_threshold($result),
519 message => " sample result was $result" 535 message => " sample result was $result"
520 ); 536 );
@@ -523,13 +539,13 @@ The return value is ready to pass to C <nagios_exit>, e . g .,
523=item set_thresholds(warning => "10:25", critical => "~:25") 539=item set_thresholds(warning => "10:25", critical => "~:25")
524 540
525Sets the acceptable ranges and creates the plugin's 541Sets the acceptable ranges and creates the plugin's
526Nagios::Plugins::Threshold object. See 542Monitoring::Plugins::Threshold object. See
527http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT 543https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
528for details and examples of the threshold format. 544for details and examples of the threshold format.
529 545
530=item threshold() 546=item threshold()
531 547
532Returns the object's C<Nagios::Plugin::Threshold> object, if it has 548Returns the object's C<Monitoring::Plugin::Threshold> object, if it has
533been defined by calling set_thresholds(). You can pass a new 549been defined by calling set_thresholds(). You can pass a new
534Threshold object to it to replace the old one too, but you shouldn't 550Threshold object to it to replace the old one too, but you shouldn't
535need to do that from a plugin script. 551need to do that from a plugin script.
@@ -543,17 +559,17 @@ EXPERIMENTAL AND SUBJECT TO CHANGE
543add_messages and check_messages are higher-level convenience methods to add 559add_messages and check_messages are higher-level convenience methods to add
544and then check a set of messages, returning an appropriate return code 560and then check a set of messages, returning an appropriate return code
545and/or result message. They are equivalent to maintaining a set of @critical, 561and/or result message. They are equivalent to maintaining a set of @critical,
546@warning, and and @ok message arrays (add_message), and then doing a final 562@warning, and and @ok message arrays (add_message), and then doing a final
547if test (check_messages) like this: 563if test (check_messages) like this:
548 564
549 if (@critical) { 565 if (@critical) {
550 nagios_exit( CRITICAL, join(' ', @critical) ); 566 plugin_exit( CRITICAL, join(' ', @critical) );
551 } 567 }
552 elsif (@warning) { 568 elsif (@warning) {
553 nagios_exit( WARNING, join(' ', @warning) ); 569 plugin_exit( WARNING, join(' ', @warning) );
554 } 570 }
555 else { 571 else {
556 nagios_exit( OK, join(' ', @ok) ); 572 plugin_exit( OK, join(' ', @ok) );
557 } 573 }
558 574
559=over 4 575=over 4
@@ -571,7 +587,7 @@ Only CRITICAL, WARNING, and OK are accepted as valid codes.
571Check the current set of messages and return an appropriate nagios return 587Check the current set of messages and return an appropriate nagios return
572code and/or a result message. In scalar context, returns only a return 588code and/or a result message. In scalar context, returns only a return
573code; in list context returns both a return code and an output message, 589code; in list context returns both a return code and an output message,
574suitable for passing directly to nagios_exit() e.g. 590suitable for passing directly to plugin_exit() e.g.
575 591
576 $code = $np->check_messages; 592 $code = $np->check_messages;
577 ($code, $message) = $np->check_messages; 593 ($code, $message) = $np->check_messages;
@@ -587,7 +603,7 @@ check_messages accepts the following named arguments (none are required):
587 603
588=item join => SCALAR 604=item join => SCALAR
589 605
590A string used to join the relevant array to generate the message 606A string used to join the relevant array to generate the message
591string returned in list context i.e. if the 'critical' array @crit 607string returned in list context i.e. if the 'critical' array @crit
592is non-empty, check_messages would return: 608is non-empty, check_messages would return:
593 609
@@ -599,9 +615,9 @@ as the result message. Default: ' ' (space).
599 615
600By default, only one set of messages are joined and returned in the 616By default, only one set of messages are joined and returned in the
601result message i.e. if the result is CRITICAL, only the 'critical' 617result message i.e. if the result is CRITICAL, only the 'critical'
602messages are included in the result; if WARNING, only the 'warning' 618messages are included in the result; if WARNING, only the 'warning'
603messages are included; if OK, the 'ok' messages are included (if 619messages are included; if OK, the 'ok' messages are included (if
604supplied) i.e. the default is to return an 'errors-only' type 620supplied) i.e. the default is to return an 'errors-only' type
605message. 621message.
606 622
607If join_all is supplied, however, it will be used as a string to 623If join_all is supplied, however, it will be used as a string to
@@ -635,10 +651,10 @@ Add a set of performance data to the object. May be called multiple times.
635The performance data is included in the standard plugin output messages by 651The performance data is included in the standard plugin output messages by
636the various exit methods. 652the various exit methods.
637 653
638See the Nagios::Plugin::Performance documentation for more information on 654See the Monitoring::Plugin::Performance documentation for more information on
639performance data and the various field definitions, as well as the relevant 655performance data and the various field definitions, as well as the relevant
640section of the Nagios Plugin guidelines 656section of the Monitoring Plugin guidelines
641(http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). 657(https://www.monitoring-plugins.org/doc/guidelines.html#AEN202).
642 658
643=back 659=back
644 660
@@ -648,50 +664,49 @@ section of the Nagios Plugin guidelines
648"Enough talk! Show me some examples!" 664"Enough talk! Show me some examples!"
649 665
650See the file 'check_stuff.pl' in the 't' directory included with the 666See the file 'check_stuff.pl' in the 't' directory included with the
651Nagios::Plugin distribution for a complete working example of a plugin 667Monitoring::Plugin distribution for a complete working example of a plugin
652script. 668script.
653 669
654 670
655=head1 VERSIONING 671=head1 VERSIONING
656 672
657The Nagios::Plugin::* modules are currently experimental and so the 673The Monitoring::Plugin::* modules are currently experimental and so the
658interfaces may change up until Nagios::Plugin hits version 1.0, although 674interfaces may change up until Monitoring::Plugin hits version 1.0, although
659every attempt will be made to keep them as backwards compatible as 675every attempt will be made to keep them as backwards compatible as
660possible. 676possible.
661 677
662 678
663=head1 SEE ALSO 679=head1 SEE ALSO
664 680
665See L<Nagios::Plugin::Functions> for a simple functional interface to a subset 681See L<Monitoring::Plugin::Functions> for a simple functional interface to a subset
666of the available Nagios::Plugin functionality. 682of the available Monitoring::Plugin functionality.
667 683
668See also L<Nagios::Plugin::Getopt>, L<Nagios::Plugin::Range>, 684See also L<Monitoring::Plugin::Getopt>, L<Monitoring::Plugin::Range>,
669L<Nagios::Plugin::Performance>, L<Nagios::Plugin::Range>, and 685L<Monitoring::Plugin::Performance>, L<Monitoring::Plugin::Range>, and
670L<Nagios::Plugin::Threshold>. 686L<Monitoring::Plugin::Threshold>.
671 687
672The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. 688The Monitoring Plugin project page is at http://monitoring-plugins.org.
673 689
674 690
675=head1 BUGS 691=head1 BUGS
676 692
677Please report bugs in these modules to the Nagios Plugin development team: 693Please report bugs in these modules to the Monitoring Plugin development team:
678nagiosplug-devel@lists.sourceforge.net. 694devel@monitoring-plugins.org.
679 695
680 696
681=head1 AUTHOR 697=head1 AUTHOR
682 698
683Maintained by the Nagios Plugin development team - 699Maintained by the Monitoring Plugin development team -
684http://nagiosplug.sourceforge.net. 700https://www.monitoring-plugins.org.
685 701
686Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. 702Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>.
687 703
688=head1 COPYRIGHT AND LICENSE 704=head1 COPYRIGHT AND LICENSE
689 705
690Copyright (C) 2006 by Nagios Plugin Development Team 706Copyright (C) 2006-2014 by Monitoring Plugin Team
691 707
692This library is free software; you can redistribute it and/or modify it 708This library is free software; you can redistribute it and/or modify it
693under the same terms as Perl itself, either Perl version 5.8.4 or, at your 709under the same terms as Perl itself, either Perl version 5.8.4 or, at your
694option, any later version of Perl 5 you may have available. 710option, any later version of Perl 5 you may have available.
695 711
696=cut 712=cut
697
diff --git a/lib/Nagios/Plugin/Config.pm b/lib/Monitoring/Plugin/Config.pm
index dd270e9..5e941d4 100644
--- a/lib/Nagios/Plugin/Config.pm
+++ b/lib/Monitoring/Plugin/Config.pm
@@ -1,4 +1,4 @@
1package Nagios::Plugin::Config; 1package Monitoring::Plugin::Config;
2 2
3use strict; 3use strict;
4use Carp; 4use Carp;
@@ -7,10 +7,11 @@ use base qw(Config::Tiny);
7 7
8my $FILENAME1 = 'plugins.ini'; 8my $FILENAME1 = 'plugins.ini';
9my $FILENAME2 = 'nagios-plugins.ini'; 9my $FILENAME2 = 'nagios-plugins.ini';
10my $FILENAME3 = 'monitoring-plugins.ini';
10my $CURRENT_FILE = undef; 11my $CURRENT_FILE = undef;
11 12
12# Config paths ending in nagios (search for $FILENAME1) 13# Config paths ending in nagios (search for $FILENAME1)
13my @NAGIOS_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios); 14my @MONITORING_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios);
14# Config paths not ending in nagios (search for $FILENAME2) 15# Config paths not ending in nagios (search for $FILENAME2)
15my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt); 16my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt);
16 17
@@ -21,26 +22,30 @@ sub read
21 22
22 unless ($_[0]) { 23 unless ($_[0]) {
23 SEARCH: { 24 SEARCH: {
24 if ($ENV{NAGIOS_CONFIG_PATH}) { 25 if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) {
25 for (split /:/, $ENV{NAGIOS_CONFIG_PATH}) { 26 for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) {
26 my $file = File::Spec->catfile($_, $FILENAME1); 27 my $file = File::Spec->catfile($_, $FILENAME1);
27 unshift(@_, $file), last SEARCH if -f $file; 28 unshift(@_, $file), last SEARCH if -f $file;
28 $file = File::Spec->catfile($_, $FILENAME2); 29 $file = File::Spec->catfile($_, $FILENAME2);
29 unshift(@_, $file), last SEARCH if -f $file; 30 unshift(@_, $file), last SEARCH if -f $file;
31 $file = File::Spec->catfile($_, $FILENAME3);
32 unshift(@_, $file), last SEARCH if -f $file;
30 } 33 }
31 } 34 }
32 for (@NAGIOS_CONFIG_PATH) { 35 for (@MONITORING_CONFIG_PATH) {
33 my $file = File::Spec->catfile($_, $FILENAME1); 36 my $file = File::Spec->catfile($_, $FILENAME1);
34 unshift(@_, $file), last SEARCH if -f $file; 37 unshift(@_, $file), last SEARCH if -f $file;
35 } 38 }
36 for (@CONFIG_PATH) { 39 for (@CONFIG_PATH) {
37 my $file = File::Spec->catfile($_, $FILENAME2); 40 my $file = File::Spec->catfile($_, $FILENAME2);
38 unshift(@_, $file), last SEARCH if -f $file; 41 unshift(@_, $file), last SEARCH if -f $file;
42 $file = File::Spec->catfile($_, $FILENAME3);
43 unshift(@_, $file), last SEARCH if -f $file;
39 } 44 }
40 } 45 }
41 46
42 # Use die instead of croak, so we can pass a clean message downstream 47 # Use die instead of croak, so we can pass a clean message downstream
43 die "Cannot find '$FILENAME1' or '$FILENAME2' in any standard location.\n" unless $_[0]; 48 die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0];
44 } 49 }
45 50
46 $CURRENT_FILE = $_[0]; 51 $CURRENT_FILE = $_[0];
@@ -94,15 +99,15 @@ sub np_getfile { return $CURRENT_FILE; }
94 99
95=head1 NAME 100=head1 NAME
96 101
97Nagios::Plugin::Config - read nagios plugin .ini style config files 102Monitoring::Plugin::Config - read nagios plugin .ini style config files
98 103
99=head1 SYNOPSIS 104=head1 SYNOPSIS
100 105
101 # Read given nagios plugin config file 106 # Read given nagios plugin config file
102 $Config = Nagios::Plugin::Config->read( '/etc/nagios/plugins.ini' ); 107 $Config = Monitoring::Plugin::Config->read( '/etc/nagios/plugins.ini' );
103 108
104 # Search for and read default nagios plugin config file 109 # Search for and read default nagios plugin config file
105 $Config = Nagios::Plugin::Config->read(); 110 $Config = Monitoring::Plugin::Config->read();
106 111
107 # Access sections and properties (returns scalars or arrayrefs) 112 # Access sections and properties (returns scalars or arrayrefs)
108 $rootproperty = $Config->{_}->{rootproperty}; 113 $rootproperty = $Config->{_}->{rootproperty};
@@ -111,22 +116,22 @@ Nagios::Plugin::Config - read nagios plugin .ini style config files
111 116
112=head1 DESCRIPTION 117=head1 DESCRIPTION
113 118
114Nagios::Plugin::Config is a subclass of the excellent Config::Tiny, 119Monitoring::Plugin::Config is a subclass of the excellent Config::Tiny,
115with the following changes: 120with the following changes:
116 121
117=over 4 122=over 4
118 123
119=item 124=item
120 125
121Repeated keys are allowed within sections, returning lists instead of scalars 126Repeated keys are allowed within sections, returning lists instead of scalars
122 127
123=item 128=item
124 129
125Write functionality has been removed i.e. access is read only 130Write functionality has been removed i.e. access is read only
126 131
127=item 132=item
128 133
129Nagios::Plugin::Config searches for a default nagios plugins file if no explicit 134Monitoring::Plugin::Config searches for a default nagios plugins file if no explicit
130filename is given to C<read()>. The current standard locations checked are: 135filename is given to C<read()>. The current standard locations checked are:
131 136
132=over 4 137=over 4
@@ -137,15 +142,15 @@ filename is given to C<read()>. The current standard locations checked are:
137 142
138=item /usr/local/etc/nagios /etc/opt/nagios/plugins.ini 143=item /usr/local/etc/nagios /etc/opt/nagios/plugins.ini
139 144
140=item /etc/nagios-plugins.ini 145=item /etc/nagios-plugins.ini
141 146
142=item /usr/local/etc/nagios-plugins.ini 147=item /usr/local/etc/nagios-plugins.ini
143 148
144=item /etc/opt/nagios-plugins.ini 149=item /etc/opt/nagios-plugins.ini
145 150
146=back 151=back
147 152
148To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable 153To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable
149to the set of directories that should be checked. The first C<plugins.ini> or 154to the set of directories that should be checked. The first C<plugins.ini> or
150C<nagios-plugins.ini> file found will be used. 155C<nagios-plugins.ini> file found will be used.
151 156
@@ -154,21 +159,19 @@ C<nagios-plugins.ini> file found will be used.
154 159
155=head1 SEE ALSO 160=head1 SEE ALSO
156 161
157L<Config::Tiny>, L<Nagios::Plugin> 162L<Config::Tiny>, L<Monitoring::Plugin>
158 163
159 164
160=head1 AUTHORS 165=head1 AUTHOR
161 166
162This code is maintained by the Nagios Plugin Development Team: 167This code is maintained by the Monitoring Plugin Development Team: see
163L<http://nagiosplug.sourceforge.net>. 168https://monitoring-plugins.org
164 169
170=head1 COPYRIGHT AND LICENSE
165 171
166=head1 COPYRIGHT and LICENCE 172Copyright (C) 2006-2014 Monitoring Plugin Development Team
167
168Copyright (C) 2006-2007 by Nagios Plugin Development Team
169 173
170This library is free software; you can redistribute it and/or modify 174This library is free software; you can redistribute it and/or modify
171it under the same terms as Perl itself. 175it under the same terms as Perl itself.
172 176
173=cut 177=cut
174
diff --git a/lib/Monitoring/Plugin/ExitResult.pm b/lib/Monitoring/Plugin/ExitResult.pm
new file mode 100644
index 0000000..aa9f5da
--- /dev/null
+++ b/lib/Monitoring/Plugin/ExitResult.pm
@@ -0,0 +1,71 @@
1# Tiny helper class to return both output and return_code when testing
2
3package Monitoring::Plugin::ExitResult;
4
5use strict;
6
7# Stringify to message
8use overload '""' => sub { shift->{message} };
9
10# Constructor
11sub new {
12 my $class = shift;
13 return bless { return_code => $_[0], message => $_[1] }, $class;
14}
15
16# Accessors
17sub message { shift->{message} }
18sub return_code { shift->{return_code} }
19sub code { shift->{return_code} }
20
211;
22
23__END__
24
25=head1 NAME
26
27Monitoring::Plugin::ExitResult - Helper class for returning both output and
28return codes when testing.
29
30=head1 SYNOPSIS
31
32 use Test::More;
33 use Monitoring::Plugin::Functions;
34
35 # In a test file somewhere
36 Monitoring::Plugin::Functions::_fake_exit(1);
37
38 # Later ...
39 $e = plugin_exit( CRITICAL, 'aiiii ...' );
40 print $e->message;
41 print $e->return_code;
42
43 # MP::ExitResult also stringifies to the message output
44 like(plugin_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');
45
46
47
48=head1 DESCRIPTION
49
50Monitoring::Plugin::ExitResult is a tiny helper class intended for use
51when testing other Monitoring::Plugin modules. A Monitoring::Plugin::ExitResult
52object is returned by plugin_exit() and friends when
53Monitoring::Plugin::Functions::_fake_exit has been set, instead of doing a
54conventional print + exit.
55
56=head1 AUTHOR
57
58This code is maintained by the Monitoring Plugin Development Team: see
59https://monitoring-plugins.org
60
61Originally:
62 Gavin Carr , E<lt>gavin@openfusion.com.auE<gt>
63
64=head1 COPYRIGHT AND LICENSE
65
66Copyright (C) 2006-2014 Monitoring Plugin Development Team
67
68This library is free software; you can redistribute it and/or modify
69it under the same terms as Perl itself.
70
71=cut
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm
index 14fe661..d2856e8 100644
--- a/lib/Nagios/Plugin/Functions.pm
+++ b/lib/Monitoring/Plugin/Functions.pm
@@ -1,7 +1,7 @@
1# Functional interface to basic Nagios::Plugin constants, exports, 1# Functional interface to basic Monitoring::Plugin constants, exports,
2# and functions 2# and functions
3 3
4package Nagios::Plugin::Functions; 4package Monitoring::Plugin::Functions;
5 5
6use 5.006; 6use 5.006;
7 7
@@ -11,19 +11,19 @@ use File::Basename;
11use Params::Validate qw(:types validate); 11use Params::Validate qw(:types validate);
12use Math::Calc::Units; 12use Math::Calc::Units;
13 13
14# Remember to update Nagios::Plugins as well 14# Remember to update Monitoring::Plugins as well
15our $VERSION = "0.36"; 15our $VERSION = "0.37";
16 16
17our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); 17our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
18 18
19require Exporter; 19require Exporter;
20our @ISA = qw(Exporter); 20our @ISA = qw(Exporter);
21our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); 21our @EXPORT = (@STATUS_CODES, qw(plugin_exit plugin_die check_messages));
22our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re); 22our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re);
23our %EXPORT_TAGS = ( 23our %EXPORT_TAGS = (
24 all => [ @EXPORT, @EXPORT_OK ], 24 all => [ @EXPORT, @EXPORT_OK ],
25 codes => [ @STATUS_CODES ], 25 codes => [ @STATUS_CODES ],
26 functions => [ qw(nagios_exit nagios_die check_messages max_state max_state_alt convert) ], 26 functions => [ qw(plugin_exit plugin_die check_messages max_state max_state_alt convert) ],
27); 27);
28 28
29use constant OK => 0; 29use constant OK => 0;
@@ -61,7 +61,7 @@ sub get_shortname {
61 return $arg->{shortname} if (defined($arg->{shortname})); 61 return $arg->{shortname} if (defined($arg->{shortname}));
62 $shortname = $arg->{plugin} if (defined( $arg->{plugin})); 62 $shortname = $arg->{plugin} if (defined( $arg->{plugin}));
63 63
64 $shortname = uc basename($shortname || $ENV{NAGIOS_PLUGIN} || $0); 64 $shortname = uc basename($shortname || $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0);
65 $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_] 65 $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_]
66 $shortname =~ s/\..*$//; # Remove any trailing suffix 66 $shortname =~ s/\..*$//; # Remove any trailing suffix
67 return $shortname; 67 return $shortname;
@@ -85,8 +85,8 @@ sub max_state_alt {
85 return UNKNOWN; 85 return UNKNOWN;
86} 86}
87 87
88# nagios_exit( $code, $message ) 88# plugin_exit( $code, $message )
89sub nagios_exit { 89sub plugin_exit {
90 my ($code, $message, $arg) = @_; 90 my ($code, $message, $arg) = @_;
91 91
92 # Handle named parameters 92 # Handle named parameters
@@ -124,21 +124,21 @@ sub nagios_exit {
124 $output = "$shortname $output" if $shortname; 124 $output = "$shortname $output" if $shortname;
125 if ($arg->{plugin}) { 125 if ($arg->{plugin}) {
126 my $plugin = $arg->{plugin}; 126 my $plugin = $arg->{plugin};
127 $output .= " | ". $plugin->all_perfoutput 127 $output .= " | ". $plugin->all_perfoutput
128 if $plugin->perfdata && $plugin->all_perfoutput; 128 if $plugin->perfdata && $plugin->all_perfoutput;
129 } 129 }
130 $output .= "\n"; 130 $output .= "\n";
131 131
132 # Don't actually exit if _fake_exit set 132 # Don't actually exit if _fake_exit set
133 if ($_fake_exit) { 133 if ($_fake_exit) {
134 require Nagios::Plugin::ExitResult; 134 require Monitoring::Plugin::ExitResult;
135 return Nagios::Plugin::ExitResult->new($code, $output); 135 return Monitoring::Plugin::ExitResult->new($code, $output);
136 } 136 }
137 137
138 _nagios_exit($code, $output); 138 _plugin_exit($code, $output);
139} 139}
140 140
141sub _nagios_exit { 141sub _plugin_exit {
142 my ($code, $output) = @_; 142 my ($code, $output) = @_;
143 # Print output and exit; die if flag set and called via a die in stack backtrace 143 # Print output and exit; die if flag set and called via a die in stack backtrace
144 if ($_use_die) { 144 if ($_use_die) {
@@ -155,34 +155,34 @@ sub _nagios_exit {
155 exit $code; 155 exit $code;
156} 156}
157 157
158# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) 158# plugin_die( $message, [ $code ]) OR plugin_die( $code, $message )
159# Default $code: UNKNOWN 159# Default $code: UNKNOWN
160sub nagios_die { 160sub plugin_die {
161 my ($arg1, $arg2, $rest) = @_; 161 my ($arg1, $arg2, $rest) = @_;
162 162
163 # Named parameters 163 # Named parameters
164 if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) { 164 if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) {
165 return nagios_exit(@_); 165 return plugin_exit(@_);
166 } 166 }
167 167
168 # ($code, $message) 168 # ($code, $message)
169 elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) { 169 elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) {
170 return nagios_exit(@_); 170 return plugin_exit(@_);
171 } 171 }
172 172
173 # ($message, $code) 173 # ($message, $code)
174 elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) { 174 elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) {
175 return nagios_exit($arg2, $arg1, $rest); 175 return plugin_exit($arg2, $arg1, $rest);
176 } 176 }
177 177
178 # Else just assume $arg1 is the message and hope for the best 178 # Else just assume $arg1 is the message and hope for the best
179 else { 179 else {
180 return nagios_exit( UNKNOWN, $arg1, $arg2 ); 180 return plugin_exit( UNKNOWN, $arg1, $arg2 );
181 } 181 }
182} 182}
183 183
184# For backwards compatibility 184# For backwards compatibility
185sub die { nagios_die(@_); } 185sub die { plugin_die(@_); }
186 186
187 187
188# ------------------------------------------------------------------------ 188# ------------------------------------------------------------------------
@@ -197,9 +197,9 @@ sub convert
197} 197}
198 198
199# ------------------------------------------------------------------------ 199# ------------------------------------------------------------------------
200# check_messages - return a status and/or message based on a set of 200# check_messages - return a status and/or message based on a set of
201# message arrays. 201# message arrays.
202# Returns a nagios status code in scalar context. 202# Returns a nagios status code in scalar context.
203# Returns a code and a message in list context. 203# Returns a code and a message in list context.
204# The message is join($join, @array) for the relevant array for the code, 204# The message is join($join, @array) for the relevant array for the code,
205# or join($join_all, $message) for all arrays if $join_all is set. 205# or join($join_all, $message) for all arrays if $join_all is set.
@@ -222,18 +222,18 @@ sub check_messages {
222 # Compose message 222 # Compose message
223 my $message = ''; 223 my $message = '';
224 if ($arg{join_all}) { 224 if ($arg{join_all}) {
225 $message = join( $arg{join_all}, 225 $message = join( $arg{join_all},
226 map { @$_ ? join( $arg{'join'}, @$_) : () } 226 map { @$_ ? join( $arg{'join'}, @$_) : () }
227 $arg{critical}, 227 $arg{critical},
228 $arg{warning}, 228 $arg{warning},
229 $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] 229 $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : []
230 ); 230 );
231 } 231 }
232 232
233 else { 233 else {
234 $message ||= join( $arg{'join'}, @{$arg{critical}} ) 234 $message ||= join( $arg{'join'}, @{$arg{critical}} )
235 if $code == CRITICAL; 235 if $code == CRITICAL;
236 $message ||= join( $arg{'join'}, @{$arg{warning}} ) 236 $message ||= join( $arg{'join'}, @{$arg{warning}} )
237 if $code == WARNING; 237 if $code == WARNING;
238 $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} 238 $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok}
239 if $arg{ok}; 239 if $arg{ok};
@@ -252,28 +252,28 @@ __END__
252 252
253=head1 NAME 253=head1 NAME
254 254
255Nagios::Plugin::Functions - functions to simplify the creation of 255Monitoring::Plugin::Functions - functions to simplify the creation of
256Nagios plugins 256Nagios plugins
257 257
258=head1 SYNOPSIS 258=head1 SYNOPSIS
259 259
260 # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default 260 # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default
261 use Nagios::Plugin::Functions; 261 use Monitoring::Plugin::Functions;
262 262
263 # nagios_exit( CODE, $message ) - exit with error code CODE, 263 # plugin_exit( CODE, $message ) - exit with error code CODE,
264 # and message "PLUGIN CODE - $message" 264 # and message "PLUGIN CODE - $message"
265 nagios_exit( CRITICAL, $critical_error ) if $critical_error; 265 plugin_exit( CRITICAL, $critical_error ) if $critical_error;
266 nagios_exit( WARNING, $warning_error ) if $warning_error; 266 plugin_exit( WARNING, $warning_error ) if $warning_error;
267 nagios_exit( OK, $result ); 267 plugin_exit( OK, $result );
268 268
269 # nagios_die( $message, [$CODE] ) - just like nagios_exit(), 269 # plugin_die( $message, [$CODE] ) - just like plugin_exit(),
270 # but CODE is optional, defaulting to UNKNOWN 270 # but CODE is optional, defaulting to UNKNOWN
271 do_something() 271 do_something()
272 or nagios_die("do_something() failed horribly"); 272 or plugin_die("do_something() failed horribly");
273 do_something_critical() 273 do_something_critical()
274 or nagios_die("do_something_critical() failed", CRITICAL); 274 or plugin_die("do_something_critical() failed", CRITICAL);
275 275
276 # check_messages - check a set of message arrays, returning a 276 # check_messages - check a set of message arrays, returning a
277 # CODE and/or a result message 277 # CODE and/or a result message
278 $code = check_messages(critical => \@crit, warning => \@warn); 278 $code = check_messages(critical => \@crit, warning => \@warn);
279 ($code, $message) = check_messages( 279 ($code, $message) = check_messages(
@@ -281,18 +281,18 @@ Nagios plugins
281 ok => \@ok ); 281 ok => \@ok );
282 282
283 # get_shortname - return the default short name for this plugin 283 # get_shortname - return the default short name for this plugin
284 # (as used by nagios_exit/die; not exported by default) 284 # (as used by plugin_exit/die; not exported by default)
285 $shortname = get_shortname(); 285 $shortname = get_shortname();
286 286
287 287
288=head1 DESCRIPTION 288=head1 DESCRIPTION
289 289
290This module is part of the Nagios::Plugin family, a set of modules 290This module is part of the Monitoring::Plugin family, a set of modules
291for simplifying the creation of Nagios plugins. This module exports 291for simplifying the creation of Nagios plugins. This module exports
292convenience functions for the class methods provided by 292convenience functions for the class methods provided by
293Nagios::Plugin. It is intended for those who prefer a simpler 293Monitoring::Plugin. It is intended for those who prefer a simpler
294functional interface, and who do not need the additional 294functional interface, and who do not need the additional
295functionality of Nagios::Plugin. 295functionality of Monitoring::Plugin.
296 296
297=head2 EXPORTS 297=head2 EXPORTS
298 298
@@ -306,8 +306,8 @@ Nagios status code constants are exported by default:
306 306
307as are the following functions: 307as are the following functions:
308 308
309 nagios_exit 309 plugin_exit
310 nagios_die 310 plugin_die
311 check_messages 311 check_messages
312 312
313The following variables and functions are exported only on request: 313The following variables and functions are exported only on request:
@@ -325,14 +325,14 @@ The following functions are supported:
325 325
326=over 4 326=over 4
327 327
328=item nagios_exit( <CODE>, $message ) 328=item plugin_exit( <CODE>, $message )
329 329
330Exit with return code CODE, and a standard nagios message of the 330Exit with return code CODE, and a standard nagios message of the
331form "PLUGIN CODE - $message". 331form "PLUGIN CODE - $message".
332 332
333=item nagios_die( $message, [CODE] ) 333=item plugin_die( $message, [CODE] )
334 334
335Same as nagios_exit(), except that CODE is optional, defaulting 335Same as plugin_exit(), except that CODE is optional, defaulting
336to UNKNOWN. NOTE: exceptions are not raised by default to calling code. 336to UNKNOWN. NOTE: exceptions are not raised by default to calling code.
337Set C<$_use_die> flag if this functionality is required (see test code). 337Set C<$_use_die> flag if this functionality is required (see test code).
338 338
@@ -354,7 +354,7 @@ check_messages() accepts the following named arguments:
354 354
355=item critical => ARRAYREF 355=item critical => ARRAYREF
356 356
357An arrayref of critical error messages - check_messages() returns 357An arrayref of critical error messages - check_messages() returns
358CRITICAL if this arrayref is non-empty. Mandatory. 358CRITICAL if this arrayref is non-empty. Mandatory.
359 359
360=item warning => ARRAYREF 360=item warning => ARRAYREF
@@ -371,7 +371,7 @@ are empty. Optional.
371 371
372=item join => SCALAR 372=item join => SCALAR
373 373
374A string used to join the relevant array to generate the message 374A string used to join the relevant array to generate the message
375string returned in list context i.e. if the 'critical' array @crit 375string returned in list context i.e. if the 'critical' array @crit
376is non-empty, check_messages would return: 376is non-empty, check_messages would return:
377 377
@@ -383,9 +383,9 @@ as the result message. Optional; default: ' ' (space).
383 383
384By default, only one set of messages are joined and returned in the 384By default, only one set of messages are joined and returned in the
385result message i.e. if the result is CRITICAL, only the 'critical' 385result message i.e. if the result is CRITICAL, only the 'critical'
386messages are included in the result; if WARNING, only the 'warning' 386messages are included in the result; if WARNING, only the 'warning'
387messages are included; if OK, the 'ok' messages are included (if 387messages are included; if OK, the 'ok' messages are included (if
388supplied) i.e. the default is to return an 'errors-only' type 388supplied) i.e. the default is to return an 'errors-only' type
389message. 389message.
390 390
391If join_all is supplied, however, it will be used as a string to 391If join_all is supplied, however, it will be used as a string to
@@ -397,9 +397,9 @@ all messages are joined and returned.
397=item get_shortname 397=item get_shortname
398 398
399Return the default shortname used for this plugin i.e. the first 399Return the default shortname used for this plugin i.e. the first
400token reported by nagios_exit/nagios_die. The default is basically 400token reported by plugin_exit/plugin_die. The default is basically
401 401
402 uc basename( $ENV{NAGIOS_PLUGIN} || $0 ) 402 uc basename( $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0 )
403 403
404with any leading 'CHECK_' and trailing file suffixes removed. 404with any leading 'CHECK_' and trailing file suffixes removed.
405 405
@@ -427,18 +427,17 @@ internal tests performed can return UNKNOWN.
427 427
428=head1 SEE ALSO 428=head1 SEE ALSO
429 429
430Nagios::Plugin; the nagios plugin developer guidelines at 430Monitoring::Plugin; the nagios plugin developer guidelines at
431http://nagiosplug.sourceforge.net/developer-guidelines.html. 431https://www.monitoring-plugins.org/doc/guidelines.html.
432 432
433=head1 AUTHOR
433 434
434=head1 AUTHORS 435This code is maintained by the Monitoring Plugin Development Team: see
435 436https://monitoring-plugins.org
436This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net
437
438 437
439=head1 COPYRIGHT AND LICENSE 438=head1 COPYRIGHT AND LICENSE
440 439
441Copyright (C) 2006 by Nagios Plugin Development Team 440Copyright (C) 2006-2014 Monitoring Plugin Development Team
442 441
443This library is free software; you can redistribute it and/or modify 442This library is free software; you can redistribute it and/or modify
444it under the same terms as Perl itself. 443it under the same terms as Perl itself.
diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index 22ff642..ce1c0f9 100644
--- a/lib/Nagios/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -1,9 +1,9 @@
1# 1#
2# Nagios::Plugin::Getopt - OO perl module providing standardised argument 2# Monitoring::Plugin::Getopt - OO perl module providing standardised argument
3# processing for nagios plugins 3# processing for nagios plugins
4# 4#
5 5
6package Nagios::Plugin::Getopt; 6package Monitoring::Plugin::Getopt;
7 7
8use strict; 8use strict;
9use File::Basename; 9use File::Basename;
@@ -12,18 +12,18 @@ use Carp;
12use Params::Validate qw(:all); 12use Params::Validate qw(:all);
13use base qw(Class::Accessor); 13use base qw(Class::Accessor);
14 14
15use Nagios::Plugin::Functions; 15use Monitoring::Plugin::Functions;
16use Nagios::Plugin::Config; 16use Monitoring::Plugin::Config;
17use vars qw($VERSION); 17use vars qw($VERSION);
18$VERSION = $Nagios::Plugin::Functions::VERSION; 18$VERSION = $Monitoring::Plugin::Functions::VERSION;
19 19
20# Standard defaults 20# Standard defaults
21my %DEFAULT = ( 21my %DEFAULT = (
22 timeout => 15, 22 timeout => 15,
23 verbose => 0, 23 verbose => 0,
24 license => 24 license =>
25"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. 25"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
26It may be used, redistributed and/or modified under the terms of the GNU 26It may be used, redistributed and/or modified under the terms of the GNU
27General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", 27General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).",
28); 28);
29# Standard arguments 29# Standard arguments
@@ -60,7 +60,7 @@ sub _die
60 my $self = shift; 60 my $self = shift;
61 my ($msg) = @_; 61 my ($msg) = @_;
62 $msg .= "\n" unless substr($msg, -1) eq "\n"; 62 $msg .= "\n" unless substr($msg, -1) eq "\n";
63 Nagios::Plugin::Functions::_nagios_exit(3, $msg); 63 Monitoring::Plugin::Functions::_plugin_exit(3, $msg);
64} 64}
65 65
66# Return the given attribute, if set, including a final newline 66# Return the given attribute, if set, including a final newline
@@ -182,7 +182,7 @@ sub _help
182} 182}
183 183
184# Return a Getopt::Long-compatible option array from the current set of specs 184# Return a Getopt::Long-compatible option array from the current set of specs
185sub _process_specs_getopt_long 185sub _process_specs_getopt_long
186{ 186{
187 my $self = shift; 187 my $self = shift;
188 188
@@ -217,7 +217,7 @@ sub _check_required_opts
217 } 217 }
218 } 218 }
219 if (@missing) { 219 if (@missing) {
220 $self->_die($self->_usage . "\n" . 220 $self->_die($self->_usage . "\n" .
221 join("\n", map { sprintf "Missing argument: %s", $_ } @missing) . "\n"); 221 join("\n", map { sprintf "Missing argument: %s", $_ } @missing) . "\n");
222 } 222 }
223} 223}
@@ -243,7 +243,7 @@ sub _load_config_section
243 $section ||= $self->{_attr}->{plugin}; 243 $section ||= $self->{_attr}->{plugin};
244 244
245 my $Config; 245 my $Config;
246 eval { $Config = Nagios::Plugin::Config->read($file); }; 246 eval { $Config = Monitoring::Plugin::Config->read($file); };
247 $self->_die($@) if ($@); #TODO: add test? 247 $self->_die($@) if ($@); #TODO: add test?
248 248
249 # TODO: is this check sane? Does --extra-opts=foo require a [foo] section? 249 # TODO: is this check sane? Does --extra-opts=foo require a [foo] section?
@@ -295,7 +295,7 @@ sub _cmdline
295 next if $key =~ m/^_/; 295 next if $key =~ m/^_/;
296 296
297 # Skip defaults and internals 297 # Skip defaults and internals
298 next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key}; 298 next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key};
299 next if grep { $key eq $_ } qw(help usage version extra-opts); 299 next if grep { $key eq $_ } qw(help usage version extra-opts);
300 next unless defined $hash->{$key}; 300 next unless defined $hash->{$key};
301 301
@@ -307,7 +307,7 @@ sub _cmdline
307 $value = $self->_cmdline_value($value); 307 $value = $self->_cmdline_value($value);
308 if (length($key) > 1) { 308 if (length($key) > 1) {
309 push @args, sprintf "--%s=%s", $key, $value; 309 push @args, sprintf "--%s=%s", $key, $value;
310 } 310 }
311 else { 311 else {
312 push @args, "-$key", $value; 312 push @args, "-$key", $value;
313 } 313 }
@@ -445,7 +445,7 @@ sub _init
445 my $self = shift; 445 my $self = shift;
446 446
447 # Check params 447 # Check params
448 my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0); 448 my $plugin = basename($ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0);
449 my %attr = validate( @_, { 449 my %attr = validate( @_, {
450 usage => 1, 450 usage => 1,
451 version => 0, 451 version => 0,
@@ -470,7 +470,7 @@ sub _init
470 $self 470 $self
471} 471}
472 472
473sub new 473sub new
474{ 474{
475 my $class = shift; 475 my $class = shift;
476 my $self = bless {}, $class; 476 my $self = bless {}, $class;
@@ -485,20 +485,20 @@ __END__
485 485
486=head1 NAME 486=head1 NAME
487 487
488Nagios::Plugin::Getopt - OO perl module providing standardised argument 488Monitoring::Plugin::Getopt - OO perl module providing standardised argument
489processing for Nagios plugins 489processing for Nagios plugins
490 490
491 491
492=head1 SYNOPSIS 492=head1 SYNOPSIS
493 493
494 use Nagios::Plugin::Getopt; 494 use Monitoring::Plugin::Getopt;
495 495
496 # Instantiate object (usage is mandatory) 496 # Instantiate object (usage is mandatory)
497 $ng = Nagios::Plugin::Getopt->new( 497 $ng = Monitoring::Plugin::Getopt->new(
498 usage => "Usage: %s -H <host> -w <warning> -c <critical>", 498 usage => "Usage: %s -H <host> -w <warning> -c <critical>",
499 version => '0.1', 499 version => '0.1',
500 url => 'http://www.openfusion.com.au/labs/nagios/', 500 url => 'http://www.openfusion.com.au/labs/nagios/',
501 blurb => 'This plugin tests various stuff.', 501 blurb => 'This plugin tests various stuff.',
502 ); 502 );
503 503
504 # Add argument - named parameters (spec and help are mandatory) 504 # Add argument - named parameters (spec and help are mandatory)
@@ -509,7 +509,7 @@ processing for Nagios plugins
509 default => 10, 509 default => 10,
510 ); 510 );
511 511
512 # Add argument - positional parameters - arg spec, help text, 512 # Add argument - positional parameters - arg spec, help text,
513 # default value, required? (first two mandatory) 513 # default value, required? (first two mandatory)
514 $ng->arg( 514 $ng->arg(
515 'warning|w=i', 515 'warning|w=i',
@@ -528,23 +528,23 @@ processing for Nagios plugins
528 528
529=head1 DESCRIPTION 529=head1 DESCRIPTION
530 530
531Nagios::Plugin::Getopt is an OO perl module providing standardised and 531Monitoring::Plugin::Getopt is an OO perl module providing standardised and
532simplified argument processing for Nagios plugins. It implements 532simplified argument processing for Nagios plugins. It implements
533a number of standard arguments itself (--help, --version, 533a number of standard arguments itself (--help, --version,
534--usage, --timeout, --verbose, and their short form counterparts), 534--usage, --timeout, --verbose, and their short form counterparts),
535produces standardised nagios plugin help output, and allows 535produces standardised nagios plugin help output, and allows
536additional arguments to be easily defined. 536additional arguments to be easily defined.
537 537
538 538
539=head2 CONSTRUCTOR 539=head2 CONSTRUCTOR
540 540
541 # Instantiate object (usage is mandatory) 541 # Instantiate object (usage is mandatory)
542 $ng = Nagios::Plugin::Getopt->new( 542 $ng = Monitoring::Plugin::Getopt->new(
543 usage => 'Usage: %s --hello', 543 usage => 'Usage: %s --hello',
544 version => '0.01', 544 version => '0.01',
545 ); 545 );
546 546
547The Nagios::Plugin::Getopt constructor accepts the following named 547The Monitoring::Plugin::Getopt constructor accepts the following named
548arguments: 548arguments:
549 549
550=over 4 550=over 4
@@ -573,7 +573,7 @@ the longer --help output. e.g.
573 573
574=item url 574=item url
575 575
576URL for info about this plugin, included in the --version/-V output, 576URL for info about this plugin, included in the --version/-V output,
577and in the longer --help output (see preceding 'version' example). 577and in the longer --help output (see preceding 'version' example).
578 578
579=item blurb 579=item blurb
@@ -583,20 +583,20 @@ Short plugin description, included in the longer --help output
583 583
584=item license 584=item license
585 585
586License text, included in the longer --help output (see below for an 586License text, included in the longer --help output (see below for an
587example). By default, this is set to the standard nagios plugins 587example). By default, this is set to the standard nagios plugins
588GPL license text: 588GPL license text:
589 589
590 This nagios plugin is free software, and comes with ABSOLUTELY 590 This nagios plugin is free software, and comes with ABSOLUTELY
591 NO WARRANTY. It may be used, redistributed and/or modified under 591 NO WARRANTY. It may be used, redistributed and/or modified under
592 the terms of the GNU General Public Licence (see 592 the terms of the GNU General Public Licence (see
593 http://www.fsf.org/licensing/licenses/gpl.txt). 593 http://www.fsf.org/licensing/licenses/gpl.txt).
594 594
595Provide your own to replace this text in the help output. 595Provide your own to replace this text in the help output.
596 596
597=item extra 597=item extra
598 598
599Extra text to be appended at the end of the longer --help output. 599Extra text to be appended at the end of the longer --help output.
600 600
601=item plugin 601=item plugin
602 602
@@ -605,7 +605,7 @@ usually correct, but you can set it explicitly if not.
605 605
606=item timeout 606=item timeout
607 607
608Timeout period in seconds, overriding the standard timeout default 608Timeout period in seconds, overriding the standard timeout default
609(15 seconds). 609(15 seconds).
610 610
611=back 611=back
@@ -630,8 +630,8 @@ example:
630 $ ./check_tcp_range -h 630 $ ./check_tcp_range -h
631 check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/] 631 check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/]
632 632
633 This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. 633 This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
634 It may be used, redistributed and/or modified under the terms of the GNU 634 It may be used, redistributed and/or modified under the terms of the GNU
635 General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt). 635 General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).
636 636
637 This plugin tests arbitrary ranges/sets of tcp ports for a host. 637 This plugin tests arbitrary ranges/sets of tcp ports for a host.
@@ -647,7 +647,7 @@ example:
647 Host name or IP address 647 Host name or IP address
648 -p, --ports=STRING 648 -p, --ports=STRING
649 Port numbers to check. Format: comma-separated, colons for ranges, 649 Port numbers to check. Format: comma-separated, colons for ranges,
650 no spaces e.g. 8700:8705,8710:8715,8760 650 no spaces e.g. 8700:8705,8710:8715,8760
651 -t, --timeout=INTEGER 651 -t, --timeout=INTEGER
652 Seconds before plugin times out (default: 15) 652 Seconds before plugin times out (default: 15)
653 -v, --verbose 653 -v, --verbose
@@ -656,14 +656,14 @@ example:
656 656
657=head2 ARGUMENTS 657=head2 ARGUMENTS
658 658
659You can define arguments for your plugin using the arg() method, which 659You can define arguments for your plugin using the arg() method, which
660supports both named and positional arguments. In both cases 660supports both named and positional arguments. In both cases
661the C<spec> and C<help> arguments are required, while the C<label>, 661the C<spec> and C<help> arguments are required, while the C<label>,
662C<default>, and C<required> arguments are optional: 662C<default>, and C<required> arguments are optional:
663 663
664 # Define --hello argument (named parameters) 664 # Define --hello argument (named parameters)
665 $ng->arg( 665 $ng->arg(
666 spec => 'hello|h=s', 666 spec => 'hello|h=s',
667 help => "Hello string", 667 help => "Hello string",
668 required => 1, 668 required => 1,
669 ); 669 );
@@ -710,12 +710,12 @@ The help string is munged in two ways:
710 710
711=item 711=item
712 712
713First, if the help string does NOT begins with a '-' sign, it is prefixed 713First, if the help string does NOT begins with a '-' sign, it is prefixed
714by an expanded form of the C<spec> argument. For instance, the following 714by an expanded form of the C<spec> argument. For instance, the following
715hello argument: 715hello argument:
716 716
717 $ng->arg( 717 $ng->arg(
718 spec => 'hello|h=s', 718 spec => 'hello|h=s',
719 help => "Hello string", 719 help => "Hello string",
720 ); 720 );
721 721
@@ -727,9 +727,9 @@ would be displayed in the help output as:
727where the '-h, --hello=STRING' part is derived from the spec definition 727where the '-h, --hello=STRING' part is derived from the spec definition
728(by convention with short args first, then long, then label/type, if any). 728(by convention with short args first, then long, then label/type, if any).
729 729
730=item 730=item
731 731
732Second, if the string contains a '%s' it will be formatted via 732Second, if the string contains a '%s' it will be formatted via
733C<sprintf> with the 'default' as the argument i.e. 733C<sprintf> with the 'default' as the argument i.e.
734 734
735 sprintf($help, $default) 735 sprintf($help, $default)
@@ -756,18 +756,18 @@ would be displayed in the help output as:
756 Exit with WARNING status if less than PERCENT of disk space is free 756 Exit with WARNING status if less than PERCENT of disk space is free
757 757
758Note that in this case we've also specified explicit labels in another 758Note that in this case we've also specified explicit labels in another
759arrayref corresponding to the C<help> one - if this had been omitted 759arrayref corresponding to the C<help> one - if this had been omitted
760the types would have defaulted to 'STRING', instead of 'BYTES' and 760the types would have defaulted to 'STRING', instead of 'BYTES' and
761'PERCENT%'. 761'PERCENT%'.
762 762
763 763
764=item label 764=item label
765 765
766The C<label> argument is a scalar or an arrayref (see 'Multi-line help' 766The C<label> argument is a scalar or an arrayref (see 'Multi-line help'
767description above) that overrides the standard type expansion when generating 767description above) that overrides the standard type expansion when generating
768help text from the spec definition. By default, C<spec=i> arguments are 768help text from the spec definition. By default, C<spec=i> arguments are
769labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled 769labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled
770as C<=STRING>. By supplying your own C<label> argument you can override these 770as C<=STRING>. By supplying your own C<label> argument you can override these
771standard 'INTEGER' and 'STRING' designations. 771standard 'INTEGER' and 'STRING' designations.
772 772
773For multi-line help, you can supply an ordered list (arrayref) of labels to 773For multi-line help, you can supply an ordered list (arrayref) of labels to
@@ -789,13 +789,13 @@ if none is explicitly supplied.
789 789
790=item required 790=item required
791 791
792The C<required> argument is a boolean used to indicate that this argument 792The C<required> argument is a boolean used to indicate that this argument
793is mandatory (Nagios::Plugin::Getopt will exit with your usage message and 793is mandatory (Monitoring::Plugin::Getopt will exit with your usage message and
794a 'Missing argument' indicator if any required arguments are not supplied). 794a 'Missing argument' indicator if any required arguments are not supplied).
795 795
796=back 796=back
797 797
798Note that --help lists your arguments in the order they are defined, so 798Note that --help lists your arguments in the order they are defined, so
799you should order your C<arg()> calls accordingly. 799you should order your C<arg()> calls accordingly.
800 800
801 801
@@ -809,7 +809,7 @@ method, which takes no arguments:
809 809
810This parses the command line arguments passed to your plugin using 810This parses the command line arguments passed to your plugin using
811Getopt::Long and the builtin and provided argument specifications. 811Getopt::Long and the builtin and provided argument specifications.
812Flags and argument values are recorded within the object, and can 812Flags and argument values are recorded within the object, and can
813be accessed either using the generic get() accessor, or using named 813be accessed either using the generic get() accessor, or using named
814accessors corresponding to your argument names. For example: 814accessors corresponding to your argument names. For example:
815 815
@@ -824,14 +824,14 @@ accessors corresponding to your argument names. For example:
824 # ... 824 # ...
825 } 825 }
826 826
827Note that where you have defined alternate argument names, the first is 827Note that where you have defined alternate argument names, the first is
828considered the citation form. All the builtin arguments are available 828considered the citation form. All the builtin arguments are available
829using their long variant names. 829using their long variant names.
830 830
831 831
832=head2 BUILTIN PROCESSING 832=head2 BUILTIN PROCESSING
833 833
834The C<getopts()> method also handles processing of the immediate builtin 834The C<getopts()> method also handles processing of the immediate builtin
835arguments, namely --usage, --version, --help, as well as checking all 835arguments, namely --usage, --version, --help, as well as checking all
836required arguments have been supplied, so you don't have to handle 836required arguments have been supplied, so you don't have to handle
837those yourself. This means that your plugin will exit from the getopts() 837those yourself. This means that your plugin will exit from the getopts()
@@ -842,32 +842,28 @@ C<getopts()> also sets up a default ALRM timeout handler so you can use an
842 842
843 alarm $ng->timeout; 843 alarm $ng->timeout;
844 844
845around any blocking operations within your plugin (which you are free 845around any blocking operations within your plugin (which you are free
846to override if you want to use a custom timeout message). 846to override if you want to use a custom timeout message).
847 847
848 848
849=head1 SEE ALSO 849=head1 SEE ALSO
850 850
851Nagios::Plugin, Getopt::Long 851Monitoring::Plugin, Getopt::Long
852 852
853 853
854=head1 AUTHOR 854=head1 AUTHOR
855 855
856Gavin Carr <gavin@openfusion.com.au> 856This code is maintained by the Monitoring Plugin Development Team: see
857https://monitoring-plugins.org
857 858
859Originally:
860 Gavin Carr <gavin@openfusion.com.au>
858 861
859=head1 COPYRIGHT AND LICENSE 862=head1 COPYRIGHT AND LICENSE
860 863
861Copyright (C) 2006-2007 by the Nagios Plugin Development Team. 864Copyright (C) 2006-2014 Monitoring Plugin Development Team
862 865
863This module is free software. It may be used, redistributed 866This library is free software; you can redistribute it and/or modify
864and/or modified under either the terms of the Perl Artistic 867it under the same terms as Perl itself.
865License (see http://www.perl.com/perl/misc/Artistic.html)
866or the GNU General Public Licence (see
867http://www.fsf.org/licensing/licenses/gpl.txt).
868 868
869=cut 869=cut
870
871# arch-tag: c917effc-7400-4ee5-a5d6-baa9316a3abf
872# vim:smartindent:sw=2:et
873
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Monitoring/Plugin/Performance.pm
index 9248fea..90fc9f4 100644
--- a/lib/Nagios/Plugin/Performance.pm
+++ b/lib/Monitoring/Plugin/Performance.pm
@@ -1,4 +1,4 @@
1package Nagios::Plugin::Performance; 1package Monitoring::Plugin::Performance;
2 2
3use 5.006; 3use 5.006;
4 4
@@ -11,15 +11,15 @@ __PACKAGE__->mk_ro_accessors(
11 qw(label value uom warning critical min max) 11 qw(label value uom warning critical min max)
12); 12);
13 13
14use Nagios::Plugin::Functions; 14use Monitoring::Plugin::Functions;
15use Nagios::Plugin::Threshold; 15use Monitoring::Plugin::Threshold;
16use Nagios::Plugin::Range; 16use Monitoring::Plugin::Range;
17our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 17our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
18 18
19sub import { 19sub import {
20 my ($class, %attr) = @_; 20 my ($class, %attr) = @_;
21 $_ = $attr{use_die} || 0; 21 $_ = $attr{use_die} || 0;
22 Nagios::Plugin::Functions::_use_die($_); 22 Monitoring::Plugin::Functions::_use_die($_);
23} 23}
24 24
25# This is NOT the same as N::P::Functions::value_re. We leave that to be the strict 25# This is NOT the same as N::P::Functions::value_re. We leave that to be the strict
@@ -46,7 +46,7 @@ sub _parse {
46 return undef if $not_value; 46 return undef if $not_value;
47 } 47 }
48 my $p = $class->new( 48 my $p = $class->new(
49 label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4], 49 label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4],
50 min => $info[5], max => $info[6] 50 min => $info[5], max => $info[6]
51 ); 51 );
52 return $p; 52 return $p;
@@ -128,13 +128,13 @@ sub clean_label {
128sub threshold 128sub threshold
129{ 129{
130 my $self = shift; 130 my $self = shift;
131 return Nagios::Plugin::Threshold->set_thresholds( 131 return Monitoring::Plugin::Threshold->set_thresholds(
132 warning => $self->warning, critical => $self->critical 132 warning => $self->warning, critical => $self->critical
133 ); 133 );
134} 134}
135 135
136# Constructor - unpack thresholds, map args to hashref 136# Constructor - unpack thresholds, map args to hashref
137sub new 137sub new
138{ 138{
139 my $class = shift; 139 my $class = shift;
140 my %arg = @_; 140 my %arg = @_;
@@ -154,15 +154,15 @@ __END__
154 154
155=head1 NAME 155=head1 NAME
156 156
157Nagios::Plugin::Performance - class for handling Nagios::Plugin 157Monitoring::Plugin::Performance - class for handling Monitoring::Plugin
158performance data. 158performance data.
159 159
160=head1 SYNOPSIS 160=head1 SYNOPSIS
161 161
162 use Nagios::Plugin::Performance use_die => 1; 162 use Monitoring::Plugin::Performance use_die => 1;
163 163
164 # Constructor (also accepts a 'threshold' obj instead of warning/critical) 164 # Constructor (also accepts a 'threshold' obj instead of warning/critical)
165 $p = Nagios::Plugin::Performance->new( 165 $p = Monitoring::Plugin::Performance->new(
166 label => 'size', 166 label => 'size',
167 value => $value, 167 value => $value,
168 uom => "kB", 168 uom => "kB",
@@ -173,9 +173,9 @@ performance data.
173 ); 173 );
174 174
175 # Parser 175 # Parser
176 @perf = Nagios::Plugin::Performance->parse_perfstring( 176 @perf = Monitoring::Plugin::Performance->parse_perfstring(
177 "/=382MB;15264;15269;; /var=218MB;9443;9448" 177 "/=382MB;15264;15269;; /var=218MB;9443;9448"
178 ) 178 )
179 or warn("Failed to parse perfstring"); 179 or warn("Failed to parse perfstring");
180 180
181 # Accessors 181 # Accessors
@@ -197,14 +197,14 @@ performance data.
197 197
198=head1 DESCRIPTION 198=head1 DESCRIPTION
199 199
200Nagios::Plugin class for handling performance data. This is a public 200Monitoring::Plugin class for handling performance data. This is a public
201interface because it could be used by performance graphing routines, 201interface because it could be used by performance graphing routines,
202such as nagiostat (http://nagiostat.sourceforge.net), perfparse 202such as nagiostat (http://nagiostat.sourceforge.net), perfparse
203(http://perfparse.sourceforge.net), nagiosgraph 203(http://perfparse.sourceforge.net), nagiosgraph
204(http://nagiosgraph.sourceforge.net) or NagiosGrapher 204(http://nagiosgraph.sourceforge.net) or NagiosGrapher
205(http://www.nagiosexchange.org/NagiosGrapher.84.0.html). 205(http://www.nagiosexchange.org/NagiosGrapher.84.0.html).
206 206
207Nagios::Plugin::Performance offers both a parsing interface (via 207Monitoring::Plugin::Performance offers both a parsing interface (via
208parse_perfstring), for turning nagios performance output strings into 208parse_perfstring), for turning nagios performance output strings into
209their components, and a composition interface (via new), for turning 209their components, and a composition interface (via new), for turning
210components into perfdata strings. 210components into perfdata strings.
@@ -213,7 +213,7 @@ components into perfdata strings.
213 213
214If you are using this module for the purposes of parsing perf data, you 214If you are using this module for the purposes of parsing perf data, you
215will probably want to set use_die => 1 at use time. This forces 215will probably want to set use_die => 1 at use time. This forces
216&Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() - 216&Monitoring::Plugin::Functions::plugin_exit to call die() - rather than exit() -
217when an error occurs. This is then trappable by an eval. If you don't set use_die, 217when an error occurs. This is then trappable by an eval. If you don't set use_die,
218then an error in these modules will cause your script to exit 218then an error in these modules will cause your script to exit
219 219
@@ -221,14 +221,14 @@ then an error in these modules will cause your script to exit
221 221
222=over 4 222=over 4
223 223
224=item Nagios::Plugin::Performance->new(%attributes) 224=item Monitoring::Plugin::Performance->new(%attributes)
225 225
226Instantiates a new Nagios::Plugin::Performance object with the given 226Instantiates a new Monitoring::Plugin::Performance object with the given
227attributes. 227attributes.
228 228
229=item Nagios::Plugin::Performance->parse_perfstring($string) 229=item Monitoring::Plugin::Performance->parse_perfstring($string)
230 230
231Returns an array of Nagios::Plugin::Performance objects based on the string 231Returns an array of Monitoring::Plugin::Performance objects based on the string
232entered. If there is an error parsing the string - which may consists of several 232entered. If there is an error parsing the string - which may consists of several
233sets of data - will return an array with all the successfully parsed sets. 233sets of data - will return an array with all the successfully parsed sets.
234 234
@@ -247,18 +247,18 @@ These all return scalars. min and max are not well supported yet.
247 247
248=item threshold 248=item threshold
249 249
250Returns a Nagios::Plugin::Threshold object holding the warning and critical 250Returns a Monitoring::Plugin::Threshold object holding the warning and critical
251ranges for this performance data (if any). 251ranges for this performance data (if any).
252 252
253=item rrdlabel 253=item rrdlabel
254 254
255Returns a string based on 'label' that is suitable for use as dataset name of 255Returns a string based on 'label' that is suitable for use as dataset name of
256an RRD i.e. munges label to be 1-19 characters long with only characters 256an RRD i.e. munges label to be 1-19 characters long with only characters
257[a-zA-Z0-9_]. 257[a-zA-Z0-9_].
258 258
259This calls $self->clean_label and then truncates to 19 characters. 259This calls $self->clean_label and then truncates to 19 characters.
260 260
261There is no guarantee that multiple N:P:Performance objects will have unique 261There is no guarantee that multiple N:P:Performance objects will have unique
262rrdlabels. 262rrdlabels.
263 263
264=item clean_label 264=item clean_label
@@ -270,25 +270,25 @@ It also converts "/" to "root" and "/{name}" to "{name}".
270 270
271=item perfoutput 271=item perfoutput
272 272
273Outputs the data in Nagios::Plugin perfdata format i.e. 273Outputs the data in Monitoring::Plugin perfdata format i.e.
274label=value[uom];[warn];[crit];[min];[max]. 274label=value[uom];[warn];[crit];[min];[max].
275 275
276=back 276=back
277 277
278=head1 SEE ALSO 278=head1 SEE ALSO
279 279
280Nagios::Plugin, Nagios::Plugin::Threshold, http://nagiosplug.sourceforge.net. 280Monitoring::Plugin, Monitoring::Plugin::Threshold, https://www.monitoring-plugins.org/doc/guidelines.html
281 281
282=head1 AUTHOR 282=head1 AUTHOR
283 283
284This code is maintained by the Nagios Plugin Development Team: see 284This code is maintained by the Monitoring Plugin Development Team: see
285http://nagiosplug.sourceforge.net. 285https://monitoring-plugins.org
286 286
287=head1 COPYRIGHT AND LICENSE 287=head1 COPYRIGHT AND LICENSE
288 288
289Copyright (C) 2006-2007 Nagios Plugin Development Team 289Copyright (C) 2006-2014 Monitoring Plugin Development Team
290 290
291This library is free software; you can redistribute it and/or modify 291This library is free software; you can redistribute it and/or modify
292it under the same terms as Perl itself. 292it under the same terms as Perl itself.
293 293
294=cut 294=cut
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Monitoring/Plugin/Range.pm
index 536f6bb..af19577 100644
--- a/lib/Nagios/Plugin/Range.pm
+++ b/lib/Monitoring/Plugin/Range.pm
@@ -1,4 +1,4 @@
1package Nagios::Plugin::Range; 1package Monitoring::Plugin::Range;
2 2
3use 5.006; 3use 5.006;
4 4
@@ -11,8 +11,8 @@ __PACKAGE__->mk_accessors(
11 qw(start end start_infinity end_infinity alert_on) 11 qw(start end start_infinity end_infinity alert_on)
12); 12);
13 13
14use Nagios::Plugin::Functions qw(:DEFAULT $value_re); 14use Monitoring::Plugin::Functions qw(:DEFAULT $value_re);
15our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 15our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
16 16
17use overload 17use overload
18 'eq' => sub { shift->_stringify }, 18 'eq' => sub { shift->_stringify },
@@ -26,7 +26,7 @@ sub _stringify {
26 my $self = shift; 26 my $self = shift;
27 return "" unless $self->is_set; 27 return "" unless $self->is_set;
28 return (($self->alert_on) ? "@" : "") . 28 return (($self->alert_on) ? "@" : "") .
29 (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . 29 (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) .
30 (($self->end_infinity == 1) ? "" : $self->end); 30 (($self->end_infinity == 1) ? "" : $self->end);
31} 31}
32 32
@@ -47,7 +47,7 @@ sub _set_range_end {
47 $self->end_infinity(0); 47 $self->end_infinity(0);
48} 48}
49 49
50# Returns a N::P::Range object if the string is a conforms to a Nagios Plugin range string, otherwise null 50# Returns a N::P::Range object if the string is a conforms to a Monitoring Plugin range string, otherwise null
51sub parse_range_string { 51sub parse_range_string {
52 my ($class, $string) = @_; 52 my ($class, $string) = @_;
53 my $valid = 0; 53 my $valid = 0;
@@ -118,7 +118,7 @@ sub check_range {
118} 118}
119 119
120# Constructor - map args to hashref for SUPER 120# Constructor - map args to hashref for SUPER
121sub new 121sub new
122{ 122{
123 shift->SUPER::new({ @_ }); 123 shift->SUPER::new({ @_ });
124} 124}
@@ -129,18 +129,18 @@ __END__
129 129
130=head1 NAME 130=head1 NAME
131 131
132Nagios::Plugin::Range - class for handling Nagios::Plugin range data. 132Monitoring::Plugin::Range - class for handling Monitoring::Plugin range data.
133 133
134=head1 SYNOPSIS 134=head1 SYNOPSIS
135 135
136 # NB: This is an internal Nagios::Plugin class. 136 # NB: This is an internal Monitoring::Plugin class.
137 # See Nagios::Plugin itself for public interfaces. 137 # See Monitoring::Plugin itself for public interfaces.
138 138
139 # Instantiate an empty range object 139 # Instantiate an empty range object
140 $r = Nagios::Plugin::Range->new; 140 $r = Monitoring::Plugin::Range->new;
141 141
142 # Instantiate by parsing a standard nagios range string 142 # Instantiate by parsing a standard nagios range string
143 $r = Nagios::Plugin::Range->parse_range_string( $range_str ); 143 $r = Monitoring::Plugin::Range->parse_range_string( $range_str );
144 144
145 # Returns true if the range is defined/non-empty 145 # Returns true if the range is defined/non-empty
146 $r->is_set; 146 $r->is_set;
@@ -151,17 +151,17 @@ Nagios::Plugin::Range - class for handling Nagios::Plugin range data.
151 151
152=head1 DESCRIPTION 152=head1 DESCRIPTION
153 153
154Internal Nagios::Plugin class for handling common range data. See 154Internal Monitoring::Plugin class for handling common range data. See
155Nagios::Plugin for public interfaces. 155Monitoring::Plugin for public interfaces.
156 156
157=head1 AUTHOR 157=head1 AUTHOR
158 158
159This code is maintained by the Nagios Plugin Development Team: see 159This code is maintained by the Monitoring Plugin Development Team: see
160http://nagiosplug.sourceforge.net. 160https://monitoring-plugins.org
161 161
162=head1 COPYRIGHT AND LICENSE 162=head1 COPYRIGHT AND LICENSE
163 163
164Copyright (C) 2006-2007 Nagios Plugin Development Team 164Copyright (C) 2006-2014 Monitoring Plugin Development Team
165 165
166This library is free software; you can redistribute it and/or modify 166This library is free software; you can redistribute it and/or modify
167it under the same terms as Perl itself. 167it under the same terms as Perl itself.
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Monitoring/Plugin/Threshold.pm
index 95a089b..e71e21b 100644
--- a/lib/Nagios/Plugin/Threshold.pm
+++ b/lib/Monitoring/Plugin/Threshold.pm
@@ -1,4 +1,4 @@
1package Nagios::Plugin::Threshold; 1package Monitoring::Plugin::Threshold;
2 2
3use 5.006; 3use 5.006;
4 4
@@ -8,11 +8,11 @@ use warnings;
8use base qw(Class::Accessor::Fast); 8use base qw(Class::Accessor::Fast);
9__PACKAGE__->mk_accessors(qw(warning critical)); 9__PACKAGE__->mk_accessors(qw(warning critical));
10 10
11use Nagios::Plugin::Range; 11use Monitoring::Plugin::Range;
12use Nagios::Plugin::Functions qw(:codes nagios_die); 12use Monitoring::Plugin::Functions qw(:codes plugin_die);
13our ($VERSION) = $Nagios::Plugin::Functions::VERSION; 13our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
14 14
15sub get_status 15sub get_status
16{ 16{
17 my ($self, $value) = @_; 17 my ($self, $value) = @_;
18 18
@@ -22,7 +22,7 @@ sub get_status
22 return CRITICAL if $self->critical->check_range($v); 22 return CRITICAL if $self->critical->check_range($v);
23 } 23 }
24 } 24 }
25 foreach my $v (@$value) { 25 foreach my $v (@$value) {
26 if ($self->warning->is_set) { 26 if ($self->warning->is_set) {
27 return WARNING if $self->warning->check_range($v); 27 return WARNING if $self->warning->check_range($v);
28 } 28 }
@@ -35,21 +35,21 @@ sub _inflate
35 my ($self, $value, $key) = @_; 35 my ($self, $value, $key) = @_;
36 36
37 # Return an undefined range if $value is undef 37 # Return an undefined range if $value is undef
38 return Nagios::Plugin::Range->new if ! defined $value; 38 return Monitoring::Plugin::Range->new if ! defined $value;
39 39
40 # For refs, check isa N::P::Range 40 # For refs, check isa N::P::Range
41 if (ref $value) { 41 if (ref $value) {
42 nagios_die("Invalid $key object: type " . ref $value) 42 plugin_die("Invalid $key object: type " . ref $value)
43 unless $value->isa("Nagios::Plugin::Range"); 43 unless $value->isa("Monitoring::Plugin::Range");
44 return $value; 44 return $value;
45 } 45 }
46 46
47 # Another quick exit if $value is an empty string 47 # Another quick exit if $value is an empty string
48 return Nagios::Plugin::Range->new if $value eq ""; 48 return Monitoring::Plugin::Range->new if $value eq "";
49 49
50 # Otherwise parse $value 50 # Otherwise parse $value
51 my $range = Nagios::Plugin::Range->parse_range_string($value); 51 my $range = Monitoring::Plugin::Range->parse_range_string($value);
52 nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); 52 plugin_die("Cannot parse $key range: '$value'") unless(defined($range));
53 return $range; 53 return $range;
54} 54}
55 55
@@ -70,9 +70,9 @@ sub set
70 my ($key, $value) = @_; 70 my ($key, $value) = @_;
71 $self->SUPER::set($key, $self->_inflate($value, $key)); 71 $self->SUPER::set($key, $self->_inflate($value, $key));
72} 72}
73 73
74# Constructor - inflate scalars to N::P::Range objects 74# Constructor - inflate scalars to N::P::Range objects
75sub new 75sub new
76{ 76{
77 my ($self, %arg) = @_; 77 my ($self, %arg) = @_;
78 $self->SUPER::new({ 78 $self->SUPER::new({
@@ -86,15 +86,15 @@ __END__
86 86
87=head1 NAME 87=head1 NAME
88 88
89Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds. 89Monitoring::Plugin::Threshold - class for handling Monitoring::Plugin thresholds.
90 90
91=head1 SYNOPSIS 91=head1 SYNOPSIS
92 92
93 # NB: This is an internal Nagios::Plugin class. 93 # NB: This is an internal Monitoring::Plugin class.
94 # See Nagios::Plugin itself for public interfaces. 94 # See Monitoring::Plugin itself for public interfaces.
95 95
96 # Constructor 96 # Constructor
97 $t = Nagios::Plugin::Threshold->set_thresholds( 97 $t = Monitoring::Plugin::Threshold->set_thresholds(
98 warning => $warning_range_string, 98 warning => $warning_range_string,
99 critical => $critical_range_string, 99 critical => $critical_range_string,
100 ); 100 );
@@ -110,10 +110,10 @@ Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds.
110 110
111=head1 DESCRIPTION 111=head1 DESCRIPTION
112 112
113Internal Nagios::Plugin class for handling threshold data. See 113Internal Monitoring::Plugin class for handling threshold data. See
114Nagios::Plugin for public interfaces. 114Monitoring::Plugin for public interfaces.
115 115
116A threshold object contains (typically) a pair of ranges, associated 116A threshold object contains (typically) a pair of ranges, associated
117with a particular severity e.g. 117with a particular severity e.g.
118 118
119 warning => range1 119 warning => range1
@@ -121,12 +121,12 @@ with a particular severity e.g.
121 121
122=head1 AUTHOR 122=head1 AUTHOR
123 123
124This code is maintained by the Nagios Plugin Development Team: see 124This code is maintained by the Monitoring Plugin Development Team: see
125http://nagiosplug.sourceforge.net. 125https://monitoring-plugins.org
126 126
127=head1 COPYRIGHT AND LICENSE 127=head1 COPYRIGHT AND LICENSE
128 128
129Copyright (C) 2006-2007 Nagios Plugin Development Team 129Copyright (C) 2006-2014 Monitoring Plugin Development Team
130 130
131This library is free software; you can redistribute it and/or modify 131This library is free software; you can redistribute it and/or modify
132it under the same terms as Perl itself. 132it under the same terms as Perl itself.
diff --git a/lib/Nagios/Plugin/ExitResult.pm b/lib/Nagios/Plugin/ExitResult.pm
deleted file mode 100644
index b161e9e..0000000
--- a/lib/Nagios/Plugin/ExitResult.pm
+++ /dev/null
@@ -1,67 +0,0 @@
1# Tiny helper class to return both output and return_code when testing
2
3package Nagios::Plugin::ExitResult;
4
5use strict;
6
7# Stringify to message
8use overload '""' => sub { shift->{message} };
9
10# Constructor
11sub new {
12 my $class = shift;
13 return bless { return_code => $_[0], message => $_[1] }, $class;
14}
15
16# Accessors
17sub message { shift->{message} }
18sub return_code { shift->{return_code} }
19sub code { shift->{return_code} }
20
211;
22
23__END__
24
25=head1 NAME
26
27Nagios::Plugin::ExitResult - Helper class for returning both output and
28return codes when testing.
29
30=head1 SYNOPSIS
31
32 use Test::More;
33 use Nagios::Plugin::Functions;
34
35 # In a test file somewhere
36 Nagios::Plugin::Functions::_fake_exit(1);
37
38 # Later ...
39 $e = nagios_exit( CRITICAL, 'aiiii ...' );
40 print $e->message;
41 print $e->return_code;
42
43 # NP::ExitResult also stringifies to the message output
44 like(nagios_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');
45
46
47
48=head1 DESCRIPTION
49
50Nagios::Plugin::ExitResult is a tiny helper class intended for use
51when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult
52object is returned by nagios_exit() and friends when
53Nagios::Plugin::Functions::_fake_exit has been set, instead of doing a
54conventional print + exit.
55
56=head1 AUTHOR
57
58Gavin Carr , E<lt>gavin@openfusion.com.auE<gt>
59
60=head1 COPYRIGHT AND LICENSE
61
62Copyright (C) 2006 by Nagios Plugin Development Team
63
64This library is free software; you can redistribute it and/or modify
65it under the same terms as Perl itself.
66
67=cut
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