summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2014-01-20 00:54:34 +0100
committerSven Nierlein <sven@nierlein.de>2014-01-20 00:54:34 +0100
commitb418181dfe80dd75169b6e8a619ac1932155dea2 (patch)
treecad9c0ae0eae8e800cfff60555ead06ad33c6856 /lib
parent1cd8d1c52cbd47121f344c4074aec84653f412ce (diff)
downloadmonitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we also rename this module. Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'lib')
-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
9 files changed, 436 insertions, 419 deletions
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