[monitoring-plugin-perl] renamed module into Monitoring::Plugin
Git Repository
git at nagios-plugins.org
Wed Jan 22 09:10:02 CET 2014
Module: monitoring-plugin-perl
Branch: master
Commit: b418181dfe80dd75169b6e8a619ac1932155dea2
Author: Sven Nierlein <sven at nierlein.de>
Date: Mon Jan 20 00:54:34 2014 +0100
URL: https://www.nagios-plugins.org/repositories/monitoring-plugin-perl/commit/?id=b418181
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we
also rename this module.
Signed-off-by: Sven Nierlein <sven at nierlein.de>
---
.gitignore | 5 +
Changes | 5 +-
MANIFEST | 64 ++++--
MANIFEST.SKIP | 21 ++
Makefile.PL | 45 ++--
README | 23 +-
lib/{Nagios => Monitoring}/Plugin.pm | 251 +++++++++++----------
lib/{Nagios => Monitoring}/Plugin/Config.pm | 53 +++--
lib/Monitoring/Plugin/ExitResult.pm | 71 ++++++
lib/{Nagios => Monitoring}/Plugin/Functions.pm | 121 +++++-----
lib/{Nagios => Monitoring}/Plugin/Getopt.pm | 138 ++++++-----
lib/{Nagios => Monitoring}/Plugin/Performance.pm | 72 +++---
lib/{Nagios => Monitoring}/Plugin/Range.pm | 32 +--
lib/{Nagios => Monitoring}/Plugin/Threshold.pm | 50 ++--
lib/Nagios/Plugin/ExitResult.pm | 67 ------
t/{Nagios-Plugin-01.t => Monitoring-Plugin-01.t} | 33 ++-
t/Monitoring-Plugin-02.t | 160 +++++++++++++
t/{Nagios-Plugin-03.t => Monitoring-Plugin-03.t} | 53 +++--
t/{Nagios-Plugin-04.t => Monitoring-Plugin-04.t} | 26 +--
t/{Nagios-Plugin-05.t => Monitoring-Plugin-05.t} | 7 +-
t/Monitoring-Plugin-Functions-01.t | 161 +++++++++++++
...tions-02.t => Monitoring-Plugin-Functions-02.t} | 9 +-
...tions-03.t => Monitoring-Plugin-Functions-03.t} | 2 +-
...tions-04.t => Monitoring-Plugin-Functions-04.t} | 2 +-
...n-Getopt-01.t => Monitoring-Plugin-Getopt-01.t} | 17 +-
...n-Getopt-02.t => Monitoring-Plugin-Getopt-02.t} | 15 +-
...n-Getopt-03.t => Monitoring-Plugin-Getopt-03.t} | 29 ++-
...n-Getopt-04.t => Monitoring-Plugin-Getopt-04.t} | 15 +-
t/Monitoring-Plugin-Performance-02.t | 13 ++
...rformance.t => Monitoring-Plugin-Performance.t} | 104 ++++-----
...os-Plugin-Range.t => Monitoring-Plugin-Range.t} | 38 ++--
...n-Threshold.t => Monitoring-Plugin-Threshold.t} | 58 ++---
t/Nagios-Plugin-02.t | 161 -------------
t/Nagios-Plugin-Functions-01.t | 161 -------------
t/Nagios-Plugin-Performance-02.t | 13 --
t/check_stuff.pl | 45 ++--
t/check_stuff.t | 10 +-
t/npg03/README | 16 +-
38 files changed, 1104 insertions(+), 1062 deletions(-)
diff --git a/.gitignore b/.gitignore
index 6cf3bbc..93cc521 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,8 @@
/pm_to_blib
/.bzr
/.bzrignore
+MYMETA.json
+MYMETA.yml
+Makefile.old
+inc/
+MANIFEST.bak
diff --git a/Changes b/Changes
index 2034b6c..b85c2ac 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,7 @@
-Revision history for Perl module Nagios::Plugin.
+Revision history for Perl module Monitoring::Plugin.
+
+0.37 20nd January 2014
+ - renamed module due to trademark issues
0.36 22nd December 2011
- Updated check_threshold to allow multiple check values to be checked at once
diff --git a/MANIFEST b/MANIFEST
index 39be2c5..8ccb51c 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,33 +1,47 @@
Changes
-lib/Nagios/Plugin.pm
-lib/Nagios/Plugin/Config.pm
-lib/Nagios/Plugin/ExitResult.pm
-lib/Nagios/Plugin/Functions.pm
-lib/Nagios/Plugin/Getopt.pm
-lib/Nagios/Plugin/Performance.pm
-lib/Nagios/Plugin/Range.pm
-lib/Nagios/Plugin/Threshold.pm
+inc/Module/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/Monitoring/Plugin.pm
+lib/Monitoring/Plugin/Config.pm
+lib/Monitoring/Plugin/ExitResult.pm
+lib/Monitoring/Plugin/Functions.pm
+lib/Monitoring/Plugin/Getopt.pm
+lib/Monitoring/Plugin/Performance.pm
+lib/Monitoring/Plugin/Range.pm
+lib/Monitoring/Plugin/Threshold.pm
Makefile.PL
MANIFEST This list of files
META.yml
+notes
README
t/check_stuff.pl
t/check_stuff.t
-t/Nagios-Plugin-01.t
-t/Nagios-Plugin-02.t
-t/Nagios-Plugin-03.t
-t/Nagios-Plugin-04.t
-t/Nagios-Plugin-Functions-01.t
-t/Nagios-Plugin-Functions-02.t
-t/Nagios-Plugin-Functions-03.t
-t/Nagios-Plugin-Getopt-01.t
-t/Nagios-Plugin-Getopt-02.t
-t/Nagios-Plugin-Getopt-03.t
-t/Nagios-Plugin-Getopt-04.t
-t/Nagios-Plugin-Performance-02.t
-t/Nagios-Plugin-Performance.t
-t/Nagios-Plugin-Range.t
-t/Nagios-Plugin-Threshold.t
+t/Monitoring-Plugin-01.t
+t/Monitoring-Plugin-02.t
+t/Monitoring-Plugin-03.t
+t/Monitoring-Plugin-04.t
+t/Monitoring-Plugin-05.t
+t/Monitoring-Plugin-Functions-01.t
+t/Monitoring-Plugin-Functions-02.t
+t/Monitoring-Plugin-Functions-03.t
+t/Monitoring-Plugin-Functions-04.t
+t/Monitoring-Plugin-Getopt-01.t
+t/Monitoring-Plugin-Getopt-02.t
+t/Monitoring-Plugin-Getopt-03.t
+t/Monitoring-Plugin-Getopt-04.t
+t/Monitoring-Plugin-Performance-02.t
+t/Monitoring-Plugin-Performance.t
+t/Monitoring-Plugin-Range.t
+t/Monitoring-Plugin-Threshold.t
t/npg03/expected/00_basic
t/npg03/expected/00_noextra
t/npg03/expected/01_override1
@@ -38,8 +52,10 @@ t/npg03/expected/05_disk3
t/npg03/expected/05_disk4
t/npg03/expected/05_disk5
t/npg03/expected/05_disk6
+t/npg03/expected/05_disk7
t/npg03/expected/09_funnystuff
t/npg03/expected/12_nosection_implicit
+t/npg03/expected/15_badsection_catch
t/npg03/input/00_basic
t/npg03/input/00_noextra
t/npg03/input/01_override1
@@ -50,9 +66,11 @@ t/npg03/input/05_disk3
t/npg03/input/05_disk4
t/npg03/input/05_disk5
t/npg03/input/05_disk6
+t/npg03/input/05_disk7
t/npg03/input/09_funnystuff
t/npg03/input/12_nosection_implicit
t/npg03/input/13_nosection_explicit_dies
t/npg03/input/14_badsection_dies
+t/npg03/input/15_badsection_catch
t/npg03/plugins.ini
t/npg03/README
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644
index 0000000..134a92b
--- /dev/null
+++ b/MANIFEST.SKIP
@@ -0,0 +1,21 @@
+.DS_Store
+\.swp
+blib
+tmp
+\.git
+^Makefile$
+Makefile.old
+MANIFEST.bak
+MANIFEST.SKIP
+MYMETA.yml
+MYMETA.json
+pm_to_blib
+.*\.gz
+# does not work for centos without F::C::R installed
+inc/File/Copy/Recursive.pm
+TODO
+build-stamp
+configure-stamp
+nytprof/
+nytprof.out
+.~ko-6.1.3-perllint~
diff --git a/Makefile.PL b/Makefile.PL
index c043edb..d1f0c2a 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,22 +1,23 @@
-use 5.006;
-use ExtUtils::MakeMaker;
-# See lib/ExtUtils/MakeMaker.pm for details of how to influence
-# the contents of the Makefile that is written.
-WriteMakefile(
- NAME => 'Nagios::Plugin',
- VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION
- PREREQ_PM => {
- Params::Validate => 0,
- Class::Accessor => 0,
- Test::More => 0.62,
- Carp => 0,
- Config::Tiny => 0,
- File::Spec => 0,
- File::Basename => 0,
- IO::File => 0,
- Math::Calc::Units => 0, # used in N::P::Performance
- }, # e.g., Module::Name => 1.1
- ($] >= 5.005 ? ## Add these new keywords supported since 5.005
- (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module
- AUTHOR => 'Nagios Plugin Development Team <nagiosplug-devel at lists.sourceforge.net>') : ()),
-);
+use inc::Module::Install;
+
+name 'Monitoring-Plugin';
+all_from 'lib/Monitoring/Plugin/Functions.pm';
+author q{Monitoring Plugin Team <devel at monitoring-plugins.org>};
+license 'perl';
+repository 'https://github.com/monitoring-plugins/monitoring-plugin-perl';
+
+requires 'Params::Validate' => 0;
+requires 'Class::Accessor' => 0;
+requires 'Carp' => 0;
+requires 'Config::Tiny' => 0;
+requires 'File::Spec' => 0;
+requires 'File::Basename' => 0;
+requires 'IO::File' => 0;
+requires 'Math::Calc::Units' => 0; # used in M::P::Performance
+
+
+build_requires 'Test::More' => 0.62;
+
+auto_install;
+
+WriteAll;
diff --git a/README b/README
index 939cc36..b0550d6 100644
--- a/README
+++ b/README
@@ -1,13 +1,12 @@
-Nagios::Plugin
-==============
+Monitoring::Plugin
+==================
-These modules are meant for perl developers of plugins for Nagios
-(http://nagiosplug.sourceforge.net). It is meant to simplify a lot
-of the common functions required to do checking of a particular
-service.
-
-The modules are still in an experimental stage and will be considered
-stable when it reaches version 1.0.
+These modules are meant for perl developers of plugins for Naemon, Nagios,
+Icinga, Shinken and other compatible products. It is meant to
+simplify a lot of the common functions required to do checking of a
+particular service.
+This module is maintained by the Monitoring-Plugins team
+(https:://monitoring-plugins.org)
INSTALLATION
@@ -23,16 +22,14 @@ EXAMPLE SCRIPT
"Enough talk! Show me where to start!"
-See the file 'check_stuff.pl' in the 't' directory for a complete
+See the file 'check_stuff.pl' in the 't' directory for a complete
working example of a plugin script.
COPYRIGHT AND LICENCE
-Copyright (C) 2006 by Nagios Plugin Development Team
+Copyright (C) 2006-2014 by Monitoring Plugin Team
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.4 or,
at your option, any later version of Perl 5 you may have available.
-
-
diff --git a/lib/Nagios/Plugin.pm b/lib/Monitoring/Plugin.pm
similarity index 67%
rename from lib/Nagios/Plugin.pm
rename to lib/Monitoring/Plugin.pm
index d85d35a..f9eb49e 100644
--- a/lib/Nagios/Plugin.pm
+++ b/lib/Monitoring/Plugin.pm
@@ -1,7 +1,7 @@
-package Nagios::Plugin;
+package Monitoring::Plugin;
-use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES);
+use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES);
use Params::Validate qw(:all);
use strict;
@@ -10,10 +10,10 @@ use warnings;
use Carp;
use base qw(Class::Accessor::Fast);
-Nagios::Plugin->mk_accessors(qw(
+Monitoring::Plugin->mk_accessors(qw(
shortname
- perfdata
- messages
+ perfdata
+ messages
opts
threshold
));
@@ -25,8 +25,8 @@ our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT);
# CPAN stupidly won't index this module without a literal $VERSION here,
# so we're forced to duplicate it explicitly
-# Make sure you update $Nagios::Plugin::Functions::VERSION too
-our $VERSION = "0.36";
+# Make sure you update $Monitoring::Plugin::Functions::VERSION too
+our $VERSION = "0.37";
sub new {
my $class = shift;
@@ -46,7 +46,7 @@ sub new {
},
);
- my $shortname = Nagios::Plugin::Functions::get_shortname(\%args);
+ my $shortname = Monitoring::Plugin::Functions::get_shortname(\%args);
delete $args{shortname} if (exists $args{shortname});
my $self = {
shortname => $shortname,
@@ -61,16 +61,16 @@ sub new {
};
bless $self, $class;
if (exists $args{usage}) {
- require Nagios::Plugin::Getopt;
- $self->opts( new Nagios::Plugin::Getopt(%args) );
+ require Monitoring::Plugin::Getopt;
+ $self->opts( new Monitoring::Plugin::Getopt(%args) );
}
return $self;
}
sub add_perfdata {
my ($self, %args) = @_;
- require Nagios::Plugin::Performance;
- my $perf = Nagios::Plugin::Performance->new(%args);
+ require Monitoring::Plugin::Performance;
+ my $perf = Monitoring::Plugin::Performance->new(%args);
push @{$self->perfdata}, $perf;
}
sub all_perfoutput {
@@ -78,33 +78,41 @@ sub all_perfoutput {
return join(" ", map {$_->perfoutput} (@{$self->perfdata}));
}
-sub set_thresholds {
- my $self = shift;
- require Nagios::Plugin::Threshold;
- return $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_));
+sub set_thresholds {
+ my $self = shift;
+ require Monitoring::Plugin::Threshold;
+ return $self->threshold( Monitoring::Plugin::Threshold->set_thresholds(@_));
}
-# NP::Functions wrappers
+# MP::Functions wrappers
+sub plugin_exit {
+ my $self = shift;
+ Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self });
+}
+sub plugin_die {
+ my $self = shift;
+ Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
+}
sub nagios_exit {
my $self = shift;
- Nagios::Plugin::Functions::nagios_exit(@_, { plugin => $self });
+ Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self });
}
sub nagios_die {
my $self = shift;
- Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self });
+ Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
}
sub die {
my $self = shift;
- Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self });
+ Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self });
}
sub max_state {
- Nagios::Plugin::Functions::max_state(@_);
+ Monitoring::Plugin::Functions::max_state(@_);
}
sub max_state_alt {
- Nagios::Plugin::Functions::max_state_alt(@_);
+ Monitoring::Plugin::Functions::max_state_alt(@_);
}
-# top level interface to Nagios::Plugin::Threshold
+# top level interface to Monitoring::Plugin::Threshold
sub check_threshold {
my $self = shift;
@@ -143,11 +151,11 @@ sub check_threshold {
else {
return UNKNOWN;
}
-
+
return $self->threshold->get_status($args{check});
}
-# top level interface to my Nagios::Plugin::Getopt object
+# top level interface to my Monitoring::Plugin::Getopt object
sub add_arg {
my $self = shift;
$self->opts->arg(@_) if $self->_check_for_opts;
@@ -160,15 +168,15 @@ sub getopts {
sub _check_for_opts {
my $self = shift;
croak
- "You have to supply a 'usage' param to Nagios::Plugin::new() if you want to use Getopts from your Nagios::Plugin object."
- unless ref $self->opts() eq 'Nagios::Plugin::Getopt';
+ "You have to supply a 'usage' param to Monitoring::Plugin::new() if you want to use Getopts from your Monitoring::Plugin object."
+ unless ref $self->opts() eq 'Monitoring::Plugin::Getopt';
return $self;
}
# -------------------------------------------------------------------------
-# NP::Functions::check_messages helpers and wrappers
+# MP::Functions::check_messages helpers and wrappers
sub add_message {
my $self = shift;
@@ -179,7 +187,7 @@ sub add_message {
# Store messages using strings rather than numeric codes
$code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code};
- $code = lc $code;
+ $code = lc $code;
croak "Error code '$code' not supported by add_message"
if $code eq 'unknown' || $code eq 'dependent';
@@ -199,7 +207,7 @@ sub check_messages {
if ($code eq 'ok') {
$args{$code} = [ $args{$code} ];
} else {
- croak "Invalid argument '$code'"
+ croak "Invalid argument '$code'"
}
}
push @{$args{$code}}, @$messages;
@@ -209,7 +217,7 @@ sub check_messages {
}
}
- Nagios::Plugin::Functions::check_messages(%args);
+ Monitoring::Plugin::Functions::check_messages(%args);
}
# -------------------------------------------------------------------------
@@ -222,23 +230,23 @@ __END__
=head1 NAME
-Nagios::Plugin - A family of perl modules to streamline writing Nagios
-plugins
+Monitoring::Plugin - A family of perl modules to streamline writing Naemon, Nagios,
+Icinga or Shinken (and compatible) plugins.
=head1 SYNOPSIS
# Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default
- # See also Nagios::Plugin::Functions for a functional interface
- use Nagios::Plugin;
+ # See also Monitoring::Plugin::Functions for a functional interface
+ use Monitoring::Plugin;
# Constructor
- $np = Nagios::Plugin->new; # OR
- $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); # OR
+ $np = Monitoring::Plugin->new; # OR
+ $np = Monitoring::Plugin->new( shortname => "PAGESIZE" ); # OR
- # use Nagios::Plugin::Getopt to process the @ARGV command line options:
+ # use Monitoring::Plugin::Getopt to process the @ARGV command line options:
# --verbose, --help, --usage, --timeout and --host are defined automatically.
- $np = Nagios::Plugin->new(
+ $np = Monitoring::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] "
. "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
);
@@ -247,7 +255,7 @@ plugins
$np->add_arg(
spec => 'warning|w=s',
help => '-w, --warning=INTEGER:INTEGER . See '
- . 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT '
+ . 'https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT '
. 'for the threshold format. ',
);
@@ -255,29 +263,29 @@ plugins
$np->getopts;
- # Exit/return value methods - nagios_exit( CODE, MESSAGE ),
- # nagios_die( MESSAGE, [CODE])
+ # Exit/return value methods - plugin_exit( CODE, MESSAGE ),
+ # plugin_die( MESSAGE, [CODE])
$page = retrieve_page($page1)
- or $np->nagios_exit( UNKNOWN, "Could not retrieve page" );
- # Return code: 3;
- # output: PAGESIZE UNKNOWN - Could not retrieve page
+ or $np->plugin_exit( UNKNOWN, "Could not retrieve page" );
+ # Return code: 3;
+ # output: PAGESIZE UNKNOWN - Could not retrieve page
test_page($page)
- or $np->nagios_exit( CRITICAL, "Bad page found" );
+ or $np->plugin_exit( CRITICAL, "Bad page found" );
- # nagios_die() is just like nagios_exit(), but return code defaults
+ # plugin_die() is just like plugin_exit(), but return code defaults
# to UNKNOWN
$page = retrieve_page($page2)
- or $np->nagios_die( "Could not retrieve page" );
- # Return code: 3;
+ or $np->plugin_die( "Could not retrieve page" );
+ # Return code: 3;
# output: PAGESIZE UNKNOWN - Could not retrieve page
- # Threshold methods
+ # Threshold methods
$code = $np->check_threshold(
check => $value,
warning => $warning_threshold,
critical => $critical_threshold,
);
- $np->nagios_exit( $code, "Threshold check failed" ) if $code != OK;
+ $np->plugin_exit( $code, "Threshold check failed" ) if $code != OK;
# Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) -
@@ -290,38 +298,38 @@ plugins
}
}
($code, $message) = $np->check_messages();
- nagios_exit( $code, $message );
- # If any items in collection matched m/Error/, returns CRITICAL and
- # the joined set of Error messages; otherwise returns OK and the
+ plugin_exit( $code, $message );
+ # If any items in collection matched m/Error/, returns CRITICAL and
+ # the joined set of Error messages; otherwise returns OK and the
# joined set of ok messages
# Perfdata methods
- $np->add_perfdata(
+ $np->add_perfdata(
label => "size",
value => $value,
uom => "kB",
threshold => $threshold,
);
$np->add_perfdata( label => "time", ... );
- $np->nagios_exit( OK, "page size at http://... was ${value}kB" );
- # Return code: 0;
+ $np->plugin_exit( OK, "page size at http://... was ${value}kB" );
+ # Return code: 0;
# output: PAGESIZE OK - page size at http://... was 36kB \
# | size=36kB;10:25;25: time=...
=head1 DESCRIPTION
-Nagios::Plugin and its associated Nagios::Plugin::* modules are a
-family of perl modules to streamline writing Nagios plugins. The main
-end user modules are Nagios::Plugin, providing an object-oriented
-interface to the entire Nagios::Plugin::* collection, and
-Nagios::Plugin::Functions, providing a simpler functional interface to
+Monitoring::Plugin and its associated Monitoring::Plugin::* modules are a
+family of perl modules to streamline writing Monitoring plugins. The main
+end user modules are Monitoring::Plugin, providing an object-oriented
+interface to the entire Monitoring::Plugin::* collection, and
+Monitoring::Plugin::Functions, providing a simpler functional interface to
a useful subset of the available functionality.
The purpose of the collection is to make it as simple as possible for
-developers to create plugins that conform the Nagios Plugin guidelines
-(http://nagiosplug.sourceforge.net/developer-guidelines.html).
+developers to create plugins that conform the Monitoring Plugin guidelines
+(https://www.monitoring-plugins.org/doc/guidelines.html).
=head2 EXPORTS
@@ -346,7 +354,7 @@ corresponding status code.
=item %STATUS_TEXT
A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the
-corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the
+corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the
reverse of %ERRORS.
=back
@@ -354,11 +362,11 @@ reverse of %ERRORS.
=head2 CONSTRUCTOR
- Nagios::Plugin->new;
+ Monitoring::Plugin->new;
- Nagios::Plugin->new( shortname => 'PAGESIZE' );
+ Monitoring::Plugin->new( shortname => 'PAGESIZE' );
- Nagios::Plugin->new(
+ Monitoring::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>]
[ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ",
version => $VERSION,
@@ -370,7 +378,7 @@ reverse of %ERRORS.
timeout => 15,
);
-Instantiates a new Nagios::Plugin object. Accepts the following named
+Instantiates a new Monitoring::Plugin object. Accepts the following named
arguments:
=over 4
@@ -382,10 +390,10 @@ output by the various exit methods. Default: uc basename $0.
=item usage ("Usage: %s --foo --bar")
-Passing a value for the usage() argument makes Nagios::Plugin
-instantiate its own C<Nagios::Plugin::Getopt> object so you can start
+Passing a value for the usage() argument makes Monitoring::Plugin
+instantiate its own C<Monitoring::Plugin::Getopt> object so you can start
doing command line argument processing. See
-L<Nagios::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the
+L<Monitoring::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the
following options:
=item version
@@ -406,7 +414,7 @@ following options:
=head2 OPTION HANDLING METHODS
-C<Nagios::Plugin> provides these methods for accessing the functionality in C<Nagios::Plugin::Getopt>.
+C<Monitoring::Plugin> provides these methods for accessing the functionality in C<Monitoring::Plugin::Getopt>.
=over 4
@@ -416,7 +424,7 @@ Examples:
# Define --hello argument (named parameters)
$plugin->add_arg(
- spec => 'hello=s',
+ spec => 'hello=s',
help => "--hello\n Hello string",
required => 1,
);
@@ -425,19 +433,19 @@ Examples:
# Parameter order is 'spec', 'help', 'default', 'required?'
$plugin->add_arg('hello=s', "--hello\n Hello string", undef, 1);
-See L<Nagios::Plugin::Getopt/ARGUMENTS> for more details.
+See L<Monitoring::Plugin::Getopt/ARGUMENTS> for more details.
=item getopts()
Parses and processes the command line options you've defined,
automatically doing the right thing with help/usage/version arguments.
-See L<Nagios::Plugin::Getopt/GETOPTS> for more details.
+See L<Monitoring::Plugin::Getopt/GETOPTS> for more details.
=item opts()
Assuming you've instantiated it by passing 'usage' to new(), opts()
-returns the Nagios::Plugin object's C<Nagios::Plugin::Getopt> object,
+returns the Monitoring::Plugin object's C<Monitoring::Plugin::Getopt> object,
with which you can do lots of great things.
E.g.
@@ -456,7 +464,7 @@ E.g.
# $plugin->getopts;
print $plugin->opts->my_argument;
-Again, see L<Nagios::Plugin::Getopt>.
+Again, see L<Monitoring::Plugin::Getopt>.
=back
@@ -464,33 +472,41 @@ Again, see L<Nagios::Plugin::Getopt>.
=over 4
-=item nagios_exit( <CODE>, $message )
+=item plugin_exit( <CODE>, $message )
Exit with return code CODE, and a standard nagios message of the
form "SHORTNAME CODE - $message".
-=item nagios_die( $message, [<CODE>] )
+=item plugin_die( $message, [<CODE>] )
-Same as nagios_exit(), except that CODE is optional, defaulting
+Same as plugin_exit(), except that CODE is optional, defaulting
to UNKNOWN. NOTE: exceptions are not raised by default to calling code.
Set C<$_use_die> flag if this functionality is required (see test code).
+=item nagios_exit( <CODE>, $message )
+
+Alias for plugin_die(). Deprecated.
+
+=item nagios_die( $message, [<CODE>] )
+
+Alias for plugin_die(). Deprecated.
+
=item die( $message, [<CODE>] )
-Alias for nagios_die(). Deprecated.
+Alias for plugin_die(). Deprecated.
=item max_state, max_state_alt
-These are wrapper function for Nagios::Plugin::Functions::max_state and
-Nagios::Plugin::Functions::max_state_alt.
+These are wrapper function for Monitoring::Plugin::Functions::max_state and
+Monitoring::Plugin::Functions::max_state_alt.
=back
=head2 THRESHOLD METHODS
These provide a top level interface to the
-C<Nagios::Plugin::Threshold> module; for more details, see
-L<Nagios::Plugin::Threshold> and L<Nagios::Plugin::Range>.
+C<Monitoring::Plugin::Threshold> module; for more details, see
+L<Monitoring::Plugin::Threshold> and L<Monitoring::Plugin::Range>.
=over 4
@@ -512,9 +528,9 @@ WARNING constant. The thresholds may be:
You can specify $value as an array of values and each will be checked against
the thresholds.
-The return value is ready to pass to C <nagios_exit>, e . g .,
+The return value is ready to pass to C <plugin_exit>, e . g .,
- $p->nagios_exit(
+ $p->plugin_exit(
return_code => $p->check_threshold($result),
message => " sample result was $result"
);
@@ -523,13 +539,13 @@ The return value is ready to pass to C <nagios_exit>, e . g .,
=item set_thresholds(warning => "10:25", critical => "~:25")
Sets the acceptable ranges and creates the plugin's
-Nagios::Plugins::Threshold object. See
-http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT
+Monitoring::Plugins::Threshold object. See
+https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
for details and examples of the threshold format.
=item threshold()
-Returns the object's C<Nagios::Plugin::Threshold> object, if it has
+Returns the object's C<Monitoring::Plugin::Threshold> object, if it has
been defined by calling set_thresholds(). You can pass a new
Threshold object to it to replace the old one too, but you shouldn't
need to do that from a plugin script.
@@ -543,17 +559,17 @@ EXPERIMENTAL AND SUBJECT TO CHANGE
add_messages and check_messages are higher-level convenience methods to add
and then check a set of messages, returning an appropriate return code
and/or result message. They are equivalent to maintaining a set of @critical,
- at warning, and and @ok message arrays (add_message), and then doing a final
+ at warning, and and @ok message arrays (add_message), and then doing a final
if test (check_messages) like this:
if (@critical) {
- nagios_exit( CRITICAL, join(' ', @critical) );
- }
+ plugin_exit( CRITICAL, join(' ', @critical) );
+ }
elsif (@warning) {
- nagios_exit( WARNING, join(' ', @warning) );
+ plugin_exit( WARNING, join(' ', @warning) );
}
else {
- nagios_exit( OK, join(' ', @ok) );
+ plugin_exit( OK, join(' ', @ok) );
}
=over 4
@@ -571,7 +587,7 @@ Only CRITICAL, WARNING, and OK are accepted as valid codes.
Check the current set of messages and return an appropriate nagios return
code and/or a result message. In scalar context, returns only a return
code; in list context returns both a return code and an output message,
-suitable for passing directly to nagios_exit() e.g.
+suitable for passing directly to plugin_exit() e.g.
$code = $np->check_messages;
($code, $message) = $np->check_messages;
@@ -587,7 +603,7 @@ check_messages accepts the following named arguments (none are required):
=item join => SCALAR
-A string used to join the relevant array to generate the message
+A string used to join the relevant array to generate the message
string returned in list context i.e. if the 'critical' array @crit
is non-empty, check_messages would return:
@@ -599,9 +615,9 @@ as the result message. Default: ' ' (space).
By default, only one set of messages are joined and returned in the
result message i.e. if the result is CRITICAL, only the 'critical'
-messages are included in the result; if WARNING, only the 'warning'
+messages are included in the result; if WARNING, only the 'warning'
messages are included; if OK, the 'ok' messages are included (if
-supplied) i.e. the default is to return an 'errors-only' type
+supplied) i.e. the default is to return an 'errors-only' type
message.
If 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.
The performance data is included in the standard plugin output messages by
the various exit methods.
-See the Nagios::Plugin::Performance documentation for more information on
+See the Monitoring::Plugin::Performance documentation for more information on
performance data and the various field definitions, as well as the relevant
-section of the Nagios Plugin guidelines
-(http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202).
+section of the Monitoring Plugin guidelines
+(https://www.monitoring-plugins.org/doc/guidelines.html#AEN202).
=back
@@ -648,50 +664,49 @@ section of the Nagios Plugin guidelines
"Enough talk! Show me some examples!"
See the file 'check_stuff.pl' in the 't' directory included with the
-Nagios::Plugin distribution for a complete working example of a plugin
+Monitoring::Plugin distribution for a complete working example of a plugin
script.
=head1 VERSIONING
-The Nagios::Plugin::* modules are currently experimental and so the
-interfaces may change up until Nagios::Plugin hits version 1.0, although
+The Monitoring::Plugin::* modules are currently experimental and so the
+interfaces may change up until Monitoring::Plugin hits version 1.0, although
every attempt will be made to keep them as backwards compatible as
possible.
=head1 SEE ALSO
-See L<Nagios::Plugin::Functions> for a simple functional interface to a subset
-of the available Nagios::Plugin functionality.
+See L<Monitoring::Plugin::Functions> for a simple functional interface to a subset
+of the available Monitoring::Plugin functionality.
-See also L<Nagios::Plugin::Getopt>, L<Nagios::Plugin::Range>,
-L<Nagios::Plugin::Performance>, L<Nagios::Plugin::Range>, and
-L<Nagios::Plugin::Threshold>.
+See also L<Monitoring::Plugin::Getopt>, L<Monitoring::Plugin::Range>,
+L<Monitoring::Plugin::Performance>, L<Monitoring::Plugin::Range>, and
+L<Monitoring::Plugin::Threshold>.
-The Nagios Plugin project page is at http://nagiosplug.sourceforge.net.
+The Monitoring Plugin project page is at http://monitoring-plugins.org.
=head1 BUGS
-Please report bugs in these modules to the Nagios Plugin development team:
-nagiosplug-devel at lists.sourceforge.net.
+Please report bugs in these modules to the Monitoring Plugin development team:
+devel at monitoring-plugins.org.
=head1 AUTHOR
-Maintained by the Nagios Plugin development team -
-http://nagiosplug.sourceforge.net.
+Maintained by the Monitoring Plugin development team -
+https://www.monitoring-plugins.org.
Originally by Ton Voon, E<lt>ton.voon at altinity.comE<gt>.
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006 by Nagios Plugin Development Team
+Copyright (C) 2006-2014 by Monitoring Plugin Team
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.4 or, at your
option, any later version of Perl 5 you may have available.
=cut
-
diff --git a/lib/Nagios/Plugin/Config.pm b/lib/Monitoring/Plugin/Config.pm
similarity index 71%
rename from lib/Nagios/Plugin/Config.pm
rename to 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 @@
-package Nagios::Plugin::Config;
+package Monitoring::Plugin::Config;
use strict;
use Carp;
@@ -7,10 +7,11 @@ use base qw(Config::Tiny);
my $FILENAME1 = 'plugins.ini';
my $FILENAME2 = 'nagios-plugins.ini';
+my $FILENAME3 = 'monitoring-plugins.ini';
my $CURRENT_FILE = undef;
# Config paths ending in nagios (search for $FILENAME1)
-my @NAGIOS_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios);
+my @MONITORING_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios);
# Config paths not ending in nagios (search for $FILENAME2)
my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt);
@@ -21,26 +22,30 @@ sub read
unless ($_[0]) {
SEARCH: {
- if ($ENV{NAGIOS_CONFIG_PATH}) {
- for (split /:/, $ENV{NAGIOS_CONFIG_PATH}) {
+ if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) {
+ for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) {
my $file = File::Spec->catfile($_, $FILENAME1);
unshift(@_, $file), last SEARCH if -f $file;
$file = File::Spec->catfile($_, $FILENAME2);
unshift(@_, $file), last SEARCH if -f $file;
+ $file = File::Spec->catfile($_, $FILENAME3);
+ unshift(@_, $file), last SEARCH if -f $file;
}
}
- for (@NAGIOS_CONFIG_PATH) {
+ for (@MONITORING_CONFIG_PATH) {
my $file = File::Spec->catfile($_, $FILENAME1);
unshift(@_, $file), last SEARCH if -f $file;
}
for (@CONFIG_PATH) {
my $file = File::Spec->catfile($_, $FILENAME2);
unshift(@_, $file), last SEARCH if -f $file;
+ $file = File::Spec->catfile($_, $FILENAME3);
+ unshift(@_, $file), last SEARCH if -f $file;
}
}
# Use die instead of croak, so we can pass a clean message downstream
- die "Cannot find '$FILENAME1' or '$FILENAME2' in any standard location.\n" unless $_[0];
+ die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0];
}
$CURRENT_FILE = $_[0];
@@ -94,15 +99,15 @@ sub np_getfile { return $CURRENT_FILE; }
=head1 NAME
-Nagios::Plugin::Config - read nagios plugin .ini style config files
+Monitoring::Plugin::Config - read nagios plugin .ini style config files
=head1 SYNOPSIS
# Read given nagios plugin config file
- $Config = Nagios::Plugin::Config->read( '/etc/nagios/plugins.ini' );
+ $Config = Monitoring::Plugin::Config->read( '/etc/nagios/plugins.ini' );
# Search for and read default nagios plugin config file
- $Config = Nagios::Plugin::Config->read();
+ $Config = Monitoring::Plugin::Config->read();
# Access sections and properties (returns scalars or arrayrefs)
$rootproperty = $Config->{_}->{rootproperty};
@@ -111,22 +116,22 @@ Nagios::Plugin::Config - read nagios plugin .ini style config files
=head1 DESCRIPTION
-Nagios::Plugin::Config is a subclass of the excellent Config::Tiny,
+Monitoring::Plugin::Config is a subclass of the excellent Config::Tiny,
with the following changes:
=over 4
-=item
+=item
Repeated keys are allowed within sections, returning lists instead of scalars
-=item
+=item
Write functionality has been removed i.e. access is read only
-=item
+=item
-Nagios::Plugin::Config searches for a default nagios plugins file if no explicit
+Monitoring::Plugin::Config searches for a default nagios plugins file if no explicit
filename is given to C<read()>. The current standard locations checked are:
=over 4
@@ -137,15 +142,15 @@ filename is given to C<read()>. The current standard locations checked are:
=item /usr/local/etc/nagios /etc/opt/nagios/plugins.ini
-=item /etc/nagios-plugins.ini
+=item /etc/nagios-plugins.ini
-=item /usr/local/etc/nagios-plugins.ini
+=item /usr/local/etc/nagios-plugins.ini
=item /etc/opt/nagios-plugins.ini
=back
-To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable
+To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable
to the set of directories that should be checked. The first C<plugins.ini> or
C<nagios-plugins.ini> file found will be used.
@@ -154,21 +159,19 @@ C<nagios-plugins.ini> file found will be used.
=head1 SEE ALSO
-L<Config::Tiny>, L<Nagios::Plugin>
+L<Config::Tiny>, L<Monitoring::Plugin>
-=head1 AUTHORS
+=head1 AUTHOR
-This code is maintained by the Nagios Plugin Development Team:
-L<http://nagiosplug.sourceforge.net>.
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
+=head1 COPYRIGHT AND LICENSE
-=head1 COPYRIGHT and LICENCE
-
-Copyright (C) 2006-2007 by Nagios Plugin Development Team
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
-
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 @@
+# Tiny helper class to return both output and return_code when testing
+
+package Monitoring::Plugin::ExitResult;
+
+use strict;
+
+# Stringify to message
+use overload '""' => sub { shift->{message} };
+
+# Constructor
+sub new {
+ my $class = shift;
+ return bless { return_code => $_[0], message => $_[1] }, $class;
+}
+
+# Accessors
+sub message { shift->{message} }
+sub return_code { shift->{return_code} }
+sub code { shift->{return_code} }
+
+1;
+
+__END__
+
+=head1 NAME
+
+Monitoring::Plugin::ExitResult - Helper class for returning both output and
+return codes when testing.
+
+=head1 SYNOPSIS
+
+ use Test::More;
+ use Monitoring::Plugin::Functions;
+
+ # In a test file somewhere
+ Monitoring::Plugin::Functions::_fake_exit(1);
+
+ # Later ...
+ $e = plugin_exit( CRITICAL, 'aiiii ...' );
+ print $e->message;
+ print $e->return_code;
+
+ # MP::ExitResult also stringifies to the message output
+ like(plugin_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');
+
+
+
+=head1 DESCRIPTION
+
+Monitoring::Plugin::ExitResult is a tiny helper class intended for use
+when testing other Monitoring::Plugin modules. A Monitoring::Plugin::ExitResult
+object is returned by plugin_exit() and friends when
+Monitoring::Plugin::Functions::_fake_exit has been set, instead of doing a
+conventional print + exit.
+
+=head1 AUTHOR
+
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
+
+Originally:
+ Gavin Carr , E<lt>gavin at openfusion.com.auE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm
similarity index 79%
rename from lib/Nagios/Plugin/Functions.pm
rename to 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 @@
-# Functional interface to basic Nagios::Plugin constants, exports,
+# Functional interface to basic Monitoring::Plugin constants, exports,
# and functions
-package Nagios::Plugin::Functions;
+package Monitoring::Plugin::Functions;
use 5.006;
@@ -11,19 +11,19 @@ use File::Basename;
use Params::Validate qw(:types validate);
use Math::Calc::Units;
-# Remember to update Nagios::Plugins as well
-our $VERSION = "0.36";
+# Remember to update Monitoring::Plugins as well
+our $VERSION = "0.37";
our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
require Exporter;
our @ISA = qw(Exporter);
-our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages));
+our @EXPORT = (@STATUS_CODES, qw(plugin_exit plugin_die check_messages));
our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re);
our %EXPORT_TAGS = (
all => [ @EXPORT, @EXPORT_OK ],
codes => [ @STATUS_CODES ],
- functions => [ qw(nagios_exit nagios_die check_messages max_state max_state_alt convert) ],
+ functions => [ qw(plugin_exit plugin_die check_messages max_state max_state_alt convert) ],
);
use constant OK => 0;
@@ -61,7 +61,7 @@ sub get_shortname {
return $arg->{shortname} if (defined($arg->{shortname}));
$shortname = $arg->{plugin} if (defined( $arg->{plugin}));
- $shortname = uc basename($shortname || $ENV{NAGIOS_PLUGIN} || $0);
+ $shortname = uc basename($shortname || $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0);
$shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_]
$shortname =~ s/\..*$//; # Remove any trailing suffix
return $shortname;
@@ -85,8 +85,8 @@ sub max_state_alt {
return UNKNOWN;
}
-# nagios_exit( $code, $message )
-sub nagios_exit {
+# plugin_exit( $code, $message )
+sub plugin_exit {
my ($code, $message, $arg) = @_;
# Handle named parameters
@@ -124,21 +124,21 @@ sub nagios_exit {
$output = "$shortname $output" if $shortname;
if ($arg->{plugin}) {
my $plugin = $arg->{plugin};
- $output .= " | ". $plugin->all_perfoutput
+ $output .= " | ". $plugin->all_perfoutput
if $plugin->perfdata && $plugin->all_perfoutput;
}
$output .= "\n";
# Don't actually exit if _fake_exit set
if ($_fake_exit) {
- require Nagios::Plugin::ExitResult;
- return Nagios::Plugin::ExitResult->new($code, $output);
+ require Monitoring::Plugin::ExitResult;
+ return Monitoring::Plugin::ExitResult->new($code, $output);
}
- _nagios_exit($code, $output);
+ _plugin_exit($code, $output);
}
-sub _nagios_exit {
+sub _plugin_exit {
my ($code, $output) = @_;
# Print output and exit; die if flag set and called via a die in stack backtrace
if ($_use_die) {
@@ -155,34 +155,34 @@ sub _nagios_exit {
exit $code;
}
-# nagios_die( $message, [ $code ]) OR nagios_die( $code, $message )
+# plugin_die( $message, [ $code ]) OR plugin_die( $code, $message )
# Default $code: UNKNOWN
-sub nagios_die {
+sub plugin_die {
my ($arg1, $arg2, $rest) = @_;
# Named parameters
if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) {
- return nagios_exit(@_);
+ return plugin_exit(@_);
}
# ($code, $message)
elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) {
- return nagios_exit(@_);
+ return plugin_exit(@_);
}
# ($message, $code)
elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) {
- return nagios_exit($arg2, $arg1, $rest);
+ return plugin_exit($arg2, $arg1, $rest);
}
# Else just assume $arg1 is the message and hope for the best
else {
- return nagios_exit( UNKNOWN, $arg1, $arg2 );
+ return plugin_exit( UNKNOWN, $arg1, $arg2 );
}
}
# For backwards compatibility
-sub die { nagios_die(@_); }
+sub die { plugin_die(@_); }
# ------------------------------------------------------------------------
@@ -197,9 +197,9 @@ sub convert
}
# ------------------------------------------------------------------------
-# check_messages - return a status and/or message based on a set of
+# check_messages - return a status and/or message based on a set of
# message arrays.
-# Returns a nagios status code in scalar context.
+# Returns a nagios status code in scalar context.
# Returns a code and a message in list context.
# The message is join($join, @array) for the relevant array for the code,
# or join($join_all, $message) for all arrays if $join_all is set.
@@ -222,18 +222,18 @@ sub check_messages {
# Compose message
my $message = '';
if ($arg{join_all}) {
- $message = join( $arg{join_all},
+ $message = join( $arg{join_all},
map { @$_ ? join( $arg{'join'}, @$_) : () }
- $arg{critical},
+ $arg{critical},
$arg{warning},
$arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : []
);
}
else {
- $message ||= join( $arg{'join'}, @{$arg{critical}} )
+ $message ||= join( $arg{'join'}, @{$arg{critical}} )
if $code == CRITICAL;
- $message ||= join( $arg{'join'}, @{$arg{warning}} )
+ $message ||= join( $arg{'join'}, @{$arg{warning}} )
if $code == WARNING;
$message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok}
if $arg{ok};
@@ -252,28 +252,28 @@ __END__
=head1 NAME
-Nagios::Plugin::Functions - functions to simplify the creation of
+Monitoring::Plugin::Functions - functions to simplify the creation of
Nagios plugins
=head1 SYNOPSIS
# Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default
- use Nagios::Plugin::Functions;
+ use Monitoring::Plugin::Functions;
- # nagios_exit( CODE, $message ) - exit with error code CODE,
+ # plugin_exit( CODE, $message ) - exit with error code CODE,
# and message "PLUGIN CODE - $message"
- nagios_exit( CRITICAL, $critical_error ) if $critical_error;
- nagios_exit( WARNING, $warning_error ) if $warning_error;
- nagios_exit( OK, $result );
+ plugin_exit( CRITICAL, $critical_error ) if $critical_error;
+ plugin_exit( WARNING, $warning_error ) if $warning_error;
+ plugin_exit( OK, $result );
- # nagios_die( $message, [$CODE] ) - just like nagios_exit(),
+ # plugin_die( $message, [$CODE] ) - just like plugin_exit(),
# but CODE is optional, defaulting to UNKNOWN
do_something()
- or nagios_die("do_something() failed horribly");
+ or plugin_die("do_something() failed horribly");
do_something_critical()
- or nagios_die("do_something_critical() failed", CRITICAL);
+ or plugin_die("do_something_critical() failed", CRITICAL);
- # check_messages - check a set of message arrays, returning a
+ # check_messages - check a set of message arrays, returning a
# CODE and/or a result message
$code = check_messages(critical => \@crit, warning => \@warn);
($code, $message) = check_messages(
@@ -281,18 +281,18 @@ Nagios plugins
ok => \@ok );
# get_shortname - return the default short name for this plugin
- # (as used by nagios_exit/die; not exported by default)
+ # (as used by plugin_exit/die; not exported by default)
$shortname = get_shortname();
=head1 DESCRIPTION
-This module is part of the Nagios::Plugin family, a set of modules
+This module is part of the Monitoring::Plugin family, a set of modules
for simplifying the creation of Nagios plugins. This module exports
-convenience functions for the class methods provided by
-Nagios::Plugin. It is intended for those who prefer a simpler
-functional interface, and who do not need the additional
-functionality of Nagios::Plugin.
+convenience functions for the class methods provided by
+Monitoring::Plugin. It is intended for those who prefer a simpler
+functional interface, and who do not need the additional
+functionality of Monitoring::Plugin.
=head2 EXPORTS
@@ -306,8 +306,8 @@ Nagios status code constants are exported by default:
as are the following functions:
- nagios_exit
- nagios_die
+ plugin_exit
+ plugin_die
check_messages
The following variables and functions are exported only on request:
@@ -325,14 +325,14 @@ The following functions are supported:
=over 4
-=item nagios_exit( <CODE>, $message )
+=item plugin_exit( <CODE>, $message )
Exit with return code CODE, and a standard nagios message of the
form "PLUGIN CODE - $message".
-=item nagios_die( $message, [CODE] )
+=item plugin_die( $message, [CODE] )
-Same as nagios_exit(), except that CODE is optional, defaulting
+Same as plugin_exit(), except that CODE is optional, defaulting
to UNKNOWN. NOTE: exceptions are not raised by default to calling code.
Set C<$_use_die> flag if this functionality is required (see test code).
@@ -354,7 +354,7 @@ check_messages() accepts the following named arguments:
=item critical => ARRAYREF
-An arrayref of critical error messages - check_messages() returns
+An arrayref of critical error messages - check_messages() returns
CRITICAL if this arrayref is non-empty. Mandatory.
=item warning => ARRAYREF
@@ -371,7 +371,7 @@ are empty. Optional.
=item join => SCALAR
-A string used to join the relevant array to generate the message
+A string used to join the relevant array to generate the message
string returned in list context i.e. if the 'critical' array @crit
is non-empty, check_messages would return:
@@ -383,9 +383,9 @@ as the result message. Optional; default: ' ' (space).
By default, only one set of messages are joined and returned in the
result message i.e. if the result is CRITICAL, only the 'critical'
-messages are included in the result; if WARNING, only the 'warning'
+messages are included in the result; if WARNING, only the 'warning'
messages are included; if OK, the 'ok' messages are included (if
-supplied) i.e. the default is to return an 'errors-only' type
+supplied) i.e. the default is to return an 'errors-only' type
message.
If join_all is supplied, however, it will be used as a string to
@@ -397,9 +397,9 @@ all messages are joined and returned.
=item get_shortname
Return the default shortname used for this plugin i.e. the first
-token reported by nagios_exit/nagios_die. The default is basically
+token reported by plugin_exit/plugin_die. The default is basically
- uc basename( $ENV{NAGIOS_PLUGIN} || $0 )
+ uc basename( $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0 )
with any leading 'CHECK_' and trailing file suffixes removed.
@@ -427,18 +427,17 @@ internal tests performed can return UNKNOWN.
=head1 SEE ALSO
-Nagios::Plugin; the nagios plugin developer guidelines at
-http://nagiosplug.sourceforge.net/developer-guidelines.html.
+Monitoring::Plugin; the nagios plugin developer guidelines at
+https://www.monitoring-plugins.org/doc/guidelines.html.
+=head1 AUTHOR
-=head1 AUTHORS
-
-This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net
-
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006 by Nagios Plugin Development Team
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
similarity index 91%
rename from lib/Nagios/Plugin/Getopt.pm
rename to 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 @@
#
-# Nagios::Plugin::Getopt - OO perl module providing standardised argument
+# Monitoring::Plugin::Getopt - OO perl module providing standardised argument
# processing for nagios plugins
#
-package Nagios::Plugin::Getopt;
+package Monitoring::Plugin::Getopt;
use strict;
use File::Basename;
@@ -12,18 +12,18 @@ use Carp;
use Params::Validate qw(:all);
use base qw(Class::Accessor);
-use Nagios::Plugin::Functions;
-use Nagios::Plugin::Config;
+use Monitoring::Plugin::Functions;
+use Monitoring::Plugin::Config;
use vars qw($VERSION);
-$VERSION = $Nagios::Plugin::Functions::VERSION;
+$VERSION = $Monitoring::Plugin::Functions::VERSION;
# Standard defaults
my %DEFAULT = (
timeout => 15,
verbose => 0,
license =>
-"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
-It may be used, redistributed and/or modified under the terms of the GNU
+"This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
+It may be used, redistributed and/or modified under the terms of the GNU
General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).",
);
# Standard arguments
@@ -60,7 +60,7 @@ sub _die
my $self = shift;
my ($msg) = @_;
$msg .= "\n" unless substr($msg, -1) eq "\n";
- Nagios::Plugin::Functions::_nagios_exit(3, $msg);
+ Monitoring::Plugin::Functions::_plugin_exit(3, $msg);
}
# Return the given attribute, if set, including a final newline
@@ -182,7 +182,7 @@ sub _help
}
# Return a Getopt::Long-compatible option array from the current set of specs
-sub _process_specs_getopt_long
+sub _process_specs_getopt_long
{
my $self = shift;
@@ -217,7 +217,7 @@ sub _check_required_opts
}
}
if (@missing) {
- $self->_die($self->_usage . "\n" .
+ $self->_die($self->_usage . "\n" .
join("\n", map { sprintf "Missing argument: %s", $_ } @missing) . "\n");
}
}
@@ -243,7 +243,7 @@ sub _load_config_section
$section ||= $self->{_attr}->{plugin};
my $Config;
- eval { $Config = Nagios::Plugin::Config->read($file); };
+ eval { $Config = Monitoring::Plugin::Config->read($file); };
$self->_die($@) if ($@); #TODO: add test?
# TODO: is this check sane? Does --extra-opts=foo require a [foo] section?
@@ -295,7 +295,7 @@ sub _cmdline
next if $key =~ m/^_/;
# Skip defaults and internals
- next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key};
+ next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key};
next if grep { $key eq $_ } qw(help usage version extra-opts);
next unless defined $hash->{$key};
@@ -307,7 +307,7 @@ sub _cmdline
$value = $self->_cmdline_value($value);
if (length($key) > 1) {
push @args, sprintf "--%s=%s", $key, $value;
- }
+ }
else {
push @args, "-$key", $value;
}
@@ -445,7 +445,7 @@ sub _init
my $self = shift;
# Check params
- my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0);
+ my $plugin = basename($ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0);
my %attr = validate( @_, {
usage => 1,
version => 0,
@@ -470,7 +470,7 @@ sub _init
$self
}
-sub new
+sub new
{
my $class = shift;
my $self = bless {}, $class;
@@ -485,20 +485,20 @@ __END__
=head1 NAME
-Nagios::Plugin::Getopt - OO perl module providing standardised argument
+Monitoring::Plugin::Getopt - OO perl module providing standardised argument
processing for Nagios plugins
=head1 SYNOPSIS
- use Nagios::Plugin::Getopt;
+ use Monitoring::Plugin::Getopt;
# Instantiate object (usage is mandatory)
- $ng = Nagios::Plugin::Getopt->new(
+ $ng = Monitoring::Plugin::Getopt->new(
usage => "Usage: %s -H <host> -w <warning> -c <critical>",
version => '0.1',
url => 'http://www.openfusion.com.au/labs/nagios/',
- blurb => 'This plugin tests various stuff.',
+ blurb => 'This plugin tests various stuff.',
);
# Add argument - named parameters (spec and help are mandatory)
@@ -509,7 +509,7 @@ processing for Nagios plugins
default => 10,
);
- # Add argument - positional parameters - arg spec, help text,
+ # Add argument - positional parameters - arg spec, help text,
# default value, required? (first two mandatory)
$ng->arg(
'warning|w=i',
@@ -528,23 +528,23 @@ processing for Nagios plugins
=head1 DESCRIPTION
-Nagios::Plugin::Getopt is an OO perl module providing standardised and
-simplified argument processing for Nagios plugins. It implements
-a number of standard arguments itself (--help, --version,
---usage, --timeout, --verbose, and their short form counterparts),
-produces standardised nagios plugin help output, and allows
+Monitoring::Plugin::Getopt is an OO perl module providing standardised and
+simplified argument processing for Nagios plugins. It implements
+a number of standard arguments itself (--help, --version,
+--usage, --timeout, --verbose, and their short form counterparts),
+produces standardised nagios plugin help output, and allows
additional arguments to be easily defined.
=head2 CONSTRUCTOR
# Instantiate object (usage is mandatory)
- $ng = Nagios::Plugin::Getopt->new(
+ $ng = Monitoring::Plugin::Getopt->new(
usage => 'Usage: %s --hello',
version => '0.01',
);
-The Nagios::Plugin::Getopt constructor accepts the following named
+The Monitoring::Plugin::Getopt constructor accepts the following named
arguments:
=over 4
@@ -573,7 +573,7 @@ the longer --help output. e.g.
=item url
-URL for info about this plugin, included in the --version/-V output,
+URL for info about this plugin, included in the --version/-V output,
and in the longer --help output (see preceding 'version' example).
=item blurb
@@ -583,20 +583,20 @@ Short plugin description, included in the longer --help output
=item license
-License text, included in the longer --help output (see below for an
+License text, included in the longer --help output (see below for an
example). By default, this is set to the standard nagios plugins
GPL license text:
- This nagios plugin is free software, and comes with ABSOLUTELY
- NO WARRANTY. It may be used, redistributed and/or modified under
- the terms of the GNU General Public Licence (see
+ This nagios plugin is free software, and comes with ABSOLUTELY
+ NO WARRANTY. It may be used, redistributed and/or modified under
+ the terms of the GNU General Public Licence (see
http://www.fsf.org/licensing/licenses/gpl.txt).
Provide your own to replace this text in the help output.
=item extra
-Extra text to be appended at the end of the longer --help output.
+Extra text to be appended at the end of the longer --help output.
=item plugin
@@ -605,7 +605,7 @@ usually correct, but you can set it explicitly if not.
=item timeout
-Timeout period in seconds, overriding the standard timeout default
+Timeout period in seconds, overriding the standard timeout default
(15 seconds).
=back
@@ -630,8 +630,8 @@ example:
$ ./check_tcp_range -h
check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/]
- This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
- It may be used, redistributed and/or modified under the terms of the GNU
+ This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
+ It may be used, redistributed and/or modified under the terms of the GNU
General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).
This plugin tests arbitrary ranges/sets of tcp ports for a host.
@@ -647,7 +647,7 @@ example:
Host name or IP address
-p, --ports=STRING
Port numbers to check. Format: comma-separated, colons for ranges,
- no spaces e.g. 8700:8705,8710:8715,8760
+ no spaces e.g. 8700:8705,8710:8715,8760
-t, --timeout=INTEGER
Seconds before plugin times out (default: 15)
-v, --verbose
@@ -656,14 +656,14 @@ example:
=head2 ARGUMENTS
-You can define arguments for your plugin using the arg() method, which
+You can define arguments for your plugin using the arg() method, which
supports both named and positional arguments. In both cases
-the C<spec> and C<help> arguments are required, while the C<label>,
+the C<spec> and C<help> arguments are required, while the C<label>,
C<default>, and C<required> arguments are optional:
# Define --hello argument (named parameters)
$ng->arg(
- spec => 'hello|h=s',
+ spec => 'hello|h=s',
help => "Hello string",
required => 1,
);
@@ -710,12 +710,12 @@ The help string is munged in two ways:
=item
-First, if the help string does NOT begins with a '-' sign, it is prefixed
-by an expanded form of the C<spec> argument. For instance, the following
+First, if the help string does NOT begins with a '-' sign, it is prefixed
+by an expanded form of the C<spec> argument. For instance, the following
hello argument:
$ng->arg(
- spec => 'hello|h=s',
+ spec => 'hello|h=s',
help => "Hello string",
);
@@ -727,9 +727,9 @@ would be displayed in the help output as:
where the '-h, --hello=STRING' part is derived from the spec definition
(by convention with short args first, then long, then label/type, if any).
-=item
+=item
-Second, if the string contains a '%s' it will be formatted via
+Second, if the string contains a '%s' it will be formatted via
C<sprintf> with the 'default' as the argument i.e.
sprintf($help, $default)
@@ -756,18 +756,18 @@ would be displayed in the help output as:
Exit with WARNING status if less than PERCENT of disk space is free
Note that in this case we've also specified explicit labels in another
-arrayref corresponding to the C<help> one - if this had been omitted
-the types would have defaulted to 'STRING', instead of 'BYTES' and
+arrayref corresponding to the C<help> one - if this had been omitted
+the types would have defaulted to 'STRING', instead of 'BYTES' and
'PERCENT%'.
=item label
-The C<label> argument is a scalar or an arrayref (see 'Multi-line help'
+The C<label> argument is a scalar or an arrayref (see 'Multi-line help'
description above) that overrides the standard type expansion when generating
-help text from the spec definition. By default, C<spec=i> arguments are
-labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled
-as C<=STRING>. By supplying your own C<label> argument you can override these
+help text from the spec definition. By default, C<spec=i> arguments are
+labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled
+as C<=STRING>. By supplying your own C<label> argument you can override these
standard 'INTEGER' and 'STRING' designations.
For multi-line help, you can supply an ordered list (arrayref) of labels to
@@ -789,13 +789,13 @@ if none is explicitly supplied.
=item required
-The C<required> argument is a boolean used to indicate that this argument
-is mandatory (Nagios::Plugin::Getopt will exit with your usage message and
+The C<required> argument is a boolean used to indicate that this argument
+is mandatory (Monitoring::Plugin::Getopt will exit with your usage message and
a 'Missing argument' indicator if any required arguments are not supplied).
=back
-Note that --help lists your arguments in the order they are defined, so
+Note that --help lists your arguments in the order they are defined, so
you should order your C<arg()> calls accordingly.
@@ -809,7 +809,7 @@ method, which takes no arguments:
This parses the command line arguments passed to your plugin using
Getopt::Long and the builtin and provided argument specifications.
-Flags and argument values are recorded within the object, and can
+Flags and argument values are recorded within the object, and can
be accessed either using the generic get() accessor, or using named
accessors corresponding to your argument names. For example:
@@ -824,14 +824,14 @@ accessors corresponding to your argument names. For example:
# ...
}
-Note that where you have defined alternate argument names, the first is
-considered the citation form. All the builtin arguments are available
+Note that where you have defined alternate argument names, the first is
+considered the citation form. All the builtin arguments are available
using their long variant names.
=head2 BUILTIN PROCESSING
-The C<getopts()> method also handles processing of the immediate builtin
+The C<getopts()> method also handles processing of the immediate builtin
arguments, namely --usage, --version, --help, as well as checking all
required arguments have been supplied, so you don't have to handle
those 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
alarm $ng->timeout;
-around any blocking operations within your plugin (which you are free
+around any blocking operations within your plugin (which you are free
to override if you want to use a custom timeout message).
=head1 SEE ALSO
-Nagios::Plugin, Getopt::Long
+Monitoring::Plugin, Getopt::Long
=head1 AUTHOR
-Gavin Carr <gavin at openfusion.com.au>
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
+Originally:
+ Gavin Carr <gavin at openfusion.com.au>
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006-2007 by the Nagios Plugin Development Team.
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
-This module is free software. It may be used, redistributed
-and/or modified under either the terms of the Perl Artistic
-License (see http://www.perl.com/perl/misc/Artistic.html)
-or the GNU General Public Licence (see
-http://www.fsf.org/licensing/licenses/gpl.txt).
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
=cut
-
-# arch-tag: c917effc-7400-4ee5-a5d6-baa9316a3abf
-# vim:smartindent:sw=2:et
-
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Monitoring/Plugin/Performance.pm
similarity index 78%
rename from lib/Nagios/Plugin/Performance.pm
rename to 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 @@
-package Nagios::Plugin::Performance;
+package Monitoring::Plugin::Performance;
use 5.006;
@@ -11,15 +11,15 @@ __PACKAGE__->mk_ro_accessors(
qw(label value uom warning critical min max)
);
-use Nagios::Plugin::Functions;
-use Nagios::Plugin::Threshold;
-use Nagios::Plugin::Range;
-our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
+use Monitoring::Plugin::Functions;
+use Monitoring::Plugin::Threshold;
+use Monitoring::Plugin::Range;
+our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
sub import {
my ($class, %attr) = @_;
$_ = $attr{use_die} || 0;
- Nagios::Plugin::Functions::_use_die($_);
+ Monitoring::Plugin::Functions::_use_die($_);
}
# This is NOT the same as N::P::Functions::value_re. We leave that to be the strict
@@ -46,7 +46,7 @@ sub _parse {
return undef if $not_value;
}
my $p = $class->new(
- label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4],
+ label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4],
min => $info[5], max => $info[6]
);
return $p;
@@ -128,13 +128,13 @@ sub clean_label {
sub threshold
{
my $self = shift;
- return Nagios::Plugin::Threshold->set_thresholds(
+ return Monitoring::Plugin::Threshold->set_thresholds(
warning => $self->warning, critical => $self->critical
);
}
# Constructor - unpack thresholds, map args to hashref
-sub new
+sub new
{
my $class = shift;
my %arg = @_;
@@ -154,15 +154,15 @@ __END__
=head1 NAME
-Nagios::Plugin::Performance - class for handling Nagios::Plugin
+Monitoring::Plugin::Performance - class for handling Monitoring::Plugin
performance data.
=head1 SYNOPSIS
- use Nagios::Plugin::Performance use_die => 1;
+ use Monitoring::Plugin::Performance use_die => 1;
# Constructor (also accepts a 'threshold' obj instead of warning/critical)
- $p = Nagios::Plugin::Performance->new(
+ $p = Monitoring::Plugin::Performance->new(
label => 'size',
value => $value,
uom => "kB",
@@ -173,9 +173,9 @@ performance data.
);
# Parser
- @perf = Nagios::Plugin::Performance->parse_perfstring(
+ @perf = Monitoring::Plugin::Performance->parse_perfstring(
"/=382MB;15264;15269;; /var=218MB;9443;9448"
- )
+ )
or warn("Failed to parse perfstring");
# Accessors
@@ -197,14 +197,14 @@ performance data.
=head1 DESCRIPTION
-Nagios::Plugin class for handling performance data. This is a public
-interface because it could be used by performance graphing routines,
-such as nagiostat (http://nagiostat.sourceforge.net), perfparse
-(http://perfparse.sourceforge.net), nagiosgraph
-(http://nagiosgraph.sourceforge.net) or NagiosGrapher
+Monitoring::Plugin class for handling performance data. This is a public
+interface because it could be used by performance graphing routines,
+such as nagiostat (http://nagiostat.sourceforge.net), perfparse
+(http://perfparse.sourceforge.net), nagiosgraph
+(http://nagiosgraph.sourceforge.net) or NagiosGrapher
(http://www.nagiosexchange.org/NagiosGrapher.84.0.html).
-Nagios::Plugin::Performance offers both a parsing interface (via
+Monitoring::Plugin::Performance offers both a parsing interface (via
parse_perfstring), for turning nagios performance output strings into
their components, and a composition interface (via new), for turning
components into perfdata strings.
@@ -213,7 +213,7 @@ components into perfdata strings.
If you are using this module for the purposes of parsing perf data, you
will probably want to set use_die => 1 at use time. This forces
-&Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() -
+&Monitoring::Plugin::Functions::plugin_exit to call die() - rather than exit() -
when an error occurs. This is then trappable by an eval. If you don't set use_die,
then an error in these modules will cause your script to exit
@@ -221,14 +221,14 @@ then an error in these modules will cause your script to exit
=over 4
-=item Nagios::Plugin::Performance->new(%attributes)
+=item Monitoring::Plugin::Performance->new(%attributes)
-Instantiates a new Nagios::Plugin::Performance object with the given
+Instantiates a new Monitoring::Plugin::Performance object with the given
attributes.
-=item Nagios::Plugin::Performance->parse_perfstring($string)
+=item Monitoring::Plugin::Performance->parse_perfstring($string)
-Returns an array of Nagios::Plugin::Performance objects based on the string
+Returns an array of Monitoring::Plugin::Performance objects based on the string
entered. If there is an error parsing the string - which may consists of several
sets of data - will return an array with all the successfully parsed sets.
@@ -247,18 +247,18 @@ These all return scalars. min and max are not well supported yet.
=item threshold
-Returns a Nagios::Plugin::Threshold object holding the warning and critical
+Returns a Monitoring::Plugin::Threshold object holding the warning and critical
ranges for this performance data (if any).
=item rrdlabel
-Returns a string based on 'label' that is suitable for use as dataset name of
-an RRD i.e. munges label to be 1-19 characters long with only characters
+Returns a string based on 'label' that is suitable for use as dataset name of
+an RRD i.e. munges label to be 1-19 characters long with only characters
[a-zA-Z0-9_].
This calls $self->clean_label and then truncates to 19 characters.
-There is no guarantee that multiple N:P:Performance objects will have unique
+There is no guarantee that multiple N:P:Performance objects will have unique
rrdlabels.
=item clean_label
@@ -270,25 +270,25 @@ It also converts "/" to "root" and "/{name}" to "{name}".
=item perfoutput
-Outputs the data in Nagios::Plugin perfdata format i.e.
+Outputs the data in Monitoring::Plugin perfdata format i.e.
label=value[uom];[warn];[crit];[min];[max].
-=back
+=back
=head1 SEE ALSO
-Nagios::Plugin, Nagios::Plugin::Threshold, http://nagiosplug.sourceforge.net.
+Monitoring::Plugin, Monitoring::Plugin::Threshold, https://www.monitoring-plugins.org/doc/guidelines.html
=head1 AUTHOR
-This code is maintained by the Nagios Plugin Development Team: see
-http://nagiosplug.sourceforge.net.
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006-2007 Nagios Plugin Development Team
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+it under the same terms as Perl itself.
=cut
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Monitoring/Plugin/Range.pm
similarity index 80%
rename from lib/Nagios/Plugin/Range.pm
rename to 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 @@
-package Nagios::Plugin::Range;
+package Monitoring::Plugin::Range;
use 5.006;
@@ -11,8 +11,8 @@ __PACKAGE__->mk_accessors(
qw(start end start_infinity end_infinity alert_on)
);
-use Nagios::Plugin::Functions qw(:DEFAULT $value_re);
-our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
+use Monitoring::Plugin::Functions qw(:DEFAULT $value_re);
+our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
use overload
'eq' => sub { shift->_stringify },
@@ -26,7 +26,7 @@ sub _stringify {
my $self = shift;
return "" unless $self->is_set;
return (($self->alert_on) ? "@" : "") .
- (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) .
+ (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) .
(($self->end_infinity == 1) ? "" : $self->end);
}
@@ -47,7 +47,7 @@ sub _set_range_end {
$self->end_infinity(0);
}
-# Returns a N::P::Range object if the string is a conforms to a Nagios Plugin range string, otherwise null
+# Returns a N::P::Range object if the string is a conforms to a Monitoring Plugin range string, otherwise null
sub parse_range_string {
my ($class, $string) = @_;
my $valid = 0;
@@ -118,7 +118,7 @@ sub check_range {
}
# Constructor - map args to hashref for SUPER
-sub new
+sub new
{
shift->SUPER::new({ @_ });
}
@@ -129,18 +129,18 @@ __END__
=head1 NAME
-Nagios::Plugin::Range - class for handling Nagios::Plugin range data.
+Monitoring::Plugin::Range - class for handling Monitoring::Plugin range data.
=head1 SYNOPSIS
- # NB: This is an internal Nagios::Plugin class.
- # See Nagios::Plugin itself for public interfaces.
+ # NB: This is an internal Monitoring::Plugin class.
+ # See Monitoring::Plugin itself for public interfaces.
# Instantiate an empty range object
- $r = Nagios::Plugin::Range->new;
+ $r = Monitoring::Plugin::Range->new;
# Instantiate by parsing a standard nagios range string
- $r = Nagios::Plugin::Range->parse_range_string( $range_str );
+ $r = Monitoring::Plugin::Range->parse_range_string( $range_str );
# Returns true if the range is defined/non-empty
$r->is_set;
@@ -151,17 +151,17 @@ Nagios::Plugin::Range - class for handling Nagios::Plugin range data.
=head1 DESCRIPTION
-Internal Nagios::Plugin class for handling common range data. See
-Nagios::Plugin for public interfaces.
+Internal Monitoring::Plugin class for handling common range data. See
+Monitoring::Plugin for public interfaces.
=head1 AUTHOR
-This code is maintained by the Nagios Plugin Development Team: see
-http://nagiosplug.sourceforge.net.
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006-2007 Nagios Plugin Development Team
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Monitoring/Plugin/Threshold.pm
similarity index 64%
rename from lib/Nagios/Plugin/Threshold.pm
rename to 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 @@
-package Nagios::Plugin::Threshold;
+package Monitoring::Plugin::Threshold;
use 5.006;
@@ -8,11 +8,11 @@ use warnings;
use base qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors(qw(warning critical));
-use Nagios::Plugin::Range;
-use Nagios::Plugin::Functions qw(:codes nagios_die);
-our ($VERSION) = $Nagios::Plugin::Functions::VERSION;
+use Monitoring::Plugin::Range;
+use Monitoring::Plugin::Functions qw(:codes plugin_die);
+our ($VERSION) = $Monitoring::Plugin::Functions::VERSION;
-sub get_status
+sub get_status
{
my ($self, $value) = @_;
@@ -22,7 +22,7 @@ sub get_status
return CRITICAL if $self->critical->check_range($v);
}
}
- foreach my $v (@$value) {
+ foreach my $v (@$value) {
if ($self->warning->is_set) {
return WARNING if $self->warning->check_range($v);
}
@@ -35,21 +35,21 @@ sub _inflate
my ($self, $value, $key) = @_;
# Return an undefined range if $value is undef
- return Nagios::Plugin::Range->new if ! defined $value;
+ return Monitoring::Plugin::Range->new if ! defined $value;
# For refs, check isa N::P::Range
if (ref $value) {
- nagios_die("Invalid $key object: type " . ref $value)
- unless $value->isa("Nagios::Plugin::Range");
+ plugin_die("Invalid $key object: type " . ref $value)
+ unless $value->isa("Monitoring::Plugin::Range");
return $value;
}
# Another quick exit if $value is an empty string
- return Nagios::Plugin::Range->new if $value eq "";
+ return Monitoring::Plugin::Range->new if $value eq "";
# Otherwise parse $value
- my $range = Nagios::Plugin::Range->parse_range_string($value);
- nagios_die("Cannot parse $key range: '$value'") unless(defined($range));
+ my $range = Monitoring::Plugin::Range->parse_range_string($value);
+ plugin_die("Cannot parse $key range: '$value'") unless(defined($range));
return $range;
}
@@ -70,9 +70,9 @@ sub set
my ($key, $value) = @_;
$self->SUPER::set($key, $self->_inflate($value, $key));
}
-
+
# Constructor - inflate scalars to N::P::Range objects
-sub new
+sub new
{
my ($self, %arg) = @_;
$self->SUPER::new({
@@ -86,15 +86,15 @@ __END__
=head1 NAME
-Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds.
+Monitoring::Plugin::Threshold - class for handling Monitoring::Plugin thresholds.
=head1 SYNOPSIS
- # NB: This is an internal Nagios::Plugin class.
- # See Nagios::Plugin itself for public interfaces.
-
+ # NB: This is an internal Monitoring::Plugin class.
+ # See Monitoring::Plugin itself for public interfaces.
+
# Constructor
- $t = Nagios::Plugin::Threshold->set_thresholds(
+ $t = Monitoring::Plugin::Threshold->set_thresholds(
warning => $warning_range_string,
critical => $critical_range_string,
);
@@ -110,10 +110,10 @@ Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds.
=head1 DESCRIPTION
-Internal Nagios::Plugin class for handling threshold data. See
-Nagios::Plugin for public interfaces.
+Internal Monitoring::Plugin class for handling threshold data. See
+Monitoring::Plugin for public interfaces.
-A threshold object contains (typically) a pair of ranges, associated
+A threshold object contains (typically) a pair of ranges, associated
with a particular severity e.g.
warning => range1
@@ -121,12 +121,12 @@ with a particular severity e.g.
=head1 AUTHOR
-This code is maintained by the Nagios Plugin Development Team: see
-http://nagiosplug.sourceforge.net.
+This code is maintained by the Monitoring Plugin Development Team: see
+https://monitoring-plugins.org
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2006-2007 Nagios Plugin Development Team
+Copyright (C) 2006-2014 Monitoring Plugin Development Team
This library is free software; you can redistribute it and/or modify
it 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 @@
-# Tiny helper class to return both output and return_code when testing
-
-package Nagios::Plugin::ExitResult;
-
-use strict;
-
-# Stringify to message
-use overload '""' => sub { shift->{message} };
-
-# Constructor
-sub new {
- my $class = shift;
- return bless { return_code => $_[0], message => $_[1] }, $class;
-}
-
-# Accessors
-sub message { shift->{message} }
-sub return_code { shift->{return_code} }
-sub code { shift->{return_code} }
-
-1;
-
-__END__
-
-=head1 NAME
-
-Nagios::Plugin::ExitResult - Helper class for returning both output and
-return codes when testing.
-
-=head1 SYNOPSIS
-
- use Test::More;
- use Nagios::Plugin::Functions;
-
- # In a test file somewhere
- Nagios::Plugin::Functions::_fake_exit(1);
-
- # Later ...
- $e = nagios_exit( CRITICAL, 'aiiii ...' );
- print $e->message;
- print $e->return_code;
-
- # NP::ExitResult also stringifies to the message output
- like(nagios_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');
-
-
-
-=head1 DESCRIPTION
-
-Nagios::Plugin::ExitResult is a tiny helper class intended for use
-when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult
-object is returned by nagios_exit() and friends when
-Nagios::Plugin::Functions::_fake_exit has been set, instead of doing a
-conventional print + exit.
-
-=head1 AUTHOR
-
-Gavin Carr , E<lt>gavin at openfusion.com.auE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright (C) 2006 by Nagios Plugin Development Team
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
diff --git a/t/Nagios-Plugin-01.t b/t/Monitoring-Plugin-01.t
similarity index 65%
rename from t/Nagios-Plugin-01.t
rename to t/Monitoring-Plugin-01.t
index 947a704..f5882a5 100644
--- a/t/Nagios-Plugin-01.t
+++ b/t/Monitoring-Plugin-01.t
@@ -1,32 +1,32 @@
-# Nagios::Plugin original test cases
+# Monitoring::Plugin original test cases
use strict;
use Test::More tests => 15;
-BEGIN { use_ok('Nagios::Plugin') };
+BEGIN { use_ok('Monitoring::Plugin') };
-use Nagios::Plugin::Functions;
-Nagios::Plugin::Functions::_fake_exit(1);
+use Monitoring::Plugin::Functions;
+Monitoring::Plugin::Functions::_fake_exit(1);
-diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n"
+diag "\nusing Monitoring::Plugin revision ". $Monitoring::Plugin::VERSION . "\n"
if $ENV{TEST_VERBOSE};
-my $p = Nagios::Plugin->new();
-isa_ok( $p, "Nagios::Plugin");
+my $p = Monitoring::Plugin->new();
+isa_ok( $p, "Monitoring::Plugin");
$p->shortname("PAGESIZE");
is($p->shortname, "PAGESIZE", "shortname explicitly set correctly");
-$p = Nagios::Plugin->new();
-is($p->shortname, "NAGIOS-PLUGIN-01", "shortname should default on new");
+$p = Monitoring::Plugin->new();
+is($p->shortname, "MONITORING-PLUGIN-01", "shortname should default on new");
-$p = Nagios::Plugin->new( shortname => "SIZE", () );
+$p = Monitoring::Plugin->new( shortname => "SIZE", () );
is($p->shortname, "SIZE", "shortname set correctly on new");
-$p = Nagios::Plugin->new( plugin => "check_stuff", () );
+$p = Monitoring::Plugin->new( plugin => "check_stuff", () );
is($p->shortname, "STUFF", "shortname uses plugin name as default");
-$p = Nagios::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () );
+$p = Monitoring::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () );
is($p->shortname, "SIZE", "shortname is not overriden by default");
diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE};
@@ -37,10 +37,10 @@ use Data::Dumper;
#diag "dumping perfdata: ". Dumper $p->perfdata;
-$p->add_perfdata(
- label => "size",
- value => 1,
- uom => "kB",
+$p->add_perfdata(
+ label => "size",
+ value => 1,
+ uom => "kB",
threshold => $t,
);
@@ -69,4 +69,3 @@ foreach (sort {$a<=>$b} keys %$expected) {
qr/$expected->{$_}/,
"Output okay. $_ = $expected->{$_}" ;
}
-
diff --git a/t/Monitoring-Plugin-02.t b/t/Monitoring-Plugin-02.t
new file mode 100644
index 0000000..6cc834d
--- /dev/null
+++ b/t/Monitoring-Plugin-02.t
@@ -0,0 +1,160 @@
+# Monitoring::Plugin test set 2, testing MP::Functions wrapping
+
+use strict;
+use Test::More tests => 103;
+
+BEGIN { use_ok("Monitoring::Plugin") }
+require Monitoring::Plugin::Functions;
+Monitoring::Plugin::Functions::_fake_exit(1);
+
+# Hardcoded checks of constants
+my %ERRORS = %Monitoring::Plugin::Functions::ERRORS;
+is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
+is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
+is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
+is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
+is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
+
+my $plugin = 'TEST_PLUGIN';
+my $np = Monitoring::Plugin->new( shortname => $plugin );
+is($np->shortname, $plugin, "shortname() is $plugin");
+
+# Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg )
+my $r;
+my @ok = (
+ [ OK, "OK", 'test the first', ],
+ [ WARNING, "WARNING", 'test the second', ],
+ [ CRITICAL, "CRITICAL", 'test the third', ],
+ [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
+ [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
+);
+for (@ok) {
+ # CONSTANT
+ $r = $np->plugin_exit($_->[0], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"', $_->[1],
+ $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
+
+ # $string
+ $r = $np->plugin_exit($_->[1], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1],
+ $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1],
+ $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
+}
+
+# plugin_exit code corner cases
+my @ugly1 = (
+ [ -1, 'testing code -1' ],
+ [ 7, 'testing code 7' ],
+ [ undef, 'testing code undef' ],
+ [ '', qq(testing code '') ],
+ [ 'string', qq(testing code 'string') ],
+);
+for (@ugly1) {
+ $r = $np->plugin_exit($_->[0], $_->[1]);
+ my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
+ is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN);
+ like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"',
+ $display, 'UNKNOWN.*' . $_->[1]));
+}
+
+# plugin_exit message corner cases
+my @ugly2 = (
+ [ '' ],
+ [ undef ],
+ [ UNKNOWN ],
+);
+for (@ugly2) {
+ $r = $np->plugin_exit(CRITICAL, $_->[0]);
+ my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
+ my $display2 = defined $_->[0] ? $_->[0] : '';
+ like($r->message, qr/CRITICAL\b.*\b$display2$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"',
+ $display1, "CRITICAL.*$display2"));
+}
+
+# Test plugin_die( $msg )
+my @msg = (
+ [ 'die you dog' ],
+ [ '' ],
+ [ undef ],
+);
+for (@msg) {
+ $r = $np->plugin_die($_->[0]);
+ my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
+ my $display2 = defined $_->[0] ? $_->[0] : '';
+ is($r->return_code, UNKNOWN,
+ sprintf('plugin_die(%s) returned UNKNOWN', $display1));
+ like($r->message, qr/UNKNOWN\b.*\b$display2$/,
+ sprintf('plugin_die(%s) output matched "%s"', $display1,
+ "UNKNOWN.*$display2"));
+}
+
+# Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ),
+# plugin_die( $string, $msg ), and plugin_die( $msg, $string )
+ at ok = (
+ [ OK, "OK", 'test the first', ],
+ [ WARNING, "WARNING", 'test the second', ],
+ [ CRITICAL, "CRITICAL", 'test the third', ],
+ [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
+ [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
+);
+for (@ok) {
+ # CONSTANT, $msg
+ $r = $np->plugin_die($_->[0], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die(%s, $msg) output matched "%s"',
+ $_->[1], $_->[1] . '.*' . $_->[2]));
+
+ # $msg, CONSTANT
+ $r = $np->plugin_die($_->[2], $_->[0]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, %s) output matched "%s"',
+ $_->[1], $_->[1] . '.*' . $_->[2]));
+
+ # $string, $msg
+ $r = $np->plugin_die($_->[1], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+
+ # $string, $msg
+ $r = $np->plugin_die($_->[2], $_->[1]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+}
+
+
+# shortname testing
+SKIP: {
+ skip "requires File::Basename", 2 unless eval { require File::Basename };
+ $np = Monitoring::Plugin->new( version => "1");
+ $plugin = uc File::Basename::basename($0);
+ $plugin =~ s/\..*$//;
+ is($np->shortname, $plugin, "shortname() is '$plugin'");
+ $r = $np->plugin_exit(OK, "foobar");
+ like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'");
+}
diff --git a/t/Nagios-Plugin-03.t b/t/Monitoring-Plugin-03.t
similarity index 90%
rename from t/Nagios-Plugin-03.t
rename to t/Monitoring-Plugin-03.t
index bc4f5e3..d419342 100644
--- a/t/Nagios-Plugin-03.t
+++ b/t/Monitoring-Plugin-03.t
@@ -3,15 +3,15 @@
use strict;
use Test::More tests => 61;
-BEGIN {
- use_ok("Nagios::Plugin");
- use_ok("Nagios::Plugin::Functions", ":all");
+BEGIN {
+ use_ok("Monitoring::Plugin");
+ use_ok("Monitoring::Plugin::Functions", ":all");
}
-Nagios::Plugin::Functions::_fake_exit(1);
+Monitoring::Plugin::Functions::_fake_exit(1);
-my $plugin = 'NP_CHECK_MESSAGES_03';
-my $np = Nagios::Plugin->new( shortname => $plugin, () );
-is($np->shortname, $plugin, "shortname() is $plugin");
+my $plugin = 'MP_CHECK_MESSAGES_03';
+my $np = Monitoring::Plugin->new( shortname => $plugin, () );
+is($np->shortname, $plugin, "shortname() is $plugin");
my ($code, $message);
@@ -113,11 +113,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message")
# -------------------------------------------------------------------------
# join_all messages
my $join_all = ' :: ';
-my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(critical warning ok));
-my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(critical warning));
-my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(warning ok));
# critical, warning, ok
@@ -172,33 +172,33 @@ is($message, 'D E F', "join_all '$join_all' (critical, warning) message is $mess
# add_messages
# Constant codes
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( CRITICAL, "A B C" );
$np->add_message( WARNING, "D E F" );
($code, $message) = $np->check_messages();
is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}");
is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( CRITICAL, "A B C" );
($code, $message) = $np->check_messages();
is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}");
is($message, $messages{critical}, "(CRITICAL) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( WARNING, "D E F" );
($code, $message) = $np->check_messages();
is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}");
is($message, $messages{warning}, "(WARNING) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( WARNING, "D E F" );
$np->add_message( OK, "G H I" );
($code, $message) = $np->check_messages();
is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}");
is($message, $messages{warning}, "(WARNING, OK) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( OK, "G H I" );
($code, $message) = $np->check_messages();
is($code, OK, "(OK) code is $STATUS_TEXT{$code}");
@@ -206,33 +206,33 @@ is($message, $messages{ok}, "(OK) message is $message");
# String codes
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( critical => "A B C" );
$np->add_message( warning => "D E F" );
($code, $message) = $np->check_messages();
is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}");
is($message, $messages{critical}, "(critical, warning) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( critical => "A B C" );
($code, $message) = $np->check_messages();
is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}");
is($message, $messages{critical}, "(critical) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( warning => "D E F" );
($code, $message) = $np->check_messages();
is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}");
is($message, $messages{warning}, "(warning) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( warning => "D E F" );
$np->add_message( ok => "G H I" );
($code, $message) = $np->check_messages();
is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}");
is($message, $messages{warning}, "(warning, ok) message is $message");
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
$np->add_message( ok => "G H I" );
($code, $message) = $np->check_messages();
is($code, OK, "(ok) code is $STATUS_TEXT{$code}");
@@ -240,7 +240,7 @@ is($message, $messages{ok}, "(ok) message is $message");
# No add_message
-$np = Nagios::Plugin->new();
+$np = Monitoring::Plugin->new();
($code, $message) = $np->check_messages();
is($code, OK, "() code is $STATUS_TEXT{$code}");
is($message, '', "() message is ''");
@@ -250,14 +250,13 @@ is($message, '', "() message is ''");
# Error conditions
# add_message errors
-$np = Nagios::Plugin->new();
-ok(! defined eval { $np->add_message( foobar => 'hi mum' ) },
+$np = Monitoring::Plugin->new();
+ok(! defined eval { $np->add_message( foobar => 'hi mum' ) },
'add_message dies on invalid code');
-ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) },
+ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) },
'add_message dies on invalid code');
# UNKNOWN and DEPENDENT error codes
-ok(! defined eval { $np->add_message( unknown => 'hi mum' ) },
+ok(! defined eval { $np->add_message( unknown => 'hi mum' ) },
'add_message dies on UNKNOWN code');
-ok(! defined eval { $np->add_message( dependent => 'hi mum' ) },
+ok(! defined eval { $np->add_message( dependent => 'hi mum' ) },
'add_message dies on DEPENDENT code');
-
diff --git a/t/Nagios-Plugin-04.t b/t/Monitoring-Plugin-04.t
similarity index 80%
rename from t/Nagios-Plugin-04.t
rename to t/Monitoring-Plugin-04.t
index e5eb3ab..41027f7 100644
--- a/t/Nagios-Plugin-04.t
+++ b/t/Monitoring-Plugin-04.t
@@ -5,25 +5,25 @@ use strict;
#use Test::More 'no_plan';
use Test::More tests=>30;
-BEGIN { use_ok('Nagios::Plugin') };
-use Nagios::Plugin::Functions;
-Nagios::Plugin::Functions::_fake_exit(1);
+BEGIN { use_ok('Monitoring::Plugin') };
+use Monitoring::Plugin::Functions;
+Monitoring::Plugin::Functions::_fake_exit(1);
-eval { Nagios::Plugin->new(); };
+eval { Monitoring::Plugin->new(); };
ok(! $@, "constructor DOESN'T die without usage");
-my $p = Nagios::Plugin->new();
+my $p = Monitoring::Plugin->new();
eval { $p->add_arg('warning', 'warning') };
ok($@, "add_arg() dies if you haven't instantiated with usage");
eval { $p->getopts };
ok($@, "getopts() dies if you haven't instantiated with usage");
-$p = Nagios::Plugin->new( usage => "dummy usage statement" );
+$p = Monitoring::Plugin->new( usage => "dummy usage statement" );
# option accessors work
can_ok $p, 'opts';
-isa_ok $p->opts, 'Nagios::Plugin::Getopt', "Getopt object is defined";
+isa_ok $p->opts, 'Monitoring::Plugin::Getopt', "Getopt object is defined";
$p->add_arg('warning|w=s', "warning");
$p->add_arg('critical|c=s', "critical");
@@ -35,11 +35,11 @@ is $p->opts->critical, "10", "critical opt is accessible";
can_ok $p, 'perfdata';
-#isa_ok $p->perfdata, 'Nagios::Plugin::Performance', "perfdata object is defined";
+#isa_ok $p->perfdata, 'Monitoring::Plugin::Performance', "perfdata object is defined";
can_ok $p, 'threshold';
-#isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined";
+#isa_ok $p->threshold, 'Monitoring::Plugin::Threshold', "threshold object is defined";
eval { $p->check_threshold() };
@@ -60,20 +60,20 @@ is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL w
# thresholds set explicitly
is $p->check_threshold(
- check => 2,
+ check => 2,
warning => 50,
critical => 100
), OK, "check_threshold explicit OK";
is $p->check_threshold(
- check => 66,
+ check => 66,
warning => 50,
critical => 100
), WARNING, "check_threshold explicit WARNING";
is $p->check_threshold(
- check => -1,
+ check => -1,
warning => 5,
critical => '0:5',
), CRITICAL, "check_threshold explicit CRITICAL";
@@ -82,7 +82,7 @@ is $p->check_threshold(
# what happens if you forget to define warning or critical thresholds?
$p = undef;
-$p = Nagios::Plugin->new();
+$p = Monitoring::Plugin->new();
is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN";
is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN";
diff --git a/t/Nagios-Plugin-05.t b/t/Monitoring-Plugin-05.t
similarity index 56%
rename from t/Nagios-Plugin-05.t
rename to t/Monitoring-Plugin-05.t
index cc602cc..d17464f 100644
--- a/t/Nagios-Plugin-05.t
+++ b/t/Monitoring-Plugin-05.t
@@ -1,16 +1,15 @@
# Check for exported vars
-# Can't include Nagios::Plugin::Functions because it also exports %STATUS_TEXT
+# Can't include Monitoring::Plugin::Functions because it also exports %STATUS_TEXT
use strict;
use Test::More tests=>4;
-BEGIN { use_ok('Nagios::Plugin') };
+BEGIN { use_ok('Monitoring::Plugin') };
eval ' $_ = $STATUS_TEXT{0} ';
like( $@, '/Global symbol "%STATUS_TEXT" requires explicit package name/' );
-use_ok("Nagios::Plugin", qw(%STATUS_TEXT));
+use_ok("Monitoring::Plugin", qw(%STATUS_TEXT));
eval ' $_ = $STATUS_TEXT{0} ';
is( $@, '' );
-
diff --git a/t/Monitoring-Plugin-Functions-01.t b/t/Monitoring-Plugin-Functions-01.t
new file mode 100644
index 0000000..084ad28
--- /dev/null
+++ b/t/Monitoring-Plugin-Functions-01.t
@@ -0,0 +1,161 @@
+
+use strict;
+use Test::More tests => 113;
+
+BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); }
+Monitoring::Plugin::Functions::_fake_exit(1);
+
+my $this_version=$Monitoring::Plugin::Functions::VERSION;
+foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) {
+ my $mod = "Monitoring::Plugin$m";
+ use_ok($mod);
+ # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing
+ my $v = "$mod"."::VERSION";
+ my $a = eval "\$$v";
+ is($a, $this_version, "Version number for $mod the same as Functions: $this_version");
+}
+
+# check get_shortname
+is(get_shortname, "MONITORING-PLUGIN-FUNCTIONS-01", "get_shortname ok");
+
+# Hardcoded checks of constants
+ok(%ERRORS, '%ERRORS defined');
+is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
+is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
+is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
+is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
+is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
+
+# Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg )
+my $r;
+my @ok = (
+ [ OK, "OK", 'test the first', ],
+ [ WARNING, "WARNING", 'test the second', ],
+ [ CRITICAL, "CRITICAL", 'test the third', ],
+ [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
+ [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
+);
+for (@ok) {
+ # CONSTANT
+ $r = plugin_exit($_->[0], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"',
+ $_->[1], $_->[1] . '.*' . $_->[2]));
+
+ # $string
+ $r = plugin_exit($_->[1], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+}
+
+# plugin_exit code corner cases
+my @ugly1 = (
+ [ -1, 'testing code -1' ],
+ [ 7, 'testing code 7' ],
+ [ undef, 'testing code undef' ],
+ [ '', qq(testing code '') ],
+ [ 'string', qq(testing code 'string') ],
+);
+for (@ugly1) {
+ $r = plugin_exit($_->[0], $_->[1]);
+ my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
+ is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN);
+ like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"',
+ $display, 'UNKNOWN.*' . $_->[1]));
+}
+
+# plugin_exit message corner cases
+my @ugly2 = (
+ [ '' ],
+ [ undef ],
+ [ UNKNOWN ],
+);
+for (@ugly2) {
+ $r = plugin_exit(CRITICAL, $_->[0]);
+ my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
+ my $display2 = defined $_->[0] ? $_->[0] : '';
+ like($r->message, qr/CRITICAL\b.*\b$display2$/,
+ sprintf('plugin_exit(%s, $msg) output matched "%s"',
+ $display1, "CRITICAL.*$display2"));
+}
+
+# Test plugin_die( $msg )
+my @msg = (
+ [ 'die you dog' ],
+ [ '' ],
+ [ undef ],
+);
+for (@msg) {
+ $r = plugin_die($_->[0]);
+ my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
+ my $display2 = defined $_->[0] ? $_->[0] : '';
+ is($r->return_code, UNKNOWN,
+ sprintf('plugin_die(%s) returned UNKNOWN', $display1));
+ like($r->message, qr/UNKNOWN\b.*\b$display2$/,
+ sprintf('plugin_die(%s) output matched "%s"', $display1,
+ "UNKNOWN.*$display2"));
+}
+
+# Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ),
+# plugin_die( $string, $msg ), and plugin_die( $msg, $string )
+ at ok = (
+ [ OK, "OK", 'test the first', ],
+ [ WARNING, "WARNING", 'test the second', ],
+ [ CRITICAL, "CRITICAL", 'test the third', ],
+ [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
+ [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
+);
+for (@ok) {
+ # CONSTANT, $msg
+ $r = plugin_die($_->[0], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die(%s, $msg) output matched "%s"',
+ $_->[1], $_->[1] . '.*' . $_->[2]));
+
+ # $msg, CONSTANT
+ $r = plugin_die($_->[2], $_->[0]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, %s) output matched "%s"',
+ $_->[1], $_->[1] . '.*' . $_->[2]));
+
+ # $string, $msg
+ $r = plugin_die($_->[1], $_->[2]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+
+ # $string, $msg
+ $r = plugin_die($_->[2], $_->[1]);
+ is($r->return_code, $_->[0],
+ sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0]));
+ like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+ like($r, qr/$_->[1]\b.*\b$_->[2]$/,
+ sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1],
+ $_->[1] . '.*' . $_->[2]));
+}
+
+# Check that _use_die set to 1 will catch exceptions correctly
+Monitoring::Plugin::Functions::_fake_exit(0);
+Monitoring::Plugin::Functions::_use_die(1);
+eval { plugin_die("Using die") };
+is( $@, "MONITORING-PLUGIN-FUNCTIONS-01 UNKNOWN - Using die\n", "Caught exception");
diff --git a/t/Nagios-Plugin-Functions-02.t b/t/Monitoring-Plugin-Functions-02.t
similarity index 98%
rename from t/Nagios-Plugin-Functions-02.t
rename to t/Monitoring-Plugin-Functions-02.t
index 1a9351b..3796210 100644
--- a/t/Nagios-Plugin-Functions-02.t
+++ b/t/Monitoring-Plugin-Functions-02.t
@@ -3,7 +3,7 @@
use strict;
use Test::More tests => 37;
-BEGIN { use_ok("Nagios::Plugin::Functions", ":all") }
+BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
my ($code, $message);
@@ -105,11 +105,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message")
# -------------------------------------------------------------------------
# join_all messages
my $join_all = ' :: ';
-my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(critical warning ok));
-my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(critical warning));
-my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
+my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) }
qw(warning ok));
# critical, warning, ok
@@ -175,4 +175,3 @@ ok(! defined eval { ($code, $message) = check_messages(critical => $arrays{criti
ok(defined eval { ($code, $message) = check_messages(critical => $arrays{critical}, warning => $arrays{warning}) },
"check_messages ok with 'critical' and 'warning' messages");
-
diff --git a/t/Nagios-Plugin-Functions-03.t b/t/Monitoring-Plugin-Functions-03.t
similarity index 90%
rename from t/Nagios-Plugin-Functions-03.t
rename to t/Monitoring-Plugin-Functions-03.t
index 3706e4c..9f0a62c 100644
--- a/t/Nagios-Plugin-Functions-03.t
+++ b/t/Monitoring-Plugin-Functions-03.t
@@ -3,7 +3,7 @@
use strict;
use Test::More tests => 8;
-BEGIN { use_ok("Nagios::Plugin::Functions", ":all") }
+BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
my $new_state = max_state( OK, WARNING );
diff --git a/t/Nagios-Plugin-Functions-04.t b/t/Monitoring-Plugin-Functions-04.t
similarity index 91%
rename from t/Nagios-Plugin-Functions-04.t
rename to t/Monitoring-Plugin-Functions-04.t
index d3ff05c..0a7c4e4 100644
--- a/t/Nagios-Plugin-Functions-04.t
+++ b/t/Monitoring-Plugin-Functions-04.t
@@ -3,7 +3,7 @@
use strict;
use Test::More tests => 8;
-BEGIN { use_ok("Nagios::Plugin::Functions", ":all") }
+BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") }
my $new_state = max_state_alt( OK, WARNING );
diff --git a/t/Nagios-Plugin-Getopt-01.t b/t/Monitoring-Plugin-Getopt-01.t
similarity index 94%
rename from t/Nagios-Plugin-Getopt-01.t
rename to t/Monitoring-Plugin-Getopt-01.t
index 7076d75..36f1f55 100644
--- a/t/Nagios-Plugin-Getopt-01.t
+++ b/t/Monitoring-Plugin-Getopt-01.t
@@ -1,33 +1,33 @@
-# Nagios::Plugin::Getopt basic tests
+# Monitoring::Plugin::Getopt basic tests
use strict;
use Test::More tests => 76;
-BEGIN { use_ok('Nagios::Plugin::Getopt') };
+BEGIN { use_ok('Monitoring::Plugin::Getopt') };
# Needed to get evals to work in testing
-Nagios::Plugin::Functions::_use_die(1);
+Monitoring::Plugin::Functions::_use_die(1);
my %PARAM = (
version => '0.01',
url => 'http://www.openfusion.com.au/labs/nagios/',
- blurb => 'This plugin tests various stuff.',
- usage => "Usage: %s -H <host> -w <warning_threshold>
+ blurb => 'This plugin tests various stuff.',
+ usage => "Usage: %s -H <host> -w <warning_threshold>
-c <critical threshold>",
plugin => 'test_plugin',
);
-sub setup
+sub setup
{
# Instantiate object
- my $ng = Nagios::Plugin::Getopt->new(%PARAM);
+ my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
ok($ng, 'constructor ok');
# Add argument - short form - arg spec, help text, default, required?
$ng->arg('warning|w=s' =>
qq(-w, --warning=INTEGER\n Exit with WARNING status if less than INTEGER foobars are free),
5);
-
+
# Add argument - named version
$ng->arg(
spec => 'critical|c=i',
@@ -147,4 +147,3 @@ like($@, qr/--verbose/, 'help includes default options 2');
like($@, qr/--warning/, 'help includes custom option 1');
like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args');
unlike($@, qr/Missing arg/, 'no missing arguments');
-
diff --git a/t/Nagios-Plugin-Getopt-02.t b/t/Monitoring-Plugin-Getopt-02.t
similarity index 79%
rename from t/Nagios-Plugin-Getopt-02.t
rename to t/Monitoring-Plugin-Getopt-02.t
index f83b180..c6c563e 100644
--- a/t/Nagios-Plugin-Getopt-02.t
+++ b/t/Monitoring-Plugin-Getopt-02.t
@@ -1,27 +1,27 @@
-# Nagios::Plugin::Getopt timeout tests
+# Monitoring::Plugin::Getopt timeout tests
use strict;
use Test::More tests => 14;
-BEGIN { use_ok('Nagios::Plugin::Getopt') };
+BEGIN { use_ok('Monitoring::Plugin::Getopt') };
# Needed to get evals to work in testing
-Nagios::Plugin::Functions::_use_die(1);
+Monitoring::Plugin::Functions::_use_die(1);
my %PARAM = (
version => '0.01',
url => 'http://www.openfusion.com.au/labs/nagios/',
- blurb => 'This plugin tests various stuff.',
- usage => "Usage: %s -H <host> -w <warning_threshold>
+ blurb => 'This plugin tests various stuff.',
+ usage => "Usage: %s -H <host> -w <warning_threshold>
-c <critical threshold>",
plugin => 'test_plugin',
timeout => 18,
);
-sub setup
+sub setup
{
# Instantiate object
- my $ng = Nagios::Plugin::Getopt->new(%PARAM);
+ my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
ok($ng, 'constructor ok');
return $ng;
}
@@ -61,4 +61,3 @@ alarm($ng->timeout);
# Loop
ok(! defined eval { 1 while 1 }, 'loop timed out');
like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok');
-
diff --git a/t/Nagios-Plugin-Getopt-03.t b/t/Monitoring-Plugin-Getopt-03.t
similarity index 79%
rename from t/Nagios-Plugin-Getopt-03.t
rename to t/Monitoring-Plugin-Getopt-03.t
index 560b782..6490145 100644
--- a/t/Nagios-Plugin-Getopt-03.t
+++ b/t/Monitoring-Plugin-Getopt-03.t
@@ -1,4 +1,4 @@
-# Nagios::Plugin::Getopt --extra-opts tests
+# Monitoring::Plugin::Getopt --extra-opts tests
use strict;
use File::Spec;
@@ -6,15 +6,15 @@ use File::Basename;
use IO::File;
use Test::More qw(no_plan);
-BEGIN { use_ok('Nagios::Plugin::Getopt') };
+BEGIN { use_ok('Monitoring::Plugin::Getopt') };
# Needed to get evals to work in testing
-Nagios::Plugin::Functions::_use_die(1);
+Monitoring::Plugin::Functions::_use_die(1);
my $tdir = 'npg03';
if (! -d $tdir) {
my $ttdir = File::Spec->catdir('t', $tdir);
- die "missing '$tdir' directory\n" unless -d $ttdir;
+ die "missing '$tdir' directory\n" unless -d $ttdir;
$tdir = $ttdir;
}
@@ -30,22 +30,22 @@ for my $efile (glob File::Spec->catfile($tdir, 'expected', '*')) {
}
}
-# Override NAGIOS_CONFIG_PATH to use our test plugins.ini file
-$ENV{NAGIOS_CONFIG_PATH} = "/random/bogus/path:$tdir";
+# Override MONITORING_CONFIG_PATH to use our test plugins.ini file
+$ENV{MONITORING_CONFIG_PATH} = "/random/bogus/path:$tdir";
my %PARAM = (
version => '0.01',
- blurb => 'This plugin tests various stuff.',
- usage => "Usage: %s -H <host> -w <warning_threshold>
+ blurb => 'This plugin tests various stuff.',
+ usage => "Usage: %s -H <host> -w <warning_threshold>
-c <critical threshold>",
);
-sub ng_setup
+sub ng_setup
{
my $arg = shift;
# Instantiate object
- my $ng = Nagios::Plugin::Getopt->new(%PARAM);
+ my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
if (ref $arg eq 'ARRAY' && @$arg) {
$ng->arg(%$_) foreach @$arg;
@@ -54,7 +54,7 @@ sub ng_setup
return $ng;
}
-# Setup our Nagios::Plugin::Getopt object
+# Setup our Monitoring::Plugin::Getopt object
my $ng;
my $arg = [
{ spec => 'S', help => '-S' },
@@ -85,9 +85,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) {
$cmd =~ s/^\s+//;
my ($plugin, @args) = split /\s+/, $cmd;
- # Fake out the plugin name
+ # Fake out the plugin name
$ng->{_attr}->{plugin} = $plugin;
-
+
# Parse the options
SKIP: {
skip "Skipping ..." if $SKIP{$infile};
@@ -99,10 +99,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) {
ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)");
is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/);
}
- else {
+ else {
is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile);
}
}
}
}
-
diff --git a/t/Nagios-Plugin-Getopt-04.t b/t/Monitoring-Plugin-Getopt-04.t
similarity index 90%
rename from t/Nagios-Plugin-Getopt-04.t
rename to t/Monitoring-Plugin-Getopt-04.t
index 115f2a2..b6345d0 100644
--- a/t/Nagios-Plugin-Getopt-04.t
+++ b/t/Monitoring-Plugin-Getopt-04.t
@@ -1,29 +1,29 @@
-# Nagios::Plugin::Getopt spec-to-help generation tests
+# Monitoring::Plugin::Getopt spec-to-help generation tests
use strict;
use Test::More tests => 11;
-BEGIN { use_ok('Nagios::Plugin::Getopt') };
+BEGIN { use_ok('Monitoring::Plugin::Getopt') };
# Needed to get evals to work in testing
-Nagios::Plugin::Functions::_use_die(1);
+Monitoring::Plugin::Functions::_use_die(1);
my %PARAM = (
version => '0.01',
usage => "Don't use this plugin!",
);
-sub setup
+sub setup
{
# Instantiate object
- my $ng = Nagios::Plugin::Getopt->new(%PARAM);
+ my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
ok($ng, 'constructor ok');
# Positional args, no short arguments, INTEGER
$ng->arg('warning=i' =>
qq(Exit with WARNING status if less than INTEGER foobars are free),
5);
-
+
# Named args, long + short arguments, INTEGER
$ng->arg(
spec => 'critical|c=i',
@@ -35,7 +35,7 @@ sub setup
$ng->arg(
spec => 'x|y|z=s',
help => qq(Foobar. Default: %s),
- default => "XYZ",
+ default => "XYZ",
);
# Named args, multiple mixed, no label
@@ -95,4 +95,3 @@ like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok');
like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok');
like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok');
#print $@;
-
diff --git a/t/Monitoring-Plugin-Performance-02.t b/t/Monitoring-Plugin-Performance-02.t
new file mode 100644
index 0000000..c024685
--- /dev/null
+++ b/t/Monitoring-Plugin-Performance-02.t
@@ -0,0 +1,13 @@
+
+use strict;
+use Test::More tests => 3;
+use_ok("Monitoring::Plugin::Performance", use_die => 1);
+
+eval { Monitoring::Plugin::Functions::plugin_die("Testing") };
+is( $@, "MONITORING-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
+
+
+use_ok("Monitoring::Plugin::Performance");
+eval { Monitoring::Plugin::Functions::plugin_die("Test OK exit", 0) };
+
+fail("Should not get here if code works correctly because prior plugin_die should have exited");
diff --git a/t/Nagios-Plugin-Performance.t b/t/Monitoring-Plugin-Performance.t
similarity index 79%
rename from t/Nagios-Plugin-Performance.t
rename to t/Monitoring-Plugin-Performance.t
index 8dce336..bedb2e2 100644
--- a/t/Nagios-Plugin-Performance.t
+++ b/t/Monitoring-Plugin-Performance.t
@@ -2,61 +2,61 @@
use warnings;
use strict;
use Test::More;
-use Nagios::Plugin::Functions;
-Nagios::Plugin::Functions::_fake_exit(1);
+use Monitoring::Plugin::Functions;
+Monitoring::Plugin::Functions::_fake_exit(1);
my (@p, $p);
my @test = (
- {
+ {
perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root",
}, {
perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var",
}, {
perfoutput => '/var/long@:-/filesystem/name/and/bad/chars=218MB;9443;9448', label => '/var/long@:-/filesystem/name/and/bad/chars', rrdlabel => 'var_long____filesys', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => 'var_long____filesystem_name_and_bad_chars',
}, {
- perfoutput => "'page file'=36%;80;90;",
+ perfoutput => "'page file'=36%;80;90;",
expected_perfoutput => "'page file'=36%;80;90",
label => 'page file',
rrdlabel => 'page_file',
- value => '36',
- uom => '%',
- warning => 80,
- critical => 90,
- min => undef,
- max => undef,
+ value => '36',
+ uom => '%',
+ warning => 80,
+ critical => 90,
+ min => undef,
+ max => undef,
clean_label => 'page_file',
}, {
- perfoutput => "'data'=5;;;;",
+ perfoutput => "'data'=5;;;;",
expected_perfoutput => "data=5;;",
label => 'data',
rrdlabel => 'data',
value => 5,
uom => "",
- warning => undef,
- critical => undef,
- min => undef,
- max => undef,
+ warning => undef,
+ critical => undef,
+ min => undef,
+ max => undef,
clean_label => 'data',
},
);
plan tests => (11 * scalar @test) + 176;
-use_ok('Nagios::Plugin::Performance');
-diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
+use_ok('Monitoring::Plugin::Performance');
+diag "\nusing Monitoring::Plugin::Performance revision ". $Monitoring::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
# Round-trip tests
for my $t (@test) {
# Parse to components
- ($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput});
+ ($p) = Monitoring::Plugin::Performance->parse_perfstring($t->{perfoutput});
is ($p->value, $t->{value}, "value okay $t->{value}");
is ($p->label, $t->{label}, "label okay $t->{label}");
is ($p->uom, $t->{uom}, "uom okay $t->{uom}");
# Construct from components
my @construct = qw(label value uom warning critical min max);
- $p = Nagios::Plugin::Performance->new(map { $_ => $t->{$_} } @construct);
+ $p = Monitoring::Plugin::Performance->new(map { $_ => $t->{$_} } @construct);
my $expected_perfoutput = $t->{perfoutput};
if (exists $t->{expected_perfoutput}) {
$expected_perfoutput = $t->{expected_perfoutput};
@@ -75,9 +75,9 @@ for my $t (@test) {
# Construct using threshold
@construct = qw(label value uom min max);
- $p = Nagios::Plugin::Performance->new(
- map({ $_ => $t->{$_} } @construct),
- threshold => Nagios::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}),
+ $p = Monitoring::Plugin::Performance->new(
+ map({ $_ => $t->{$_} } @construct),
+ threshold => Monitoring::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}),
);
is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)");
# Check warning/critical accessors
@@ -92,7 +92,7 @@ for my $t (@test) {
# Test multiple parse_perfstrings
- at p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
cmp_ok( $p[0]->label, 'eq', "/", "label okay");
cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay");
cmp_ok( $p[0]->value, '==', 382, "value okay");
@@ -109,14 +109,14 @@ cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay");
cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay");
cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay");
- at p = Nagios::Plugin::Performance->parse_perfstring("rubbish");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("rubbish");
ok( ! @p, "Errors correctly");
-ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string");
+ok( ! Monitoring::Plugin::Performance->parse_perfstring(""), "Errors on empty string");
# Check 1 bad with 1 good format output
- at p = Nagios::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 ");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 ");
is( scalar @p, 1, "One bad piece of data - only one returned" );
is( $p[0]->label, "pl", "label okay for different numeric");
is( $p[0]->value, 0, "value okay");
@@ -127,7 +127,7 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
is( $p[0]->threshold->critical, "60", "warn okay");
# Same as above, but order swapped
- at p = Nagios::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; ");
+ at p = Monitoring::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; ");
is( scalar @p, 1, "One bad piece of data - only one returned" );
is( $p[0]->label, "pl", "label okay for different numeric");
is( $p[0]->value, 0, "value okay");
@@ -140,7 +140,7 @@ is( $p[0]->threshold->critical, "60", "warn okay");
- at p = Nagios::Plugin::Performance->parse_perfstring(
+ at p = Monitoring::Plugin::Performance->parse_perfstring(
"time=0.001229s;0.000000;0.000000;0.000000;10.000000");
cmp_ok( $p[0]->label, "eq", "time", "label okay");
cmp_ok( $p[0]->value, "==", 0.001229, "value okay");
@@ -150,27 +150,27 @@ cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
- at p = Nagios::Plugin::Performance->parse_perfstring(
+ at p = Monitoring::Plugin::Performance->parse_perfstring(
"load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;");
cmp_ok( $p[0]->label, "eq", "load1", "label okay");
-cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string");
+cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string");
cmp_ok( $p[0]->uom, "eq", "", "uom empty");
cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay");
cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay");
cmp_ok( $p[1]->label, "eq", "load5", "label okay");
cmp_ok( $p[2]->label, "eq", "load15", "label okay");
- at p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" );
+ at p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0" );
cmp_ok( $p[0]->label, "eq", "users", "label okay");
cmp_ok( $p[0]->value, "==", 4, "value okay");
cmp_ok( $p[0]->uom, "eq", "", "uom empty");
cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay");
cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay");
- at p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" );
+ at p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" );
ok( @p, "parse correctly with linefeed at end (nagiosgraph)");
- at p = Nagios::Plugin::Performance->parse_perfstring(
+ at p = Monitoring::Plugin::Performance->parse_perfstring(
"time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" );
cmp_ok( $p[0]->label, "eq", "time", "label okay");
cmp_ok( $p[0]->value, "eq", "0.2153", "value okay");
@@ -184,21 +184,21 @@ cmp_ok( $p[1]->uom, "eq", "B", "uom okay");
ok( ! $p[1]->threshold->critical->is_set, "crit okay");
# Edge cases
- at p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20");
cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _");
ok( $p[0]->threshold->warning->is_set, "Warning range has been set");
cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters");
cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label");
-# turn off fake_exit and enable use_die so we pick up on errors via nagios_die
-Nagios::Plugin::Functions::_use_die(1);
-Nagios::Plugin::Functions::_fake_exit(0);
+# turn off fake_exit and enable use_die so we pick up on errors via plugin_die
+Monitoring::Plugin::Functions::_use_die(1);
+Monitoring::Plugin::Functions::_fake_exit(0);
- at p = Nagios::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000");
cmp_ok( $p[0]->label, "eq", "time", "label okay");
cmp_ok( $p[0]->value, "eq", "0.002722", "value okay");
cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
- ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set");
+ ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set");
ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set");
# The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification
# of 0. See http://rt.cpan.org/Ticket/Display.html?id=41109
@@ -206,7 +206,7 @@ cmp_ok( $p[0]->uom, "eq", "s", "uom okay");
is( $p[0]->threshold->warning."", "0", "warn okay");
is( $p[0]->threshold->critical."", "0", "crit okay");
- at p = Nagios::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95");
cmp_ok( $p[0]->label, "eq", "pct_used", "label okay");
cmp_ok( $p[0]->value, "eq", "73.7", "value okay");
cmp_ok( $p[0]->uom, "eq", "%", "uom okay");
@@ -216,7 +216,7 @@ cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay");
cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay");
# Check ranges are parsed correctly
- at p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;");
is( $p[0]->label, "availability", "label okay");
is( $p[0]->value, "93.8", "value okay");
is( $p[0]->uom, "%", "uom okay");
@@ -225,7 +225,7 @@ is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set");
is( $p[0]->threshold->warning, "90:99", "warn okay");
# Check that negative values are parsed correctly in value and ranges
- at p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;");
is( $p[0]->label, "offset", "label okay");
is( $p[0]->value, "-0.004476", "value okay");
is( $p[0]->uom, "s", "uom okay");
@@ -235,7 +235,7 @@ is( $p[0]->threshold->warning, "-60:-5", "warn okay");
is( $p[0]->threshold->critical, "-120:-3", "crit okay");
# Check infinity values are okay
- at p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:");
is( $p[0]->label, "salary", "label okay");
is( $p[0]->value, "52", "value okay");
is( $p[0]->uom, "GBP", "uom okay");
@@ -245,7 +245,7 @@ is( $p[0]->threshold->warning, "~:23.5", "warn okay");
is( $p[0]->threshold->critical, "45.2:", "warn okay");
# Check scientific notation
- at p = Nagios::Plugin::Performance->parse_perfstring("offset=1.120567322e-05");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("offset=1.120567322e-05");
is( $p[0]->label, "offset", "label okay for scientific notation");
is( $p[0]->value, 1.120567322e-05, "value okay");
is( $p[0]->uom, "", "uom okay");
@@ -254,7 +254,7 @@ ok( ! $p[0]->threshold->critical->is_set, "Critical range has not been set");
# Check scientific notation with warnings and criticals
- at p = Nagios::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25");
is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals");
is( $p[0]->value, -1.120567322e-05, "value okay");
is( $p[0]->uom, "unit", "uom okay");
@@ -266,7 +266,7 @@ is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay");
# Check different collation with commas instead of periods
- at p = Nagios::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;");
is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods");
is( $p[0]->value, 1.391, "value okay");
is( $p[0]->uom, "ms", "uom okay");
@@ -284,7 +284,7 @@ is( $p[1]->threshold->critical, "60", "warn okay");
# Another set of comma separated stuff
- at p = Nagios::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;");
is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods");
is( $p[0]->value, -0.023545, "value okay");
is( $p[0]->uom, "s", "uom okay");
@@ -294,14 +294,14 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
is( $p[0]->threshold->critical, 120, "warn okay");
# Some values with funny commas
- at p = Nagios::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6");
is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6");
is( $p[0]->value, 45.6, "value okay");
is( $p[0]->uom, "", "uom okay");
# Test labels with spaces (returned by nsclient++)
- at p = Nagios::Plugin::Performance->parse_perfstring("'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 'D:\ Label: Serial Number XA22aa2e'=8015MB;16388;18436;1;2048");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 'D:\ Label: Serial Number XA22aa2e'=8015MB;16388;18436;1;2048");
is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e");
is( $p[0]->rrdlabel, "C__Label___Serial_N");
is( $p[0]->value, 8015, "value okay");
@@ -322,7 +322,7 @@ is( $p[1]->max, 2048, "max ok");
# Mix labels with and without quotes
- at p = Nagios::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 ");
+ at p = Monitoring::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 ");
is( $p[0]->label, "short" );
is( $p[0]->rrdlabel, "short");
is( $p[0]->value, 4, "value okay");
@@ -351,7 +351,7 @@ is( $p[2]->min, undef, "min ok");
is( $p[2]->max, undef, "max ok");
- at p = Nagios::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9=");
+ at p = Monitoring::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9=");
is_deeply( \@p, [], "Fails parsing correctly");
-# add_perfdata tests in t/Nagios-Plugin-01.t
+# add_perfdata tests in t/Monitoring-Plugin-01.t
diff --git a/t/Nagios-Plugin-Range.t b/t/Monitoring-Plugin-Range.t
similarity index 87%
rename from t/Nagios-Plugin-Range.t
rename to t/Monitoring-Plugin-Range.t
index 6fe080c..9a6e826 100644
--- a/t/Nagios-Plugin-Range.t
+++ b/t/Monitoring-Plugin-Range.t
@@ -1,15 +1,15 @@
use strict;
-#use Test::More qw(no_plan);
+#use Test::More qw(no_plan);
use Test::More tests => 151;
-BEGIN {
- use_ok('Nagios::Plugin::Range');
+BEGIN {
+ use_ok('Monitoring::Plugin::Range');
# Silence warnings unless TEST_VERBOSE is set
$SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} };
};
-diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE};
+diag "\nusing Monitoring::Plugin::Range revision ". $Monitoring::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE};
my $r;
@@ -25,14 +25,14 @@ foreach (qw(
), '1,10' # avoid warning about using , inside qw()
) {
- $r =Nagios::Plugin::Range->parse_range_string($_);
+ $r =Monitoring::Plugin::Range->parse_range_string($_);
is $r, undef, "'$_' should not be a valid range" ;
}
diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string("6");
-isa_ok( $r, "Nagios::Plugin::Range");
+$r = Monitoring::Plugin::Range->parse_range_string("6");
+isa_ok( $r, "Monitoring::Plugin::Range");
ok( defined $r, "'6' is valid range");
cmp_ok( $r->start, '==', 0, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -53,7 +53,7 @@ sub test_expected {
my $r = shift;
my $expected = shift;
foreach (sort {$a<=>$b} keys %$expected) {
- is $r->check_range($_), $expected->{$_},
+ is $r->check_range($_), $expected->{$_},
" $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")";
}
}
@@ -61,7 +61,7 @@ sub test_expected {
test_expected( $r, $expected );
diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string("-7:23");
+$r = Monitoring::Plugin::Range->parse_range_string("-7:23");
ok( defined $r, "'-7:23' is valid range");
cmp_ok( $r->start, '==', -7, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -72,7 +72,7 @@ cmp_ok( $r, 'eq', "-7:23", "Stringification back to original");
$expected = {
-23 => 1,
-7 => 0,
- -1 => 0,
+ -1 => 0,
0 => 0,
4 => 0,
23 => 0,
@@ -83,7 +83,7 @@ test_expected( $r, $expected );
diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string(":5.75");
+$r = Monitoring::Plugin::Range->parse_range_string(":5.75");
ok( defined $r, "':5.75' is valid range");
cmp_ok( $r->start, '==', 0, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -105,7 +105,7 @@ test_expected( $r, $expected );
diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string("~:-95.99");
+$r = Monitoring::Plugin::Range->parse_range_string("~:-95.99");
ok( defined $r, "'~:-95.99' is valid range");
cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
cmp_ok( $r->end, '==', -95.99, "End correct");
@@ -126,7 +126,7 @@ test_expected( $r, $expected );
diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE};
test_expected( $r, $expected );
-$r = Nagios::Plugin::Range->parse_range_string("10:");
+$r = Monitoring::Plugin::Range->parse_range_string("10:");
ok( defined $r, "'10:' is valid range");
cmp_ok( $r->start, '==', 10, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -147,7 +147,7 @@ test_expected( $r, $expected );
diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE};
test_expected( $r, $expected );
-$r = Nagios::Plugin::Range->parse_range_string("123456789012345:");
+$r = Monitoring::Plugin::Range->parse_range_string("123456789012345:");
ok( defined $r, "'123456789012345:' is valid range");
cmp_ok( $r->start, '==', 123456789012345, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -159,7 +159,7 @@ $expected = {
0 => 1,
# The fractional values needs to be quoted, otherwise the hash rounds it up to ..345
# and there is one less test run.
- # I think some newer versions of perl use a higher precision value for the hash key.
+ # I think some newer versions of perl use a higher precision value for the hash key.
# This doesn't appear to affect the actual plugin though
"123456789012344.91" => 1,
123456789012345 => 0,
@@ -170,7 +170,7 @@ test_expected( $r, $expected );
diag "range: <= zero " if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string("~:0");
+$r = Monitoring::Plugin::Range->parse_range_string("~:0");
ok( defined $r, "'~:0' is valid range");
cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
cmp_ok( $r->end, '==', 0, "End correct");
@@ -191,7 +191,7 @@ test_expected( $r, $expected );
diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567');
+$r = Monitoring::Plugin::Range->parse_range_string('@0:657.8210567');
ok( defined $r, '"@0:657.8210567" is a valid range');
cmp_ok( $r->start, '==', 0, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -216,7 +216,7 @@ test_expected( $r, $expected );
diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE};
-$r = Nagios::Plugin::Range->parse_range_string('1:1');
+$r = Monitoring::Plugin::Range->parse_range_string('1:1');
ok( defined $r, '"1:1" is a valid range');
cmp_ok( $r->start, '==', 1, "Start correct");
cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
@@ -237,7 +237,7 @@ $expected = {
test_expected( $r, $expected );
-$r = Nagios::Plugin::Range->parse_range_string('2:1');
+$r = Monitoring::Plugin::Range->parse_range_string('2:1');
ok( ! defined $r, '"2:1" is rejected');
# TODO: Need more tests for invalid data
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Monitoring-Plugin-Threshold.t
similarity index 78%
rename from t/Nagios-Plugin-Threshold.t
rename to t/Monitoring-Plugin-Threshold.t
index 78d2189..8849464 100644
--- a/t/Nagios-Plugin-Threshold.t
+++ b/t/Monitoring-Plugin-Threshold.t
@@ -1,32 +1,32 @@
use strict;
use Test::More tests => 93;
-BEGIN {
- use_ok('Nagios::Plugin::Threshold');
- use_ok('Nagios::Plugin::Functions', ':all' );
+BEGIN {
+ use_ok('Monitoring::Plugin::Threshold');
+ use_ok('Monitoring::Plugin::Functions', ':all' );
# Silence warnings unless TEST_VERBOSE is set
$SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} };
}
-diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n"
+diag "\nusing Monitoring::Plugin::Threshold revision ". $Monitoring::Plugin::Threshold::VERSION . "\n"
if $ENV{TEST_VERBOSE};
-Nagios::Plugin::Functions::_fake_exit(1);
+Monitoring::Plugin::Functions::_fake_exit(1);
my $t;
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => undef, critical => undef);
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => undef, critical => undef);
ok( defined $t, "two undefs" );
ok( ! $t->warning->is_set, "warning not set" );
ok( ! $t->critical->is_set, "critical not set" );
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => "", critical => "");
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "", critical => "");
ok( defined $t, "two empty strings" );
ok( ! $t->warning->is_set, "warning not set" );
ok( ! $t->critical->is_set, "critical not set" );
diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE};
-my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80");
+my $t = Monitoring::Plugin::Threshold->set_thresholds(critical => "80");
ok( defined $t, "Threshold ('', '80') set");
ok( ! $t->warning->is_set, "Warning not set");
cmp_ok( $t->critical->start, '==', 0, "Critical strat set correctly");
@@ -59,11 +59,11 @@ sub test_expected_statuses {
}
test_expected_statuses( $t, $expected );
-# GMC: this test seems bogus to me - either we've died, in which case internal
+# GMC: this test seems bogus to me - either we've died, in which case internal
# state is undefined (and untestable!), or we should be returning a non-fatal error
if (0) {
diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
- eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") };
+ eval { $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") };
ok( defined $t, "Threshold ('5:33', '') set");
cmp_ok( $t->warning->start, '==', 5, "Warning start set");
cmp_ok( $t->warning->end, '==', 33, "Warning end set");
@@ -72,7 +72,7 @@ if (0) {
# GC: same as previous test, except critical is undef instead of ''
diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef);
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef);
ok( defined $t, "Threshold ('5:33', '') set");
cmp_ok( $t->warning->start, '==', 5, "Warning start set");
cmp_ok( $t->warning->end, '==', 33, "Warning end set");
@@ -91,7 +91,7 @@ $expected = { qw(
test_expected_statuses( $t, $expected );
diag "threshold: warn if more than 30; critical if > 60" if $ENV{TEST_VERBOSE};
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60");
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60");
ok( defined $t, "Threshold ('~:30', '~:60') set");
cmp_ok( $t->warning->end, '==', 30, "Warning end set");
cmp_ok( $t->critical->end, '==',60, "Critical end set");
@@ -118,23 +118,23 @@ test_expected_statuses( $t, $expected );
goto SKIP_DEATH;
diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE};
diag "you should see one invalid range definition warning and an UNKNOWN line here:\n";
-Nagios::Plugin::Functions->print_on_die(1);
-Nagios::Plugin::Functions->exit_on_die(1);
+Monitoring::Plugin::Functions->print_on_die(1);
+Monitoring::Plugin::Functions->exit_on_die(1);
dies_ok( sub {
- $t = Nagios::Plugin::Threshold->set_thresholds(
- warning => "total",
+ $t = Monitoring::Plugin::Threshold->set_thresholds(
+ warning => "total",
critical => "rubbish"
)
- }, "bad thresholds cause death"
+ }, "bad thresholds cause death"
);
-Nagios::Plugin::Functions->print_on_die(0);
-Nagios::Plugin::Functions->exit_on_die(0);
+Monitoring::Plugin::Functions->print_on_die(0);
+Monitoring::Plugin::Functions->exit_on_die(0);
SKIP_DEATH:
diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE};
-$t = Nagios::Plugin::Threshold->set_thresholds( critical => "~:25" );
+$t = Monitoring::Plugin::Threshold->set_thresholds( critical => "~:25" );
ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" );
ok( ! $t->warning->is_set, "Warning not set");
cmp_ok( $t->critical->end, '==',25, "Critical end set");
@@ -145,14 +145,14 @@ $expected = { qw(
4 OK
10 OK
14.21 OK
- 25 OK
+ 25 OK
25.01 CRITICAL
31001 CRITICAL
) };
test_expected_statuses( $t, $expected);
diag "threshold: warn if OUTSIDE {10..25} , critical if > 25 " if $ENV{TEST_VERBOSE};
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25");
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25");
ok( defined $t, "Threshold ('10:25', '~:25') set");
cmp_ok( $t->warning->start, '==', 10, "Warning start set");
cmp_ok( $t->warning->end, '==', 25, "Warning end set");
@@ -164,7 +164,7 @@ $expected = { qw(
9.999999 WARNING
10 OK
14.21 OK
- 25 OK
+ 25 OK
25.01 CRITICAL
31001 CRITICAL
) };
@@ -172,7 +172,7 @@ test_expected_statuses( $t, $expected );
diag "warn if INSIDE {10..25} , critical if < 10 " if $ENV{TEST_VERBOSE};
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:");
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:");
$expected = { qw(
-1 CRITICAL
4 CRITICAL
@@ -187,7 +187,7 @@ test_expected_statuses( $t, $expected );
# GMC: as of 0.16, set_thresholds can also be called as a mutator
-diag "threshold mutator: warn if more than 30; critical if > 60"
+diag "threshold mutator: warn if more than 30; critical if > 60"
if $ENV{TEST_VERBOSE};
my $t1 = $t;
$t->set_thresholds(warning => "0:45", critical => "0:90");
@@ -200,16 +200,16 @@ is( $t->critical->end, 90, "Critical end ok");
# Also as of 0.16, accepts N::P::Range objects as arguments
-my $warning = Nagios::Plugin::Range->parse_range_string("50");
-my $critical = Nagios::Plugin::Range->parse_range_string("70:90");
-$t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
+my $warning = Monitoring::Plugin::Range->parse_range_string("50");
+my $critical = Monitoring::Plugin::Range->parse_range_string("70:90");
+$t = Monitoring::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
ok( defined $t, "Threshold from ranges ('50', '70:90') set");
is( $t->warning->start, 0, "Warning start ok");
is( $t->warning->end, 50, "Warning end ok");
is( $t->critical->start, 70, "Critical start ok");
is( $t->critical->end, 90, "Critical end ok");
-$critical = Nagios::Plugin::Range->parse_range_string("90:");
+$critical = Monitoring::Plugin::Range->parse_range_string("90:");
$t->set_thresholds(warning => "~:20", critical => $critical);
ok( defined $t, "Threshold from string + range ('~:20', '90:') set");
ok( $t->warning->start_infinity, "Warning start ok (infinity)");
diff --git a/t/Nagios-Plugin-02.t b/t/Nagios-Plugin-02.t
deleted file mode 100644
index f64fb6f..0000000
--- a/t/Nagios-Plugin-02.t
+++ /dev/null
@@ -1,161 +0,0 @@
-# Nagios::Plugin test set 2, testing NP::Functions wrapping
-
-use strict;
-use Test::More tests => 103;
-
-BEGIN { use_ok("Nagios::Plugin") }
-require Nagios::Plugin::Functions;
-Nagios::Plugin::Functions::_fake_exit(1);
-
-# Hardcoded checks of constants
-my %ERRORS = %Nagios::Plugin::Functions::ERRORS;
-is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
-is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
-is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
-is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
-is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
-
-my $plugin = 'TEST_PLUGIN';
-my $np = Nagios::Plugin->new( shortname => $plugin );
-is($np->shortname, $plugin, "shortname() is $plugin");
-
-# Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg )
-my $r;
-my @ok = (
- [ OK, "OK", 'test the first', ],
- [ WARNING, "WARNING", 'test the second', ],
- [ CRITICAL, "CRITICAL", 'test the third', ],
- [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
- [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
-);
-for (@ok) {
- # CONSTANT
- $r = $np->nagios_exit($_->[0], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"', $_->[1],
- $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
-
- # $string
- $r = $np->nagios_exit($_->[1], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1],
- $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
- like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1],
- $plugin . ' ' . $_->[1] . '.*' . $_->[2]));
-}
-
-# nagios_exit code corner cases
-my @ugly1 = (
- [ -1, 'testing code -1' ],
- [ 7, 'testing code 7' ],
- [ undef, 'testing code undef' ],
- [ '', qq(testing code '') ],
- [ 'string', qq(testing code 'string') ],
-);
-for (@ugly1) {
- $r = $np->nagios_exit($_->[0], $_->[1]);
- my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
- is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN);
- like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"',
- $display, 'UNKNOWN.*' . $_->[1]));
-}
-
-# nagios_exit message corner cases
-my @ugly2 = (
- [ '' ],
- [ undef ],
- [ UNKNOWN ],
-);
-for (@ugly2) {
- $r = $np->nagios_exit(CRITICAL, $_->[0]);
- my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
- my $display2 = defined $_->[0] ? $_->[0] : '';
- like($r->message, qr/CRITICAL\b.*\b$display2$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"',
- $display1, "CRITICAL.*$display2"));
-}
-
-# Test nagios_die( $msg )
-my @msg = (
- [ 'die you dog' ],
- [ '' ],
- [ undef ],
-);
-for (@msg) {
- $r = $np->nagios_die($_->[0]);
- my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
- my $display2 = defined $_->[0] ? $_->[0] : '';
- is($r->return_code, UNKNOWN,
- sprintf('nagios_die(%s) returned UNKNOWN', $display1));
- like($r->message, qr/UNKNOWN\b.*\b$display2$/,
- sprintf('nagios_die(%s) output matched "%s"', $display1,
- "UNKNOWN.*$display2"));
-}
-
-# Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ),
-# nagios_die( $string, $msg ), and nagios_die( $msg, $string )
- at ok = (
- [ OK, "OK", 'test the first', ],
- [ WARNING, "WARNING", 'test the second', ],
- [ CRITICAL, "CRITICAL", 'test the third', ],
- [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
- [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
-);
-for (@ok) {
- # CONSTANT, $msg
- $r = $np->nagios_die($_->[0], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die(%s, $msg) output matched "%s"',
- $_->[1], $_->[1] . '.*' . $_->[2]));
-
- # $msg, CONSTANT
- $r = $np->nagios_die($_->[2], $_->[0]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, %s) output matched "%s"',
- $_->[1], $_->[1] . '.*' . $_->[2]));
-
- # $string, $msg
- $r = $np->nagios_die($_->[1], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
- like($r, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
-
- # $string, $msg
- $r = $np->nagios_die($_->[2], $_->[1]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
- like($r, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
-}
-
-
-# shortname testing
-SKIP: {
- skip "requires File::Basename", 2 unless eval { require File::Basename };
- $np = Nagios::Plugin->new( version => "1");
- $plugin = uc File::Basename::basename($0);
- $plugin =~ s/\..*$//;
- is($np->shortname, $plugin, "shortname() is '$plugin'");
- $r = $np->nagios_exit(OK, "foobar");
- like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'");
-}
-
diff --git a/t/Nagios-Plugin-Functions-01.t b/t/Nagios-Plugin-Functions-01.t
deleted file mode 100644
index 5268255..0000000
--- a/t/Nagios-Plugin-Functions-01.t
+++ /dev/null
@@ -1,161 +0,0 @@
-
-use strict;
-use Test::More tests => 113;
-
-BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); }
-Nagios::Plugin::Functions::_fake_exit(1);
-
-my $this_version=$Nagios::Plugin::Functions::VERSION;
-foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) {
- my $mod = "Nagios::Plugin$m";
- use_ok($mod);
- # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing
- my $v = "$mod"."::VERSION";
- my $a = eval "\$$v";
- is($a, $this_version, "Version number for $mod the same as Functions: $this_version");
-}
-
-# check get_shortname
-is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok");
-
-# Hardcoded checks of constants
-ok(defined %ERRORS, '%ERRORS defined');
-is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
-is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
-is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
-is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}");
-is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}");
-
-# Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg )
-my $r;
-my @ok = (
- [ OK, "OK", 'test the first', ],
- [ WARNING, "WARNING", 'test the second', ],
- [ CRITICAL, "CRITICAL", 'test the third', ],
- [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
- [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
-);
-for (@ok) {
- # CONSTANT
- $r = nagios_exit($_->[0], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"',
- $_->[1], $_->[1] . '.*' . $_->[2]));
-
- # $string
- $r = nagios_exit($_->[1], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
- like($r, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
-}
-
-# nagios_exit code corner cases
-my @ugly1 = (
- [ -1, 'testing code -1' ],
- [ 7, 'testing code 7' ],
- [ undef, 'testing code undef' ],
- [ '', qq(testing code '') ],
- [ 'string', qq(testing code 'string') ],
-);
-for (@ugly1) {
- $r = nagios_exit($_->[0], $_->[1]);
- my $display = defined $_->[0] ? "'$_->[0]'" : 'undef';
- is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN);
- like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"',
- $display, 'UNKNOWN.*' . $_->[1]));
-}
-
-# nagios_exit message corner cases
-my @ugly2 = (
- [ '' ],
- [ undef ],
- [ UNKNOWN ],
-);
-for (@ugly2) {
- $r = nagios_exit(CRITICAL, $_->[0]);
- my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
- my $display2 = defined $_->[0] ? $_->[0] : '';
- like($r->message, qr/CRITICAL\b.*\b$display2$/,
- sprintf('nagios_exit(%s, $msg) output matched "%s"',
- $display1, "CRITICAL.*$display2"));
-}
-
-# Test nagios_die( $msg )
-my @msg = (
- [ 'die you dog' ],
- [ '' ],
- [ undef ],
-);
-for (@msg) {
- $r = nagios_die($_->[0]);
- my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef";
- my $display2 = defined $_->[0] ? $_->[0] : '';
- is($r->return_code, UNKNOWN,
- sprintf('nagios_die(%s) returned UNKNOWN', $display1));
- like($r->message, qr/UNKNOWN\b.*\b$display2$/,
- sprintf('nagios_die(%s) output matched "%s"', $display1,
- "UNKNOWN.*$display2"));
-}
-
-# Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ),
-# nagios_die( $string, $msg ), and nagios_die( $msg, $string )
- at ok = (
- [ OK, "OK", 'test the first', ],
- [ WARNING, "WARNING", 'test the second', ],
- [ CRITICAL, "CRITICAL", 'test the third', ],
- [ UNKNOWN, "UNKNOWN", 'test the fourth', ],
- [ DEPENDENT, "DEPENDENT", 'test the fifth', ],
-);
-for (@ok) {
- # CONSTANT, $msg
- $r = nagios_die($_->[0], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die(%s, $msg) output matched "%s"',
- $_->[1], $_->[1] . '.*' . $_->[2]));
-
- # $msg, CONSTANT
- $r = nagios_die($_->[2], $_->[0]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, %s) output matched "%s"',
- $_->[1], $_->[1] . '.*' . $_->[2]));
-
- # $string, $msg
- $r = nagios_die($_->[1], $_->[2]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
- like($r, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
-
- # $string, $msg
- $r = nagios_die($_->[2], $_->[1]);
- is($r->return_code, $_->[0],
- sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0]));
- like($r->message, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
- like($r, qr/$_->[1]\b.*\b$_->[2]$/,
- sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1],
- $_->[1] . '.*' . $_->[2]));
-}
-
-# Check that _use_die set to 1 will catch exceptions correctly
-Nagios::Plugin::Functions::_fake_exit(0);
-Nagios::Plugin::Functions::_use_die(1);
-eval { nagios_die("Using die") };
-is( $@, "NAGIOS-PLUGIN-FUNCTIONS-01 UNKNOWN - Using die\n", "Caught exception");
diff --git a/t/Nagios-Plugin-Performance-02.t b/t/Nagios-Plugin-Performance-02.t
deleted file mode 100644
index c0c5a71..0000000
--- a/t/Nagios-Plugin-Performance-02.t
+++ /dev/null
@@ -1,13 +0,0 @@
-
-use strict;
-use Test::More tests => 3;
-use_ok("Nagios::Plugin::Performance", use_die => 1);
-
-eval { Nagios::Plugin::Functions::nagios_die("Testing") };
-is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import");
-
-
-use_ok("Nagios::Plugin::Performance");
-eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) };
-
-fail("Should not get here if code works correctly because prior nagios_die should have exited");
diff --git a/t/check_stuff.pl b/t/check_stuff.pl
index 112a18a..4fc125c 100755
--- a/t/check_stuff.pl
+++ b/t/check_stuff.pl
@@ -2,21 +2,21 @@
### check_stuff.pl
-# an example Nagios plugin using the Nagios::Plugin modules.
+# an example Monitoring plugin using the Monitoring::Plugin modules.
# Originally by Nathan Vonnahme, n8v at users dot sourceforge
# dot net, July 19 2006
# Please modify to your heart's content and use as the basis for all
-# the really cool Nagios monitoring scripts you're going to create.
-# You rock.
+# the really cool monitoring scripts you're going to create.
+# You rock.
##############################################################################
# prologue
use strict;
use warnings;
-use Nagios::Plugin ;
+use Monitoring::Plugin;
use vars qw($VERSION $PROGNAME $verbose $warn $critical $timeout $result);
$VERSION = '1.0';
@@ -28,18 +28,18 @@ $PROGNAME = basename($0);
##############################################################################
# define and get the command line options.
-# see the command line option guidelines at
-# http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS
+# see the command line option guidelines at
+# https://www.monitoring-plugins.org/doc/guidelines.html#PLUGOPTIONS
-# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory)
-my $p = Nagios::Plugin->new(
+# Instantiate Monitoring::Plugin object (the 'usage' parameter is mandatory)
+my $p = Monitoring::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>]
- [ -c|--critical=<critical threshold> ]
- [ -w|--warning=<warning threshold> ]
+ [ -c|--critical=<critical threshold> ]
+ [ -w|--warning=<warning threshold> ]
[ -r|--result = <INTEGER> ]",
version => $VERSION,
- blurb => 'This plugin is an example of a Nagios plugin written in Perl using the Nagios::Plugin modules. It will generate a random integer between 1 and 20 (though you can specify the number with the -n option for testing), and will output OK, WARNING or CRITICAL if the resulting number is outside the specified thresholds.',
+ blurb => 'This plugin is an example of a monitoring plugin written in Perl using the Monitoring::Plugin modules. It will generate a random integer between 1 and 20 (though you can specify the number with the -n option for testing), and will output OK, WARNING or CRITICAL if the resulting number is outside the specified thresholds.',
extra => "
@@ -47,11 +47,7 @@ THRESHOLDs for -w and -c are specified 'min:max' or 'min:' or ':max'
(or 'max'). If specified '\@min:max', a warning status will be generated
if the count *is* inside the specified range.
-See more threshold examples at http
- : // nagiosplug
- . sourceforge
- . net / developer-guidelines
- . html #THRESHOLDFORMAT
+See more threshold examples at https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
Examples:
@@ -75,7 +71,7 @@ See more threshold examples at http
$p->add_arg(
spec => 'warning|w=s',
- help =>
+ help =>
qq{-w, --warning=INTEGER:INTEGER
Minimum and maximum number of allowable result, outside of which a
warning will be generated. If omitted, no warning is generated.},
@@ -86,7 +82,7 @@ qq{-w, --warning=INTEGER:INTEGER
$p->add_arg(
spec => 'critical|c=s',
- help =>
+ help =>
qq{-c, --critical=INTEGER:INTEGER
Minimum and maximum number of the generated result, outside of
which a critical will be generated. },
@@ -94,7 +90,7 @@ qq{-c, --critical=INTEGER:INTEGER
$p->add_arg(
spec => 'result|r=f',
- help =>
+ help =>
qq{-r, --result=INTEGER
Specify the result on the command line rather than generating a
random number. For testing.},
@@ -106,11 +102,11 @@ $p->getopts;
# perform sanity checking on command line options
if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) {
- $p->nagios_die( " invalid number supplied for the -r option " );
+ $p->plugin_die( " invalid number supplied for the -r option " );
}
unless ( defined $p->opts->warning || defined $p->opts->critical ) {
- $p->nagios_die( " you didn't supply a threshold argument " );
+ $p->plugin_die( " you didn't supply a threshold argument " );
}
@@ -135,8 +131,7 @@ else {
##############################################################################
# check the result against the defined warning and critical thresholds,
# output the result and exit
-$p->nagios_exit(
- return_code => $p->check_threshold($result),
- message => " sample result was $result"
+$p->plugin_exit(
+ return_code => $p->check_threshold($result),
+ message => " sample result was $result"
);
-
diff --git a/t/check_stuff.t b/t/check_stuff.t
index 2815b76..6a1d845 100755
--- a/t/check_stuff.t
+++ b/t/check_stuff.t
@@ -1,5 +1,5 @@
#!/usr/local/bin/perl
-#
+#
use strict; use warnings;
#use Test::More qw(no_plan);
use Test::More tests => 14;
@@ -10,7 +10,7 @@ $s = "$^X -Ilib $s";
my $n = 'STUFF';
-# Nagios status strings and exit codes
+# Monitoring status strings and exit codes
my %e = qw(
OK 0
WARNING 1
@@ -58,9 +58,3 @@ sub test_expected {
like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_";
}
}
-
-
-
-
-
-
diff --git a/t/npg03/README b/t/npg03/README
index 3dbdaf8..541ece7 100644
--- a/t/npg03/README
+++ b/t/npg03/README
@@ -1,15 +1,15 @@
-Nagios-Plugin-Getopt-03.t automatically tests all cases defined in
-the 'input' directory and expects the output to match the
-corresponding file in the 'expected' directory. To define a new test
-case, just create a new file in the 'input' directory containing the
-input command line, and a corresponding file in the 'expected'
-directory containing what you think the expanded command line should
+Monitoring-Plugin-Getopt-03.t automatically tests all cases defined in
+the 'input' directory and expects the output to match the
+corresponding file in the 'expected' directory. To define a new test
+case, just create a new file in the 'input' directory containing the
+input command line, and a corresponding file in the 'expected'
+directory containing what you think the expanded command line should
be. Note that this expansion is normalised as follows:
- command line arguments are reported in alphabetical order
- extraneous white space is removed
-Also, if you use a completely new argument than those currently
-defined in Nagios-Plugin-Getopt-03.t you will need to define it
+Also, if you use a completely new argument than those currently
+defined in Monitoring-Plugin-Getopt-03.t you will need to define it
there as well.
More information about the Commits
mailing list