summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MANIFEST1
-rw-r--r--Makefile.PL11
-rw-r--r--lib/Nagios/Plugin.pm16
-rw-r--r--lib/Nagios/Plugin/Functions.pm10
-rw-r--r--lib/Nagios/Plugin/Performance.pm2
-rw-r--r--lib/Nagios/Plugin/Range.pm2
-rw-r--r--lib/Nagios/Plugin/Threshold.pm2
-rw-r--r--t/Nagios-Plugin-01.t3
-rw-r--r--t/Nagios-Plugin-02.t15
9 files changed, 46 insertions, 16 deletions
diff --git a/MANIFEST b/MANIFEST
index a0764e5..f46acd9 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,6 +6,7 @@ t/check_stuff.pl
6t/check_stuff.t 6t/check_stuff.t
7t/Nagios-Plugin-01.t 7t/Nagios-Plugin-01.t
8t/Nagios-Plugin-02.t 8t/Nagios-Plugin-02.t
9t/Nagios-Plugin-03.t
9t/Nagios-Plugin-Functions-01.t 10t/Nagios-Plugin-Functions-01.t
10t/Nagios-Plugin-Functions-02.t 11t/Nagios-Plugin-Functions-02.t
11t/Nagios-Plugin-Getopt-01.t 12t/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 @@
1use 5.008004; 1use 5.006;
2use ExtUtils::MakeMaker; 2use 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" => {
12package Nagios::Plugin; 12package Nagios::Plugin;
13 13
14use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); 14use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES);
15use Nagios::Plugin::Performance;
16use Nagios::Plugin::Threshold;
17 15
18use strict; 16use strict;
19use warnings; 17use warnings;
@@ -29,6 +27,7 @@ our $VERSION = $Nagios::Plugin::Functions::VERSION;
29 27
30sub add_perfdata { 28sub 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
40sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } 39sub 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
43sub nagios_exit { 46sub 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
59sub 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
3package Nagios::Plugin::Functions; 4package Nagios::Plugin::Functions;
4 5
6use 5.006;
7
5use strict; 8use strict;
6use warnings; 9use warnings;
7use File::Basename; 10use 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 @@
1package Nagios::Plugin::Performance; 1package Nagios::Plugin::Performance;
2 2
3use 5.008004; 3use 5.006;
4 4
5use strict; 5use strict;
6use warnings; 6use 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 @@
1package Nagios::Plugin::Range; 1package Nagios::Plugin::Range;
2 2
3use 5.008004; 3use 5.006;
4 4
5use strict; 5use strict;
6use warnings; 6use 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 @@
1package Nagios::Plugin::Threshold; 1package Nagios::Plugin::Threshold;
2 2
3use 5.008004; 3use 5.006;
4 4
5use strict; 5use strict;
6use warnings; 6use 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
2use strict; 3use strict;
3use Test::More tests => 12; 4use Test::More tests => 12;
@@ -17,7 +18,7 @@ $p->shortname("PAGESIZE");
17is($p->shortname, "PAGESIZE", "shortname set correctly"); 18is($p->shortname, "PAGESIZE", "shortname set correctly");
18 19
19$p = Nagios::Plugin->new; 20$p = Nagios::Plugin->new;
20ok(! defined $p->shortname, "shortname should be unset on new"); 21is($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" );
23is($p->shortname, "SIZE", "shortname set correctly on new"); 24is($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
2use strict; 3use strict;
3use Test::More tests => 101; 4use Test::More tests => 103;
4 5
5BEGIN { use_ok("Nagios::Plugin") } 6BEGIN { use_ok("Nagios::Plugin") }
6require Nagios::Plugin::Functions; 7require Nagios::Plugin::Functions;
@@ -146,3 +147,15 @@ for (@ok) {
146 $_->[1] . '.*' . $_->[2])); 147 $_->[1] . '.*' . $_->[2]));
147} 148}
148 149
150
151# shortname testing
152SKIP: {
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