diff options
| author | Gavin Carr <gonzai@users.sourceforge.net> | 2006-10-04 22:02:39 +0000 | 
|---|---|---|
| committer | Gavin Carr <gonzai@users.sourceforge.net> | 2006-10-04 22:02:39 +0000 | 
| commit | e63887eda6765e1059939ff9c89e4fb244b5819b (patch) | |
| tree | 3ae2b11db96535bdbd7a8da60fde642a8fd80619 | |
| parent | 579fdad51ca7c1d306ba040954864216b0e07050 (diff) | |
| download | monitoring-plugin-perl-e63887eda6765e1059939ff9c89e4fb244b5819b.tar.gz | |
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
| -rw-r--r-- | MANIFEST | 1 | ||||
| -rw-r--r-- | Makefile.PL | 11 | ||||
| -rw-r--r-- | lib/Nagios/Plugin.pm | 16 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 10 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 2 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Range.pm | 2 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 2 | ||||
| -rw-r--r-- | t/Nagios-Plugin-01.t | 3 | ||||
| -rw-r--r-- | t/Nagios-Plugin-02.t | 15 | 
9 files changed, 46 insertions, 16 deletions
| @@ -6,6 +6,7 @@ t/check_stuff.pl | |||
| 6 | t/check_stuff.t | 6 | t/check_stuff.t | 
| 7 | t/Nagios-Plugin-01.t | 7 | t/Nagios-Plugin-01.t | 
| 8 | t/Nagios-Plugin-02.t | 8 | t/Nagios-Plugin-02.t | 
| 9 | t/Nagios-Plugin-03.t | ||
| 9 | t/Nagios-Plugin-Functions-01.t | 10 | t/Nagios-Plugin-Functions-01.t | 
| 10 | t/Nagios-Plugin-Functions-02.t | 11 | t/Nagios-Plugin-Functions-02.t | 
| 11 | t/Nagios-Plugin-Getopt-01.t | 12 | 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 @@ | |||
| 1 | use 5.008004; | 1 | use 5.006; | 
| 2 | use ExtUtils::MakeMaker; | 2 | use ExtUtils::MakeMaker; | 
| 3 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence | 3 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence | 
| 4 | # the contents of the Makefile that is written. | 4 | # the contents of the Makefile that is written. | 
| @@ -6,10 +6,11 @@ WriteMakefile( | |||
| 6 | NAME => 'Nagios::Plugin', | 6 | NAME => 'Nagios::Plugin', | 
| 7 | VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION | 7 | VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION | 
| 8 | PREREQ_PM => { | 8 | PREREQ_PM => { | 
| 9 | Class::Struct => 0, | 9 | Class::Struct => 0, | 
| 10 | Params::Validate => 0.24, | 10 | Params::Validate => 0.24, | 
| 11 | Class::Accessor => 0.22, | 11 | Class::Accessor => 0.22, | 
| 12 | Test::More => 0.62, | 12 | Test::More => 0.62, | 
| 13 | Carp => 0, | ||
| 13 | }, # e.g., Module::Name => 1.1 | 14 | }, # e.g., Module::Name => 1.1 | 
| 14 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 | 15 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 | 
| 15 | (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module | 16 | (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" => { | |||
| 12 | package Nagios::Plugin; | 12 | package Nagios::Plugin; | 
| 13 | 13 | ||
| 14 | use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); | 14 | use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); | 
| 15 | use Nagios::Plugin::Performance; | ||
| 16 | use Nagios::Plugin::Threshold; | ||
| 17 | 15 | ||
| 18 | use strict; | 16 | use strict; | 
| 19 | use warnings; | 17 | use warnings; | 
| @@ -29,6 +27,7 @@ our $VERSION = $Nagios::Plugin::Functions::VERSION; | |||
| 29 | 27 | ||
| 30 | sub add_perfdata { | 28 | sub add_perfdata { | 
| 31 | my ($self, %args) = @_; | 29 | my ($self, %args) = @_; | 
| 30 | require Nagios::Plugin::Performance; | ||
| 32 | my $perf = Nagios::Plugin::Performance->new(%args); | 31 | my $perf = Nagios::Plugin::Performance->new(%args); | 
| 33 | push @{$self->perfdata}, $perf; | 32 | push @{$self->perfdata}, $perf; | 
| 34 | } | 33 | } | 
| @@ -37,7 +36,11 @@ sub all_perfoutput { | |||
| 37 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); | 36 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); | 
| 38 | } | 37 | } | 
| 39 | 38 | ||
| 40 | sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } | 39 | sub set_thresholds { | 
| 40 | shift; | ||
| 41 | require Nagios::Plugin::Threshold; | ||
| 42 | Nagios::Plugin::Threshold->set_thresholds(@_); | ||
| 43 | } | ||
| 41 | 44 | ||
| 42 | # NP::Functions wrappers | 45 | # NP::Functions wrappers | 
| 43 | sub nagios_exit { | 46 | sub nagios_exit { | 
| @@ -52,6 +55,13 @@ sub die { | |||
| 52 | my $self = shift; | 55 | my $self = shift; | 
| 53 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); | 56 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); | 
| 54 | } | 57 | } | 
| 58 | # Override default shortname accessor to add default | ||
| 59 | sub shortname { | ||
| 60 | my $self = shift; | ||
| 61 | $self->{'Nagios::__::Plugin::shortname'} = shift if @_; | ||
| 62 | return $self->{'Nagios::__::Plugin::shortname'} || | ||
| 63 | Nagios::Plugin::Functions::get_shortname(); | ||
| 64 | } | ||
| 55 | 65 | ||
| 56 | # ------------------------------------------------------------------------- | 66 | # ------------------------------------------------------------------------- | 
| 57 | # NP::Functions::check_messages helpers and wrappers | 67 | # 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 @@ | |||
| 1 | # This module holds all exported variables | 1 | # Functional interface to basic Nagios::Plugin constants, exports, | 
| 2 | # and base functions | 2 | # and functions | 
| 3 | |||
| 3 | package Nagios::Plugin::Functions; | 4 | package Nagios::Plugin::Functions; | 
| 4 | 5 | ||
| 6 | use 5.006; | ||
| 7 | |||
| 5 | use strict; | 8 | use strict; | 
| 6 | use warnings; | 9 | use warnings; | 
| 7 | use File::Basename; | 10 | use File::Basename; | 
| @@ -47,7 +50,8 @@ sub get_shortname { | |||
| 47 | return $arg{plugin}->shortname if $arg{plugin}; | 50 | return $arg{plugin}->shortname if $arg{plugin}; | 
| 48 | 51 | ||
| 49 | my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); | 52 | my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); | 
| 50 | $shortname =~ s/^CHECK_//; | 53 | $shortname =~ s/^CHECK_//; # Remove any leading CHECK_ | 
| 54 | $shortname =~ s/\..*$//; # Remove any trailing suffix | ||
| 51 | return $shortname; | 55 | return $shortname; | 
| 52 | } | 56 | } | 
| 53 | 57 | ||
| 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 @@ | |||
| 1 | package Nagios::Plugin::Performance; | 1 | package Nagios::Plugin::Performance; | 
| 2 | 2 | ||
| 3 | use 5.008004; | 3 | use 5.006; | 
| 4 | 4 | ||
| 5 | use strict; | 5 | use strict; | 
| 6 | use warnings; | 6 | 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 @@ | |||
| 1 | package Nagios::Plugin::Range; | 1 | package Nagios::Plugin::Range; | 
| 2 | 2 | ||
| 3 | use 5.008004; | 3 | use 5.006; | 
| 4 | 4 | ||
| 5 | use strict; | 5 | use strict; | 
| 6 | use warnings; | 6 | 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 @@ | |||
| 1 | package Nagios::Plugin::Threshold; | 1 | package Nagios::Plugin::Threshold; | 
| 2 | 2 | ||
| 3 | use 5.008004; | 3 | use 5.006; | 
| 4 | 4 | ||
| 5 | use strict; | 5 | use strict; | 
| 6 | use warnings; | 6 | 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 @@ | |||
| 1 | # Nagios::Plugin original test cases | ||
| 1 | 2 | ||
| 2 | use strict; | 3 | use strict; | 
| 3 | use Test::More tests => 12; | 4 | use Test::More tests => 12; | 
| @@ -17,7 +18,7 @@ $p->shortname("PAGESIZE"); | |||
| 17 | is($p->shortname, "PAGESIZE", "shortname set correctly"); | 18 | is($p->shortname, "PAGESIZE", "shortname set correctly"); | 
| 18 | 19 | ||
| 19 | $p = Nagios::Plugin->new; | 20 | $p = Nagios::Plugin->new; | 
| 20 | ok(! defined $p->shortname, "shortname should be unset on new"); | 21 | is($p->shortname, "NAGIOS-PLUGIN-01", "shortname should default on new"); | 
| 21 | 22 | ||
| 22 | $p = Nagios::Plugin->new( shortname => "SIZE" ); | 23 | $p = Nagios::Plugin->new( shortname => "SIZE" ); | 
| 23 | is($p->shortname, "SIZE", "shortname set correctly on new"); | 24 | 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 @@ | |||
| 1 | # Nagios::Plugin test set 2, testing NP::Functions wrapping | ||
| 1 | 2 | ||
| 2 | use strict; | 3 | use strict; | 
| 3 | use Test::More tests => 101; | 4 | use Test::More tests => 103; | 
| 4 | 5 | ||
| 5 | BEGIN { use_ok("Nagios::Plugin") } | 6 | BEGIN { use_ok("Nagios::Plugin") } | 
| 6 | require Nagios::Plugin::Functions; | 7 | require Nagios::Plugin::Functions; | 
| @@ -146,3 +147,15 @@ for (@ok) { | |||
| 146 | $_->[1] . '.*' . $_->[2])); | 147 | $_->[1] . '.*' . $_->[2])); | 
| 147 | } | 148 | } | 
| 148 | 149 | ||
| 150 | |||
| 151 | # shortname testing | ||
| 152 | SKIP: { | ||
| 153 | skip "requires File::Basename", 2 unless eval { require File::Basename }; | ||
| 154 | $np = Nagios::Plugin->new; | ||
| 155 | $plugin = uc File::Basename::basename($0); | ||
| 156 | $plugin =~ s/\..*$//; | ||
| 157 | is($np->shortname, $plugin, "shortname() is '$plugin'"); | ||
| 158 | $r = $np->nagios_exit(OK, "foobar"); | ||
| 159 | like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'"); | ||
| 160 | } | ||
| 161 | |||
