From e63887eda6765e1059939ff9c89e4fb244b5819b Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Wed, 4 Oct 2006 22:02:39 +0000 Subject: Fix NP shortname defaulting; downgrade version requirements. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1489 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/MANIFEST b/MANIFEST index a0764e5..f46acd9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,6 +6,7 @@ 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-Functions-01.t t/Nagios-Plugin-Functions-02.t t/Nagios-Plugin-Getopt-01.t diff --git a/Makefile.PL b/Makefile.PL index 6da133a..275883f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,4 +1,4 @@ -use 5.008004; +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. @@ -6,10 +6,11 @@ WriteMakefile( NAME => 'Nagios::Plugin', VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION PREREQ_PM => { - Class::Struct => 0, - Params::Validate => 0.24, - Class::Accessor => 0.22, - Test::More => 0.62, + Class::Struct => 0, + Params::Validate => 0.24, + Class::Accessor => 0.22, + Test::More => 0.62, + Carp => 0, }, # 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 diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 5debdbc..29b79b9 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm @@ -12,8 +12,6 @@ struct "Nagios::__::Plugin" => { package Nagios::Plugin; use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); -use Nagios::Plugin::Performance; -use Nagios::Plugin::Threshold; use strict; use warnings; @@ -29,6 +27,7 @@ our $VERSION = $Nagios::Plugin::Functions::VERSION; sub add_perfdata { my ($self, %args) = @_; + require Nagios::Plugin::Performance; my $perf = Nagios::Plugin::Performance->new(%args); push @{$self->perfdata}, $perf; } @@ -37,7 +36,11 @@ sub all_perfoutput { return join(" ", map {$_->perfoutput} (@{$self->perfdata})); } -sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } +sub set_thresholds { + shift; + require Nagios::Plugin::Threshold; + Nagios::Plugin::Threshold->set_thresholds(@_); +} # NP::Functions wrappers sub nagios_exit { @@ -52,6 +55,13 @@ sub die { my $self = shift; Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); } +# Override default shortname accessor to add default +sub shortname { + my $self = shift; + $self->{'Nagios::__::Plugin::shortname'} = shift if @_; + return $self->{'Nagios::__::Plugin::shortname'} || + Nagios::Plugin::Functions::get_shortname(); +} # ------------------------------------------------------------------------- # NP::Functions::check_messages helpers and wrappers diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 9cb7eb6..804661c 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -1,7 +1,10 @@ -# This module holds all exported variables -# and base functions +# Functional interface to basic Nagios::Plugin constants, exports, +# and functions + package Nagios::Plugin::Functions; +use 5.006; + use strict; use warnings; use File::Basename; @@ -47,7 +50,8 @@ sub get_shortname { return $arg{plugin}->shortname if $arg{plugin}; my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); - $shortname =~ s/^CHECK_//; + $shortname =~ s/^CHECK_//; # Remove any leading CHECK_ + $shortname =~ s/\..*$//; # Remove any trailing suffix return $shortname; } diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index 38803a6..512e07d 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm @@ -1,6 +1,6 @@ package Nagios::Plugin::Performance; -use 5.008004; +use 5.006; use strict; use warnings; diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index f354a54..53a857f 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm @@ -1,6 +1,6 @@ package Nagios::Plugin::Range; -use 5.008004; +use 5.006; use strict; use warnings; diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index 3e14d82..829da66 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm @@ -1,6 +1,6 @@ package Nagios::Plugin::Threshold; -use 5.008004; +use 5.006; use strict; use warnings; diff --git a/t/Nagios-Plugin-01.t b/t/Nagios-Plugin-01.t index 0ae2113..9de5009 100644 --- a/t/Nagios-Plugin-01.t +++ b/t/Nagios-Plugin-01.t @@ -1,3 +1,4 @@ +# Nagios::Plugin original test cases use strict; use Test::More tests => 12; @@ -17,7 +18,7 @@ $p->shortname("PAGESIZE"); is($p->shortname, "PAGESIZE", "shortname set correctly"); $p = Nagios::Plugin->new; -ok(! defined $p->shortname, "shortname should be unset on new"); +is($p->shortname, "NAGIOS-PLUGIN-01", "shortname should default on new"); $p = Nagios::Plugin->new( shortname => "SIZE" ); is($p->shortname, "SIZE", "shortname set correctly on new"); diff --git a/t/Nagios-Plugin-02.t b/t/Nagios-Plugin-02.t index 8f25cff..360e180 100644 --- a/t/Nagios-Plugin-02.t +++ b/t/Nagios-Plugin-02.t @@ -1,6 +1,7 @@ +# Nagios::Plugin test set 2, testing NP::Functions wrapping use strict; -use Test::More tests => 101; +use Test::More tests => 103; BEGIN { use_ok("Nagios::Plugin") } require Nagios::Plugin::Functions; @@ -146,3 +147,15 @@ for (@ok) { $_->[1] . '.*' . $_->[2])); } + +# shortname testing +SKIP: { + skip "requires File::Basename", 2 unless eval { require File::Basename }; + $np = Nagios::Plugin->new; + $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'"); +} + -- cgit v0.10-9-g596f