diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Changes | 5 | ||||
-rw-r--r-- | MANIFEST | 64 | ||||
-rw-r--r-- | MANIFEST.SKIP | 21 | ||||
-rw-r--r-- | Makefile.PL | 45 | ||||
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | lib/Monitoring/Plugin.pm (renamed from lib/Nagios/Plugin.pm) | 251 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Config.pm (renamed from lib/Nagios/Plugin/Config.pm) | 53 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/ExitResult.pm | 71 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Functions.pm (renamed from lib/Nagios/Plugin/Functions.pm) | 121 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Getopt.pm (renamed from lib/Nagios/Plugin/Getopt.pm) | 138 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Performance.pm (renamed from lib/Nagios/Plugin/Performance.pm) | 72 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Range.pm (renamed from lib/Nagios/Plugin/Range.pm) | 32 | ||||
-rw-r--r-- | lib/Monitoring/Plugin/Threshold.pm (renamed from lib/Nagios/Plugin/Threshold.pm) | 50 | ||||
-rw-r--r-- | lib/Nagios/Plugin/ExitResult.pm | 67 | ||||
-rw-r--r-- | t/Monitoring-Plugin-01.t (renamed from t/Nagios-Plugin-01.t) | 33 | ||||
-rw-r--r-- | t/Monitoring-Plugin-02.t | 160 | ||||
-rw-r--r-- | t/Monitoring-Plugin-03.t (renamed from t/Nagios-Plugin-03.t) | 53 | ||||
-rw-r--r-- | t/Monitoring-Plugin-04.t (renamed from t/Nagios-Plugin-04.t) | 26 | ||||
-rw-r--r-- | t/Monitoring-Plugin-05.t (renamed from t/Nagios-Plugin-05.t) | 7 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-01.t | 161 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-02.t (renamed from t/Nagios-Plugin-Functions-02.t) | 9 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-03.t (renamed from t/Nagios-Plugin-Functions-03.t) | 2 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-04.t (renamed from t/Nagios-Plugin-Functions-04.t) | 2 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Getopt-01.t (renamed from t/Nagios-Plugin-Getopt-01.t) | 17 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Getopt-02.t (renamed from t/Nagios-Plugin-Getopt-02.t) | 15 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Getopt-03.t (renamed from t/Nagios-Plugin-Getopt-03.t) | 29 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Getopt-04.t (renamed from t/Nagios-Plugin-Getopt-04.t) | 15 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Performance-02.t | 13 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Performance.t (renamed from t/Nagios-Plugin-Performance.t) | 104 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Range.t (renamed from t/Nagios-Plugin-Range.t) | 38 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Threshold.t (renamed from t/Nagios-Plugin-Threshold.t) | 58 | ||||
-rw-r--r-- | t/Nagios-Plugin-02.t | 161 | ||||
-rw-r--r-- | t/Nagios-Plugin-Functions-01.t | 161 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance-02.t | 13 | ||||
-rwxr-xr-x | t/check_stuff.pl | 45 | ||||
-rwxr-xr-x | t/check_stuff.t | 10 | ||||
-rw-r--r-- | t/npg03/README | 16 |
38 files changed, 1104 insertions, 1062 deletions
@@ -5,3 +5,8 @@ | |||
5 | /pm_to_blib | 5 | /pm_to_blib |
6 | /.bzr | 6 | /.bzr |
7 | /.bzrignore | 7 | /.bzrignore |
8 | MYMETA.json | ||
9 | MYMETA.yml | ||
10 | Makefile.old | ||
11 | inc/ | ||
12 | MANIFEST.bak | ||
@@ -1,4 +1,7 @@ | |||
1 | Revision history for Perl module Nagios::Plugin. | 1 | Revision history for Perl module Monitoring::Plugin. |
2 | |||
3 | 0.37 20nd January 2014 | ||
4 | - renamed module due to trademark issues | ||
2 | 5 | ||
3 | 0.36 22nd December 2011 | 6 | 0.36 22nd December 2011 |
4 | - Updated check_threshold to allow multiple check values to be checked at once | 7 | - Updated check_threshold to allow multiple check values to be checked at once |
@@ -1,33 +1,47 @@ | |||
1 | Changes | 1 | Changes |
2 | lib/Nagios/Plugin.pm | 2 | inc/Module/AutoInstall.pm |
3 | lib/Nagios/Plugin/Config.pm | 3 | inc/Module/Install.pm |
4 | lib/Nagios/Plugin/ExitResult.pm | 4 | inc/Module/Install/AutoInstall.pm |
5 | lib/Nagios/Plugin/Functions.pm | 5 | inc/Module/Install/Base.pm |
6 | lib/Nagios/Plugin/Getopt.pm | 6 | inc/Module/Install/Can.pm |
7 | lib/Nagios/Plugin/Performance.pm | 7 | inc/Module/Install/Fetch.pm |
8 | lib/Nagios/Plugin/Range.pm | 8 | inc/Module/Install/Include.pm |
9 | lib/Nagios/Plugin/Threshold.pm | 9 | inc/Module/Install/Makefile.pm |
10 | inc/Module/Install/Metadata.pm | ||
11 | inc/Module/Install/Win32.pm | ||
12 | inc/Module/Install/WriteAll.pm | ||
13 | lib/Monitoring/Plugin.pm | ||
14 | lib/Monitoring/Plugin/Config.pm | ||
15 | lib/Monitoring/Plugin/ExitResult.pm | ||
16 | lib/Monitoring/Plugin/Functions.pm | ||
17 | lib/Monitoring/Plugin/Getopt.pm | ||
18 | lib/Monitoring/Plugin/Performance.pm | ||
19 | lib/Monitoring/Plugin/Range.pm | ||
20 | lib/Monitoring/Plugin/Threshold.pm | ||
10 | Makefile.PL | 21 | Makefile.PL |
11 | MANIFEST This list of files | 22 | MANIFEST This list of files |
12 | META.yml | 23 | META.yml |
24 | notes | ||
13 | README | 25 | README |
14 | t/check_stuff.pl | 26 | t/check_stuff.pl |
15 | t/check_stuff.t | 27 | t/check_stuff.t |
16 | t/Nagios-Plugin-01.t | 28 | t/Monitoring-Plugin-01.t |
17 | t/Nagios-Plugin-02.t | 29 | t/Monitoring-Plugin-02.t |
18 | t/Nagios-Plugin-03.t | 30 | t/Monitoring-Plugin-03.t |
19 | t/Nagios-Plugin-04.t | 31 | t/Monitoring-Plugin-04.t |
20 | t/Nagios-Plugin-Functions-01.t | 32 | t/Monitoring-Plugin-05.t |
21 | t/Nagios-Plugin-Functions-02.t | 33 | t/Monitoring-Plugin-Functions-01.t |
22 | t/Nagios-Plugin-Functions-03.t | 34 | t/Monitoring-Plugin-Functions-02.t |
23 | t/Nagios-Plugin-Getopt-01.t | 35 | t/Monitoring-Plugin-Functions-03.t |
24 | t/Nagios-Plugin-Getopt-02.t | 36 | t/Monitoring-Plugin-Functions-04.t |
25 | t/Nagios-Plugin-Getopt-03.t | 37 | t/Monitoring-Plugin-Getopt-01.t |
26 | t/Nagios-Plugin-Getopt-04.t | 38 | t/Monitoring-Plugin-Getopt-02.t |
27 | t/Nagios-Plugin-Performance-02.t | 39 | t/Monitoring-Plugin-Getopt-03.t |
28 | t/Nagios-Plugin-Performance.t | 40 | t/Monitoring-Plugin-Getopt-04.t |
29 | t/Nagios-Plugin-Range.t | 41 | t/Monitoring-Plugin-Performance-02.t |
30 | t/Nagios-Plugin-Threshold.t | 42 | t/Monitoring-Plugin-Performance.t |
43 | t/Monitoring-Plugin-Range.t | ||
44 | t/Monitoring-Plugin-Threshold.t | ||
31 | t/npg03/expected/00_basic | 45 | t/npg03/expected/00_basic |
32 | t/npg03/expected/00_noextra | 46 | t/npg03/expected/00_noextra |
33 | t/npg03/expected/01_override1 | 47 | t/npg03/expected/01_override1 |
@@ -38,8 +52,10 @@ t/npg03/expected/05_disk3 | |||
38 | t/npg03/expected/05_disk4 | 52 | t/npg03/expected/05_disk4 |
39 | t/npg03/expected/05_disk5 | 53 | t/npg03/expected/05_disk5 |
40 | t/npg03/expected/05_disk6 | 54 | t/npg03/expected/05_disk6 |
55 | t/npg03/expected/05_disk7 | ||
41 | t/npg03/expected/09_funnystuff | 56 | t/npg03/expected/09_funnystuff |
42 | t/npg03/expected/12_nosection_implicit | 57 | t/npg03/expected/12_nosection_implicit |
58 | t/npg03/expected/15_badsection_catch | ||
43 | t/npg03/input/00_basic | 59 | t/npg03/input/00_basic |
44 | t/npg03/input/00_noextra | 60 | t/npg03/input/00_noextra |
45 | t/npg03/input/01_override1 | 61 | t/npg03/input/01_override1 |
@@ -50,9 +66,11 @@ t/npg03/input/05_disk3 | |||
50 | t/npg03/input/05_disk4 | 66 | t/npg03/input/05_disk4 |
51 | t/npg03/input/05_disk5 | 67 | t/npg03/input/05_disk5 |
52 | t/npg03/input/05_disk6 | 68 | t/npg03/input/05_disk6 |
69 | t/npg03/input/05_disk7 | ||
53 | t/npg03/input/09_funnystuff | 70 | t/npg03/input/09_funnystuff |
54 | t/npg03/input/12_nosection_implicit | 71 | t/npg03/input/12_nosection_implicit |
55 | t/npg03/input/13_nosection_explicit_dies | 72 | t/npg03/input/13_nosection_explicit_dies |
56 | t/npg03/input/14_badsection_dies | 73 | t/npg03/input/14_badsection_dies |
74 | t/npg03/input/15_badsection_catch | ||
57 | t/npg03/plugins.ini | 75 | t/npg03/plugins.ini |
58 | t/npg03/README | 76 | 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 @@ | |||
1 | .DS_Store | ||
2 | \.swp | ||
3 | blib | ||
4 | tmp | ||
5 | \.git | ||
6 | ^Makefile$ | ||
7 | Makefile.old | ||
8 | MANIFEST.bak | ||
9 | MANIFEST.SKIP | ||
10 | MYMETA.yml | ||
11 | MYMETA.json | ||
12 | pm_to_blib | ||
13 | .*\.gz | ||
14 | # does not work for centos without F::C::R installed | ||
15 | inc/File/Copy/Recursive.pm | ||
16 | TODO | ||
17 | build-stamp | ||
18 | configure-stamp | ||
19 | nytprof/ | ||
20 | nytprof.out | ||
21 | .~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 @@ | |||
1 | use 5.006; | 1 | use inc::Module::Install; |
2 | use ExtUtils::MakeMaker; | 2 | |
3 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence | 3 | name 'Monitoring-Plugin'; |
4 | # the contents of the Makefile that is written. | 4 | all_from 'lib/Monitoring/Plugin/Functions.pm'; |
5 | WriteMakefile( | 5 | author q{Monitoring Plugin Team <devel@monitoring-plugins.org>}; |
6 | NAME => 'Nagios::Plugin', | 6 | license 'perl'; |
7 | VERSION_FROM => 'lib/Nagios/Plugin/Functions.pm', # finds $VERSION | 7 | repository 'https://github.com/monitoring-plugins/monitoring-plugin-perl'; |
8 | PREREQ_PM => { | 8 | |
9 | Params::Validate => 0, | 9 | requires 'Params::Validate' => 0; |
10 | Class::Accessor => 0, | 10 | requires 'Class::Accessor' => 0; |
11 | Test::More => 0.62, | 11 | requires 'Carp' => 0; |
12 | Carp => 0, | 12 | requires 'Config::Tiny' => 0; |
13 | Config::Tiny => 0, | 13 | requires 'File::Spec' => 0; |
14 | File::Spec => 0, | 14 | requires 'File::Basename' => 0; |
15 | File::Basename => 0, | 15 | requires 'IO::File' => 0; |
16 | IO::File => 0, | 16 | requires 'Math::Calc::Units' => 0; # used in M::P::Performance |
17 | Math::Calc::Units => 0, # used in N::P::Performance | 17 | |
18 | }, # e.g., Module::Name => 1.1 | 18 | |
19 | ($] >= 5.005 ? ## Add these new keywords supported since 5.005 | 19 | build_requires 'Test::More' => 0.62; |
20 | (ABSTRACT_FROM => 'lib/Nagios/Plugin.pm', # retrieve abstract from module | 20 | |
21 | AUTHOR => 'Nagios Plugin Development Team <nagiosplug-devel@lists.sourceforge.net>') : ()), | 21 | auto_install; |
22 | ); | 22 | |
23 | WriteAll; | ||
@@ -1,13 +1,12 @@ | |||
1 | Nagios::Plugin | 1 | Monitoring::Plugin |
2 | ============== | 2 | ================== |
3 | 3 | ||
4 | These modules are meant for perl developers of plugins for Nagios | 4 | These modules are meant for perl developers of plugins for Naemon, Nagios, |
5 | (http://nagiosplug.sourceforge.net). It is meant to simplify a lot | 5 | Icinga, Shinken and other compatible products. It is meant to |
6 | of the common functions required to do checking of a particular | 6 | simplify a lot of the common functions required to do checking of a |
7 | service. | 7 | particular service. |
8 | 8 | This module is maintained by the Monitoring-Plugins team | |
9 | The modules are still in an experimental stage and will be considered | 9 | (https:://monitoring-plugins.org) |
10 | stable when it reaches version 1.0. | ||
11 | 10 | ||
12 | INSTALLATION | 11 | INSTALLATION |
13 | 12 | ||
@@ -23,16 +22,14 @@ EXAMPLE SCRIPT | |||
23 | 22 | ||
24 | "Enough talk! Show me where to start!" | 23 | "Enough talk! Show me where to start!" |
25 | 24 | ||
26 | See the file 'check_stuff.pl' in the 't' directory for a complete | 25 | See the file 'check_stuff.pl' in the 't' directory for a complete |
27 | working example of a plugin script. | 26 | working example of a plugin script. |
28 | 27 | ||
29 | 28 | ||
30 | COPYRIGHT AND LICENCE | 29 | COPYRIGHT AND LICENCE |
31 | 30 | ||
32 | Copyright (C) 2006 by Nagios Plugin Development Team | 31 | Copyright (C) 2006-2014 by Monitoring Plugin Team |
33 | 32 | ||
34 | This library is free software; you can redistribute it and/or modify | 33 | This library is free software; you can redistribute it and/or modify |
35 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | 34 | it under the same terms as Perl itself, either Perl version 5.8.4 or, |
36 | at your option, any later version of Perl 5 you may have available. | 35 | at your option, any later version of Perl 5 you may have available. |
37 | |||
38 | |||
diff --git a/lib/Nagios/Plugin.pm b/lib/Monitoring/Plugin.pm index d85d35a..f9eb49e 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Monitoring/Plugin.pm | |||
@@ -1,7 +1,7 @@ | |||
1 | 1 | ||
2 | package Nagios::Plugin; | 2 | package Monitoring::Plugin; |
3 | 3 | ||
4 | use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); | 4 | use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); |
5 | use Params::Validate qw(:all); | 5 | use Params::Validate qw(:all); |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
@@ -10,10 +10,10 @@ use warnings; | |||
10 | use Carp; | 10 | use Carp; |
11 | use base qw(Class::Accessor::Fast); | 11 | use base qw(Class::Accessor::Fast); |
12 | 12 | ||
13 | Nagios::Plugin->mk_accessors(qw( | 13 | Monitoring::Plugin->mk_accessors(qw( |
14 | shortname | 14 | shortname |
15 | perfdata | 15 | perfdata |
16 | messages | 16 | messages |
17 | opts | 17 | opts |
18 | threshold | 18 | threshold |
19 | )); | 19 | )); |
@@ -25,8 +25,8 @@ our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT); | |||
25 | 25 | ||
26 | # CPAN stupidly won't index this module without a literal $VERSION here, | 26 | # CPAN stupidly won't index this module without a literal $VERSION here, |
27 | # so we're forced to duplicate it explicitly | 27 | # so we're forced to duplicate it explicitly |
28 | # Make sure you update $Nagios::Plugin::Functions::VERSION too | 28 | # Make sure you update $Monitoring::Plugin::Functions::VERSION too |
29 | our $VERSION = "0.36"; | 29 | our $VERSION = "0.37"; |
30 | 30 | ||
31 | sub new { | 31 | sub new { |
32 | my $class = shift; | 32 | my $class = shift; |
@@ -46,7 +46,7 @@ sub new { | |||
46 | }, | 46 | }, |
47 | ); | 47 | ); |
48 | 48 | ||
49 | my $shortname = Nagios::Plugin::Functions::get_shortname(\%args); | 49 | my $shortname = Monitoring::Plugin::Functions::get_shortname(\%args); |
50 | delete $args{shortname} if (exists $args{shortname}); | 50 | delete $args{shortname} if (exists $args{shortname}); |
51 | my $self = { | 51 | my $self = { |
52 | shortname => $shortname, | 52 | shortname => $shortname, |
@@ -61,16 +61,16 @@ sub new { | |||
61 | }; | 61 | }; |
62 | bless $self, $class; | 62 | bless $self, $class; |
63 | if (exists $args{usage}) { | 63 | if (exists $args{usage}) { |
64 | require Nagios::Plugin::Getopt; | 64 | require Monitoring::Plugin::Getopt; |
65 | $self->opts( new Nagios::Plugin::Getopt(%args) ); | 65 | $self->opts( new Monitoring::Plugin::Getopt(%args) ); |
66 | } | 66 | } |
67 | return $self; | 67 | return $self; |
68 | } | 68 | } |
69 | 69 | ||
70 | sub add_perfdata { | 70 | sub add_perfdata { |
71 | my ($self, %args) = @_; | 71 | my ($self, %args) = @_; |
72 | require Nagios::Plugin::Performance; | 72 | require Monitoring::Plugin::Performance; |
73 | my $perf = Nagios::Plugin::Performance->new(%args); | 73 | my $perf = Monitoring::Plugin::Performance->new(%args); |
74 | push @{$self->perfdata}, $perf; | 74 | push @{$self->perfdata}, $perf; |
75 | } | 75 | } |
76 | sub all_perfoutput { | 76 | sub all_perfoutput { |
@@ -78,33 +78,41 @@ sub all_perfoutput { | |||
78 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); | 78 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); |
79 | } | 79 | } |
80 | 80 | ||
81 | sub set_thresholds { | 81 | sub set_thresholds { |
82 | my $self = shift; | 82 | my $self = shift; |
83 | require Nagios::Plugin::Threshold; | 83 | require Monitoring::Plugin::Threshold; |
84 | return $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_)); | 84 | return $self->threshold( Monitoring::Plugin::Threshold->set_thresholds(@_)); |
85 | } | 85 | } |
86 | 86 | ||
87 | # NP::Functions wrappers | 87 | # MP::Functions wrappers |
88 | sub plugin_exit { | ||
89 | my $self = shift; | ||
90 | Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self }); | ||
91 | } | ||
92 | sub plugin_die { | ||
93 | my $self = shift; | ||
94 | Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); | ||
95 | } | ||
88 | sub nagios_exit { | 96 | sub nagios_exit { |
89 | my $self = shift; | 97 | my $self = shift; |
90 | Nagios::Plugin::Functions::nagios_exit(@_, { plugin => $self }); | 98 | Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self }); |
91 | } | 99 | } |
92 | sub nagios_die { | 100 | sub nagios_die { |
93 | my $self = shift; | 101 | my $self = shift; |
94 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); | 102 | Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); |
95 | } | 103 | } |
96 | sub die { | 104 | sub die { |
97 | my $self = shift; | 105 | my $self = shift; |
98 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); | 106 | Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); |
99 | } | 107 | } |
100 | sub max_state { | 108 | sub max_state { |
101 | Nagios::Plugin::Functions::max_state(@_); | 109 | Monitoring::Plugin::Functions::max_state(@_); |
102 | } | 110 | } |
103 | sub max_state_alt { | 111 | sub max_state_alt { |
104 | Nagios::Plugin::Functions::max_state_alt(@_); | 112 | Monitoring::Plugin::Functions::max_state_alt(@_); |
105 | } | 113 | } |
106 | 114 | ||
107 | # top level interface to Nagios::Plugin::Threshold | 115 | # top level interface to Monitoring::Plugin::Threshold |
108 | sub check_threshold { | 116 | sub check_threshold { |
109 | my $self = shift; | 117 | my $self = shift; |
110 | 118 | ||
@@ -143,11 +151,11 @@ sub check_threshold { | |||
143 | else { | 151 | else { |
144 | return UNKNOWN; | 152 | return UNKNOWN; |
145 | } | 153 | } |
146 | 154 | ||
147 | return $self->threshold->get_status($args{check}); | 155 | return $self->threshold->get_status($args{check}); |
148 | } | 156 | } |
149 | 157 | ||
150 | # top level interface to my Nagios::Plugin::Getopt object | 158 | # top level interface to my Monitoring::Plugin::Getopt object |
151 | sub add_arg { | 159 | sub add_arg { |
152 | my $self = shift; | 160 | my $self = shift; |
153 | $self->opts->arg(@_) if $self->_check_for_opts; | 161 | $self->opts->arg(@_) if $self->_check_for_opts; |
@@ -160,15 +168,15 @@ sub getopts { | |||
160 | sub _check_for_opts { | 168 | sub _check_for_opts { |
161 | my $self = shift; | 169 | my $self = shift; |
162 | croak | 170 | croak |
163 | "You have to supply a 'usage' param to Nagios::Plugin::new() if you want to use Getopts from your Nagios::Plugin object." | 171 | "You have to supply a 'usage' param to Monitoring::Plugin::new() if you want to use Getopts from your Monitoring::Plugin object." |
164 | unless ref $self->opts() eq 'Nagios::Plugin::Getopt'; | 172 | unless ref $self->opts() eq 'Monitoring::Plugin::Getopt'; |
165 | return $self; | 173 | return $self; |
166 | } | 174 | } |
167 | 175 | ||
168 | 176 | ||
169 | 177 | ||
170 | # ------------------------------------------------------------------------- | 178 | # ------------------------------------------------------------------------- |
171 | # NP::Functions::check_messages helpers and wrappers | 179 | # MP::Functions::check_messages helpers and wrappers |
172 | 180 | ||
173 | sub add_message { | 181 | sub add_message { |
174 | my $self = shift; | 182 | my $self = shift; |
@@ -179,7 +187,7 @@ sub add_message { | |||
179 | 187 | ||
180 | # Store messages using strings rather than numeric codes | 188 | # Store messages using strings rather than numeric codes |
181 | $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; | 189 | $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; |
182 | $code = lc $code; | 190 | $code = lc $code; |
183 | croak "Error code '$code' not supported by add_message" | 191 | croak "Error code '$code' not supported by add_message" |
184 | if $code eq 'unknown' || $code eq 'dependent'; | 192 | if $code eq 'unknown' || $code eq 'dependent'; |
185 | 193 | ||
@@ -199,7 +207,7 @@ sub check_messages { | |||
199 | if ($code eq 'ok') { | 207 | if ($code eq 'ok') { |
200 | $args{$code} = [ $args{$code} ]; | 208 | $args{$code} = [ $args{$code} ]; |
201 | } else { | 209 | } else { |
202 | croak "Invalid argument '$code'" | 210 | croak "Invalid argument '$code'" |
203 | } | 211 | } |
204 | } | 212 | } |
205 | push @{$args{$code}}, @$messages; | 213 | push @{$args{$code}}, @$messages; |
@@ -209,7 +217,7 @@ sub check_messages { | |||
209 | } | 217 | } |
210 | } | 218 | } |
211 | 219 | ||
212 | Nagios::Plugin::Functions::check_messages(%args); | 220 | Monitoring::Plugin::Functions::check_messages(%args); |
213 | } | 221 | } |
214 | 222 | ||
215 | # ------------------------------------------------------------------------- | 223 | # ------------------------------------------------------------------------- |
@@ -222,23 +230,23 @@ __END__ | |||
222 | 230 | ||
223 | =head1 NAME | 231 | =head1 NAME |
224 | 232 | ||
225 | Nagios::Plugin - A family of perl modules to streamline writing Nagios | 233 | Monitoring::Plugin - A family of perl modules to streamline writing Naemon, Nagios, |
226 | plugins | 234 | Icinga or Shinken (and compatible) plugins. |
227 | 235 | ||
228 | =head1 SYNOPSIS | 236 | =head1 SYNOPSIS |
229 | 237 | ||
230 | # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default | 238 | # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default |
231 | # See also Nagios::Plugin::Functions for a functional interface | 239 | # See also Monitoring::Plugin::Functions for a functional interface |
232 | use Nagios::Plugin; | 240 | use Monitoring::Plugin; |
233 | 241 | ||
234 | # Constructor | 242 | # Constructor |
235 | $np = Nagios::Plugin->new; # OR | 243 | $np = Monitoring::Plugin->new; # OR |
236 | $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); # OR | 244 | $np = Monitoring::Plugin->new( shortname => "PAGESIZE" ); # OR |
237 | 245 | ||
238 | 246 | ||
239 | # use Nagios::Plugin::Getopt to process the @ARGV command line options: | 247 | # use Monitoring::Plugin::Getopt to process the @ARGV command line options: |
240 | # --verbose, --help, --usage, --timeout and --host are defined automatically. | 248 | # --verbose, --help, --usage, --timeout and --host are defined automatically. |
241 | $np = Nagios::Plugin->new( | 249 | $np = Monitoring::Plugin->new( |
242 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] " | 250 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] " |
243 | . "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]", | 251 | . "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]", |
244 | ); | 252 | ); |
@@ -247,7 +255,7 @@ plugins | |||
247 | $np->add_arg( | 255 | $np->add_arg( |
248 | spec => 'warning|w=s', | 256 | spec => 'warning|w=s', |
249 | help => '-w, --warning=INTEGER:INTEGER . See ' | 257 | help => '-w, --warning=INTEGER:INTEGER . See ' |
250 | . 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT ' | 258 | . 'https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT ' |
251 | . 'for the threshold format. ', | 259 | . 'for the threshold format. ', |
252 | ); | 260 | ); |
253 | 261 | ||
@@ -255,29 +263,29 @@ plugins | |||
255 | $np->getopts; | 263 | $np->getopts; |
256 | 264 | ||
257 | 265 | ||
258 | # Exit/return value methods - nagios_exit( CODE, MESSAGE ), | 266 | # Exit/return value methods - plugin_exit( CODE, MESSAGE ), |
259 | # nagios_die( MESSAGE, [CODE]) | 267 | # plugin_die( MESSAGE, [CODE]) |
260 | $page = retrieve_page($page1) | 268 | $page = retrieve_page($page1) |
261 | or $np->nagios_exit( UNKNOWN, "Could not retrieve page" ); | 269 | or $np->plugin_exit( UNKNOWN, "Could not retrieve page" ); |
262 | # Return code: 3; | 270 | # Return code: 3; |
263 | # output: PAGESIZE UNKNOWN - Could not retrieve page | 271 | # output: PAGESIZE UNKNOWN - Could not retrieve page |
264 | test_page($page) | 272 | test_page($page) |
265 | or $np->nagios_exit( CRITICAL, "Bad page found" ); | 273 | or $np->plugin_exit( CRITICAL, "Bad page found" ); |
266 | 274 | ||
267 | # nagios_die() is just like nagios_exit(), but return code defaults | 275 | # plugin_die() is just like plugin_exit(), but return code defaults |
268 | # to UNKNOWN | 276 | # to UNKNOWN |
269 | $page = retrieve_page($page2) | 277 | $page = retrieve_page($page2) |
270 | or $np->nagios_die( "Could not retrieve page" ); | 278 | or $np->plugin_die( "Could not retrieve page" ); |
271 | # Return code: 3; | 279 | # Return code: 3; |
272 | # output: PAGESIZE UNKNOWN - Could not retrieve page | 280 | # output: PAGESIZE UNKNOWN - Could not retrieve page |
273 | 281 | ||
274 | # Threshold methods | 282 | # Threshold methods |
275 | $code = $np->check_threshold( | 283 | $code = $np->check_threshold( |
276 | check => $value, | 284 | check => $value, |
277 | warning => $warning_threshold, | 285 | warning => $warning_threshold, |
278 | critical => $critical_threshold, | 286 | critical => $critical_threshold, |
279 | ); | 287 | ); |
280 | $np->nagios_exit( $code, "Threshold check failed" ) if $code != OK; | 288 | $np->plugin_exit( $code, "Threshold check failed" ) if $code != OK; |
281 | 289 | ||
282 | 290 | ||
283 | # Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) - | 291 | # Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) - |
@@ -290,38 +298,38 @@ plugins | |||
290 | } | 298 | } |
291 | } | 299 | } |
292 | ($code, $message) = $np->check_messages(); | 300 | ($code, $message) = $np->check_messages(); |
293 | nagios_exit( $code, $message ); | 301 | plugin_exit( $code, $message ); |
294 | # If any items in collection matched m/Error/, returns CRITICAL and | 302 | # If any items in collection matched m/Error/, returns CRITICAL and |
295 | # the joined set of Error messages; otherwise returns OK and the | 303 | # the joined set of Error messages; otherwise returns OK and the |
296 | # joined set of ok messages | 304 | # joined set of ok messages |
297 | 305 | ||
298 | 306 | ||
299 | # Perfdata methods | 307 | # Perfdata methods |
300 | $np->add_perfdata( | 308 | $np->add_perfdata( |
301 | label => "size", | 309 | label => "size", |
302 | value => $value, | 310 | value => $value, |
303 | uom => "kB", | 311 | uom => "kB", |
304 | threshold => $threshold, | 312 | threshold => $threshold, |
305 | ); | 313 | ); |
306 | $np->add_perfdata( label => "time", ... ); | 314 | $np->add_perfdata( label => "time", ... ); |
307 | $np->nagios_exit( OK, "page size at http://... was ${value}kB" ); | 315 | $np->plugin_exit( OK, "page size at http://... was ${value}kB" ); |
308 | # Return code: 0; | 316 | # Return code: 0; |
309 | # output: PAGESIZE OK - page size at http://... was 36kB \ | 317 | # output: PAGESIZE OK - page size at http://... was 36kB \ |
310 | # | size=36kB;10:25;25: time=... | 318 | # | size=36kB;10:25;25: time=... |
311 | 319 | ||
312 | 320 | ||
313 | =head1 DESCRIPTION | 321 | =head1 DESCRIPTION |
314 | 322 | ||
315 | Nagios::Plugin and its associated Nagios::Plugin::* modules are a | 323 | Monitoring::Plugin and its associated Monitoring::Plugin::* modules are a |
316 | family of perl modules to streamline writing Nagios plugins. The main | 324 | family of perl modules to streamline writing Monitoring plugins. The main |
317 | end user modules are Nagios::Plugin, providing an object-oriented | 325 | end user modules are Monitoring::Plugin, providing an object-oriented |
318 | interface to the entire Nagios::Plugin::* collection, and | 326 | interface to the entire Monitoring::Plugin::* collection, and |
319 | Nagios::Plugin::Functions, providing a simpler functional interface to | 327 | Monitoring::Plugin::Functions, providing a simpler functional interface to |
320 | a useful subset of the available functionality. | 328 | a useful subset of the available functionality. |
321 | 329 | ||
322 | The purpose of the collection is to make it as simple as possible for | 330 | The purpose of the collection is to make it as simple as possible for |
323 | developers to create plugins that conform the Nagios Plugin guidelines | 331 | developers to create plugins that conform the Monitoring Plugin guidelines |
324 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). | 332 | (https://www.monitoring-plugins.org/doc/guidelines.html). |
325 | 333 | ||
326 | 334 | ||
327 | =head2 EXPORTS | 335 | =head2 EXPORTS |
@@ -346,7 +354,7 @@ corresponding status code. | |||
346 | =item %STATUS_TEXT | 354 | =item %STATUS_TEXT |
347 | 355 | ||
348 | A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the | 356 | A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the |
349 | corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the | 357 | corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the |
350 | reverse of %ERRORS. | 358 | reverse of %ERRORS. |
351 | 359 | ||
352 | =back | 360 | =back |
@@ -354,11 +362,11 @@ reverse of %ERRORS. | |||
354 | 362 | ||
355 | =head2 CONSTRUCTOR | 363 | =head2 CONSTRUCTOR |
356 | 364 | ||
357 | Nagios::Plugin->new; | 365 | Monitoring::Plugin->new; |
358 | 366 | ||
359 | Nagios::Plugin->new( shortname => 'PAGESIZE' ); | 367 | Monitoring::Plugin->new( shortname => 'PAGESIZE' ); |
360 | 368 | ||
361 | Nagios::Plugin->new( | 369 | Monitoring::Plugin->new( |
362 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] | 370 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] |
363 | [ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ", | 371 | [ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ", |
364 | version => $VERSION, | 372 | version => $VERSION, |
@@ -370,7 +378,7 @@ reverse of %ERRORS. | |||
370 | timeout => 15, | 378 | timeout => 15, |
371 | ); | 379 | ); |
372 | 380 | ||
373 | Instantiates a new Nagios::Plugin object. Accepts the following named | 381 | Instantiates a new Monitoring::Plugin object. Accepts the following named |
374 | arguments: | 382 | arguments: |
375 | 383 | ||
376 | =over 4 | 384 | =over 4 |
@@ -382,10 +390,10 @@ output by the various exit methods. Default: uc basename $0. | |||
382 | 390 | ||
383 | =item usage ("Usage: %s --foo --bar") | 391 | =item usage ("Usage: %s --foo --bar") |
384 | 392 | ||
385 | Passing a value for the usage() argument makes Nagios::Plugin | 393 | Passing a value for the usage() argument makes Monitoring::Plugin |
386 | instantiate its own C<Nagios::Plugin::Getopt> object so you can start | 394 | instantiate its own C<Monitoring::Plugin::Getopt> object so you can start |
387 | doing command line argument processing. See | 395 | doing command line argument processing. See |
388 | L<Nagios::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the | 396 | L<Monitoring::Plugin::Getopt/CONSTRUCTOR> for more about "usage" and the |
389 | following options: | 397 | following options: |
390 | 398 | ||
391 | =item version | 399 | =item version |
@@ -406,7 +414,7 @@ following options: | |||
406 | 414 | ||
407 | =head2 OPTION HANDLING METHODS | 415 | =head2 OPTION HANDLING METHODS |
408 | 416 | ||
409 | C<Nagios::Plugin> provides these methods for accessing the functionality in C<Nagios::Plugin::Getopt>. | 417 | C<Monitoring::Plugin> provides these methods for accessing the functionality in C<Monitoring::Plugin::Getopt>. |
410 | 418 | ||
411 | =over 4 | 419 | =over 4 |
412 | 420 | ||
@@ -416,7 +424,7 @@ Examples: | |||
416 | 424 | ||
417 | # Define --hello argument (named parameters) | 425 | # Define --hello argument (named parameters) |
418 | $plugin->add_arg( | 426 | $plugin->add_arg( |
419 | spec => 'hello=s', | 427 | spec => 'hello=s', |
420 | help => "--hello\n Hello string", | 428 | help => "--hello\n Hello string", |
421 | required => 1, | 429 | required => 1, |
422 | ); | 430 | ); |
@@ -425,19 +433,19 @@ Examples: | |||
425 | # Parameter order is 'spec', 'help', 'default', 'required?' | 433 | # Parameter order is 'spec', 'help', 'default', 'required?' |
426 | $plugin->add_arg('hello=s', "--hello\n Hello string", undef, 1); | 434 | $plugin->add_arg('hello=s', "--hello\n Hello string", undef, 1); |
427 | 435 | ||
428 | See L<Nagios::Plugin::Getopt/ARGUMENTS> for more details. | 436 | See L<Monitoring::Plugin::Getopt/ARGUMENTS> for more details. |
429 | 437 | ||
430 | =item getopts() | 438 | =item getopts() |
431 | 439 | ||
432 | Parses and processes the command line options you've defined, | 440 | Parses and processes the command line options you've defined, |
433 | automatically doing the right thing with help/usage/version arguments. | 441 | automatically doing the right thing with help/usage/version arguments. |
434 | 442 | ||
435 | See L<Nagios::Plugin::Getopt/GETOPTS> for more details. | 443 | See L<Monitoring::Plugin::Getopt/GETOPTS> for more details. |
436 | 444 | ||
437 | =item opts() | 445 | =item opts() |
438 | 446 | ||
439 | Assuming you've instantiated it by passing 'usage' to new(), opts() | 447 | Assuming you've instantiated it by passing 'usage' to new(), opts() |
440 | returns the Nagios::Plugin object's C<Nagios::Plugin::Getopt> object, | 448 | returns the Monitoring::Plugin object's C<Monitoring::Plugin::Getopt> object, |
441 | with which you can do lots of great things. | 449 | with which you can do lots of great things. |
442 | 450 | ||
443 | E.g. | 451 | E.g. |
@@ -456,7 +464,7 @@ E.g. | |||
456 | # $plugin->getopts; | 464 | # $plugin->getopts; |
457 | print $plugin->opts->my_argument; | 465 | print $plugin->opts->my_argument; |
458 | 466 | ||
459 | Again, see L<Nagios::Plugin::Getopt>. | 467 | Again, see L<Monitoring::Plugin::Getopt>. |
460 | 468 | ||
461 | =back | 469 | =back |
462 | 470 | ||
@@ -464,33 +472,41 @@ Again, see L<Nagios::Plugin::Getopt>. | |||
464 | 472 | ||
465 | =over 4 | 473 | =over 4 |
466 | 474 | ||
467 | =item nagios_exit( <CODE>, $message ) | 475 | =item plugin_exit( <CODE>, $message ) |
468 | 476 | ||
469 | Exit with return code CODE, and a standard nagios message of the | 477 | Exit with return code CODE, and a standard nagios message of the |
470 | form "SHORTNAME CODE - $message". | 478 | form "SHORTNAME CODE - $message". |
471 | 479 | ||
472 | =item nagios_die( $message, [<CODE>] ) | 480 | =item plugin_die( $message, [<CODE>] ) |
473 | 481 | ||
474 | Same as nagios_exit(), except that CODE is optional, defaulting | 482 | Same as plugin_exit(), except that CODE is optional, defaulting |
475 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. | 483 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. |
476 | Set C<$_use_die> flag if this functionality is required (see test code). | 484 | Set C<$_use_die> flag if this functionality is required (see test code). |
477 | 485 | ||
486 | =item nagios_exit( <CODE>, $message ) | ||
487 | |||
488 | Alias for plugin_die(). Deprecated. | ||
489 | |||
490 | =item nagios_die( $message, [<CODE>] ) | ||
491 | |||
492 | Alias for plugin_die(). Deprecated. | ||
493 | |||
478 | =item die( $message, [<CODE>] ) | 494 | =item die( $message, [<CODE>] ) |
479 | 495 | ||
480 | Alias for nagios_die(). Deprecated. | 496 | Alias for plugin_die(). Deprecated. |
481 | 497 | ||
482 | =item max_state, max_state_alt | 498 | =item max_state, max_state_alt |
483 | 499 | ||
484 | These are wrapper function for Nagios::Plugin::Functions::max_state and | 500 | These are wrapper function for Monitoring::Plugin::Functions::max_state and |
485 | Nagios::Plugin::Functions::max_state_alt. | 501 | Monitoring::Plugin::Functions::max_state_alt. |
486 | 502 | ||
487 | =back | 503 | =back |
488 | 504 | ||
489 | =head2 THRESHOLD METHODS | 505 | =head2 THRESHOLD METHODS |
490 | 506 | ||
491 | These provide a top level interface to the | 507 | These provide a top level interface to the |
492 | C<Nagios::Plugin::Threshold> module; for more details, see | 508 | C<Monitoring::Plugin::Threshold> module; for more details, see |
493 | L<Nagios::Plugin::Threshold> and L<Nagios::Plugin::Range>. | 509 | L<Monitoring::Plugin::Threshold> and L<Monitoring::Plugin::Range>. |
494 | 510 | ||
495 | =over 4 | 511 | =over 4 |
496 | 512 | ||
@@ -512,9 +528,9 @@ WARNING constant. The thresholds may be: | |||
512 | You can specify $value as an array of values and each will be checked against | 528 | You can specify $value as an array of values and each will be checked against |
513 | the thresholds. | 529 | the thresholds. |
514 | 530 | ||
515 | The return value is ready to pass to C <nagios_exit>, e . g ., | 531 | The return value is ready to pass to C <plugin_exit>, e . g ., |
516 | 532 | ||
517 | $p->nagios_exit( | 533 | $p->plugin_exit( |
518 | return_code => $p->check_threshold($result), | 534 | return_code => $p->check_threshold($result), |
519 | message => " sample result was $result" | 535 | message => " sample result was $result" |
520 | ); | 536 | ); |
@@ -523,13 +539,13 @@ The return value is ready to pass to C <nagios_exit>, e . g ., | |||
523 | =item set_thresholds(warning => "10:25", critical => "~:25") | 539 | =item set_thresholds(warning => "10:25", critical => "~:25") |
524 | 540 | ||
525 | Sets the acceptable ranges and creates the plugin's | 541 | Sets the acceptable ranges and creates the plugin's |
526 | Nagios::Plugins::Threshold object. See | 542 | Monitoring::Plugins::Threshold object. See |
527 | http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT | 543 | https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT |
528 | for details and examples of the threshold format. | 544 | for details and examples of the threshold format. |
529 | 545 | ||
530 | =item threshold() | 546 | =item threshold() |
531 | 547 | ||
532 | Returns the object's C<Nagios::Plugin::Threshold> object, if it has | 548 | Returns the object's C<Monitoring::Plugin::Threshold> object, if it has |
533 | been defined by calling set_thresholds(). You can pass a new | 549 | been defined by calling set_thresholds(). You can pass a new |
534 | Threshold object to it to replace the old one too, but you shouldn't | 550 | Threshold object to it to replace the old one too, but you shouldn't |
535 | need to do that from a plugin script. | 551 | need to do that from a plugin script. |
@@ -543,17 +559,17 @@ EXPERIMENTAL AND SUBJECT TO CHANGE | |||
543 | add_messages and check_messages are higher-level convenience methods to add | 559 | add_messages and check_messages are higher-level convenience methods to add |
544 | and then check a set of messages, returning an appropriate return code | 560 | and then check a set of messages, returning an appropriate return code |
545 | and/or result message. They are equivalent to maintaining a set of @critical, | 561 | and/or result message. They are equivalent to maintaining a set of @critical, |
546 | @warning, and and @ok message arrays (add_message), and then doing a final | 562 | @warning, and and @ok message arrays (add_message), and then doing a final |
547 | if test (check_messages) like this: | 563 | if test (check_messages) like this: |
548 | 564 | ||
549 | if (@critical) { | 565 | if (@critical) { |
550 | nagios_exit( CRITICAL, join(' ', @critical) ); | 566 | plugin_exit( CRITICAL, join(' ', @critical) ); |
551 | } | 567 | } |
552 | elsif (@warning) { | 568 | elsif (@warning) { |
553 | nagios_exit( WARNING, join(' ', @warning) ); | 569 | plugin_exit( WARNING, join(' ', @warning) ); |
554 | } | 570 | } |
555 | else { | 571 | else { |
556 | nagios_exit( OK, join(' ', @ok) ); | 572 | plugin_exit( OK, join(' ', @ok) ); |
557 | } | 573 | } |
558 | 574 | ||
559 | =over 4 | 575 | =over 4 |
@@ -571,7 +587,7 @@ Only CRITICAL, WARNING, and OK are accepted as valid codes. | |||
571 | Check the current set of messages and return an appropriate nagios return | 587 | Check the current set of messages and return an appropriate nagios return |
572 | code and/or a result message. In scalar context, returns only a return | 588 | code and/or a result message. In scalar context, returns only a return |
573 | code; in list context returns both a return code and an output message, | 589 | code; in list context returns both a return code and an output message, |
574 | suitable for passing directly to nagios_exit() e.g. | 590 | suitable for passing directly to plugin_exit() e.g. |
575 | 591 | ||
576 | $code = $np->check_messages; | 592 | $code = $np->check_messages; |
577 | ($code, $message) = $np->check_messages; | 593 | ($code, $message) = $np->check_messages; |
@@ -587,7 +603,7 @@ check_messages accepts the following named arguments (none are required): | |||
587 | 603 | ||
588 | =item join => SCALAR | 604 | =item join => SCALAR |
589 | 605 | ||
590 | A string used to join the relevant array to generate the message | 606 | A string used to join the relevant array to generate the message |
591 | string returned in list context i.e. if the 'critical' array @crit | 607 | string returned in list context i.e. if the 'critical' array @crit |
592 | is non-empty, check_messages would return: | 608 | is non-empty, check_messages would return: |
593 | 609 | ||
@@ -599,9 +615,9 @@ as the result message. Default: ' ' (space). | |||
599 | 615 | ||
600 | By default, only one set of messages are joined and returned in the | 616 | By default, only one set of messages are joined and returned in the |
601 | result message i.e. if the result is CRITICAL, only the 'critical' | 617 | result message i.e. if the result is CRITICAL, only the 'critical' |
602 | messages are included in the result; if WARNING, only the 'warning' | 618 | messages are included in the result; if WARNING, only the 'warning' |
603 | messages are included; if OK, the 'ok' messages are included (if | 619 | messages are included; if OK, the 'ok' messages are included (if |
604 | supplied) i.e. the default is to return an 'errors-only' type | 620 | supplied) i.e. the default is to return an 'errors-only' type |
605 | message. | 621 | message. |
606 | 622 | ||
607 | If join_all is supplied, however, it will be used as a string to | 623 | 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. | |||
635 | The performance data is included in the standard plugin output messages by | 651 | The performance data is included in the standard plugin output messages by |
636 | the various exit methods. | 652 | the various exit methods. |
637 | 653 | ||
638 | See the Nagios::Plugin::Performance documentation for more information on | 654 | See the Monitoring::Plugin::Performance documentation for more information on |
639 | performance data and the various field definitions, as well as the relevant | 655 | performance data and the various field definitions, as well as the relevant |
640 | section of the Nagios Plugin guidelines | 656 | section of the Monitoring Plugin guidelines |
641 | (http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). | 657 | (https://www.monitoring-plugins.org/doc/guidelines.html#AEN202). |
642 | 658 | ||
643 | =back | 659 | =back |
644 | 660 | ||
@@ -648,50 +664,49 @@ section of the Nagios Plugin guidelines | |||
648 | "Enough talk! Show me some examples!" | 664 | "Enough talk! Show me some examples!" |
649 | 665 | ||
650 | See the file 'check_stuff.pl' in the 't' directory included with the | 666 | See the file 'check_stuff.pl' in the 't' directory included with the |
651 | Nagios::Plugin distribution for a complete working example of a plugin | 667 | Monitoring::Plugin distribution for a complete working example of a plugin |
652 | script. | 668 | script. |
653 | 669 | ||
654 | 670 | ||
655 | =head1 VERSIONING | 671 | =head1 VERSIONING |
656 | 672 | ||
657 | The Nagios::Plugin::* modules are currently experimental and so the | 673 | The Monitoring::Plugin::* modules are currently experimental and so the |
658 | interfaces may change up until Nagios::Plugin hits version 1.0, although | 674 | interfaces may change up until Monitoring::Plugin hits version 1.0, although |
659 | every attempt will be made to keep them as backwards compatible as | 675 | every attempt will be made to keep them as backwards compatible as |
660 | possible. | 676 | possible. |
661 | 677 | ||
662 | 678 | ||
663 | =head1 SEE ALSO | 679 | =head1 SEE ALSO |
664 | 680 | ||
665 | See L<Nagios::Plugin::Functions> for a simple functional interface to a subset | 681 | See L<Monitoring::Plugin::Functions> for a simple functional interface to a subset |
666 | of the available Nagios::Plugin functionality. | 682 | of the available Monitoring::Plugin functionality. |
667 | 683 | ||
668 | See also L<Nagios::Plugin::Getopt>, L<Nagios::Plugin::Range>, | 684 | See also L<Monitoring::Plugin::Getopt>, L<Monitoring::Plugin::Range>, |
669 | L<Nagios::Plugin::Performance>, L<Nagios::Plugin::Range>, and | 685 | L<Monitoring::Plugin::Performance>, L<Monitoring::Plugin::Range>, and |
670 | L<Nagios::Plugin::Threshold>. | 686 | L<Monitoring::Plugin::Threshold>. |
671 | 687 | ||
672 | The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. | 688 | The Monitoring Plugin project page is at http://monitoring-plugins.org. |
673 | 689 | ||
674 | 690 | ||
675 | =head1 BUGS | 691 | =head1 BUGS |
676 | 692 | ||
677 | Please report bugs in these modules to the Nagios Plugin development team: | 693 | Please report bugs in these modules to the Monitoring Plugin development team: |
678 | nagiosplug-devel@lists.sourceforge.net. | 694 | devel@monitoring-plugins.org. |
679 | 695 | ||
680 | 696 | ||
681 | =head1 AUTHOR | 697 | =head1 AUTHOR |
682 | 698 | ||
683 | Maintained by the Nagios Plugin development team - | 699 | Maintained by the Monitoring Plugin development team - |
684 | http://nagiosplug.sourceforge.net. | 700 | https://www.monitoring-plugins.org. |
685 | 701 | ||
686 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. | 702 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. |
687 | 703 | ||
688 | =head1 COPYRIGHT AND LICENSE | 704 | =head1 COPYRIGHT AND LICENSE |
689 | 705 | ||
690 | Copyright (C) 2006 by Nagios Plugin Development Team | 706 | Copyright (C) 2006-2014 by Monitoring Plugin Team |
691 | 707 | ||
692 | This library is free software; you can redistribute it and/or modify it | 708 | This library is free software; you can redistribute it and/or modify it |
693 | under the same terms as Perl itself, either Perl version 5.8.4 or, at your | 709 | under the same terms as Perl itself, either Perl version 5.8.4 or, at your |
694 | option, any later version of Perl 5 you may have available. | 710 | option, any later version of Perl 5 you may have available. |
695 | 711 | ||
696 | =cut | 712 | =cut |
697 | |||
diff --git a/lib/Nagios/Plugin/Config.pm b/lib/Monitoring/Plugin/Config.pm index dd270e9..5e941d4 100644 --- a/lib/Nagios/Plugin/Config.pm +++ b/lib/Monitoring/Plugin/Config.pm | |||
@@ -1,4 +1,4 @@ | |||
1 | package Nagios::Plugin::Config; | 1 | package Monitoring::Plugin::Config; |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | use Carp; | 4 | use Carp; |
@@ -7,10 +7,11 @@ use base qw(Config::Tiny); | |||
7 | 7 | ||
8 | my $FILENAME1 = 'plugins.ini'; | 8 | my $FILENAME1 = 'plugins.ini'; |
9 | my $FILENAME2 = 'nagios-plugins.ini'; | 9 | my $FILENAME2 = 'nagios-plugins.ini'; |
10 | my $FILENAME3 = 'monitoring-plugins.ini'; | ||
10 | my $CURRENT_FILE = undef; | 11 | my $CURRENT_FILE = undef; |
11 | 12 | ||
12 | # Config paths ending in nagios (search for $FILENAME1) | 13 | # Config paths ending in nagios (search for $FILENAME1) |
13 | my @NAGIOS_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios); | 14 | my @MONITORING_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios); |
14 | # Config paths not ending in nagios (search for $FILENAME2) | 15 | # Config paths not ending in nagios (search for $FILENAME2) |
15 | my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt); | 16 | my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt); |
16 | 17 | ||
@@ -21,26 +22,30 @@ sub read | |||
21 | 22 | ||
22 | unless ($_[0]) { | 23 | unless ($_[0]) { |
23 | SEARCH: { | 24 | SEARCH: { |
24 | if ($ENV{NAGIOS_CONFIG_PATH}) { | 25 | if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) { |
25 | for (split /:/, $ENV{NAGIOS_CONFIG_PATH}) { | 26 | for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) { |
26 | my $file = File::Spec->catfile($_, $FILENAME1); | 27 | my $file = File::Spec->catfile($_, $FILENAME1); |
27 | unshift(@_, $file), last SEARCH if -f $file; | 28 | unshift(@_, $file), last SEARCH if -f $file; |
28 | $file = File::Spec->catfile($_, $FILENAME2); | 29 | $file = File::Spec->catfile($_, $FILENAME2); |
29 | unshift(@_, $file), last SEARCH if -f $file; | 30 | unshift(@_, $file), last SEARCH if -f $file; |
31 | $file = File::Spec->catfile($_, $FILENAME3); | ||
32 | unshift(@_, $file), last SEARCH if -f $file; | ||
30 | } | 33 | } |
31 | } | 34 | } |
32 | for (@NAGIOS_CONFIG_PATH) { | 35 | for (@MONITORING_CONFIG_PATH) { |
33 | my $file = File::Spec->catfile($_, $FILENAME1); | 36 | my $file = File::Spec->catfile($_, $FILENAME1); |
34 | unshift(@_, $file), last SEARCH if -f $file; | 37 | unshift(@_, $file), last SEARCH if -f $file; |
35 | } | 38 | } |
36 | for (@CONFIG_PATH) { | 39 | for (@CONFIG_PATH) { |
37 | my $file = File::Spec->catfile($_, $FILENAME2); | 40 | my $file = File::Spec->catfile($_, $FILENAME2); |
38 | unshift(@_, $file), last SEARCH if -f $file; | 41 | unshift(@_, $file), last SEARCH if -f $file; |
42 | $file = File::Spec->catfile($_, $FILENAME3); | ||
43 | unshift(@_, $file), last SEARCH if -f $file; | ||
39 | } | 44 | } |
40 | } | 45 | } |
41 | 46 | ||
42 | # Use die instead of croak, so we can pass a clean message downstream | 47 | # Use die instead of croak, so we can pass a clean message downstream |
43 | die "Cannot find '$FILENAME1' or '$FILENAME2' in any standard location.\n" unless $_[0]; | 48 | die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0]; |
44 | } | 49 | } |
45 | 50 | ||
46 | $CURRENT_FILE = $_[0]; | 51 | $CURRENT_FILE = $_[0]; |
@@ -94,15 +99,15 @@ sub np_getfile { return $CURRENT_FILE; } | |||
94 | 99 | ||
95 | =head1 NAME | 100 | =head1 NAME |
96 | 101 | ||
97 | Nagios::Plugin::Config - read nagios plugin .ini style config files | 102 | Monitoring::Plugin::Config - read nagios plugin .ini style config files |
98 | 103 | ||
99 | =head1 SYNOPSIS | 104 | =head1 SYNOPSIS |
100 | 105 | ||
101 | # Read given nagios plugin config file | 106 | # Read given nagios plugin config file |
102 | $Config = Nagios::Plugin::Config->read( '/etc/nagios/plugins.ini' ); | 107 | $Config = Monitoring::Plugin::Config->read( '/etc/nagios/plugins.ini' ); |
103 | 108 | ||
104 | # Search for and read default nagios plugin config file | 109 | # Search for and read default nagios plugin config file |
105 | $Config = Nagios::Plugin::Config->read(); | 110 | $Config = Monitoring::Plugin::Config->read(); |
106 | 111 | ||
107 | # Access sections and properties (returns scalars or arrayrefs) | 112 | # Access sections and properties (returns scalars or arrayrefs) |
108 | $rootproperty = $Config->{_}->{rootproperty}; | 113 | $rootproperty = $Config->{_}->{rootproperty}; |
@@ -111,22 +116,22 @@ Nagios::Plugin::Config - read nagios plugin .ini style config files | |||
111 | 116 | ||
112 | =head1 DESCRIPTION | 117 | =head1 DESCRIPTION |
113 | 118 | ||
114 | Nagios::Plugin::Config is a subclass of the excellent Config::Tiny, | 119 | Monitoring::Plugin::Config is a subclass of the excellent Config::Tiny, |
115 | with the following changes: | 120 | with the following changes: |
116 | 121 | ||
117 | =over 4 | 122 | =over 4 |
118 | 123 | ||
119 | =item | 124 | =item |
120 | 125 | ||
121 | Repeated keys are allowed within sections, returning lists instead of scalars | 126 | Repeated keys are allowed within sections, returning lists instead of scalars |
122 | 127 | ||
123 | =item | 128 | =item |
124 | 129 | ||
125 | Write functionality has been removed i.e. access is read only | 130 | Write functionality has been removed i.e. access is read only |
126 | 131 | ||
127 | =item | 132 | =item |
128 | 133 | ||
129 | Nagios::Plugin::Config searches for a default nagios plugins file if no explicit | 134 | Monitoring::Plugin::Config searches for a default nagios plugins file if no explicit |
130 | filename is given to C<read()>. The current standard locations checked are: | 135 | filename is given to C<read()>. The current standard locations checked are: |
131 | 136 | ||
132 | =over 4 | 137 | =over 4 |
@@ -137,15 +142,15 @@ filename is given to C<read()>. The current standard locations checked are: | |||
137 | 142 | ||
138 | =item /usr/local/etc/nagios /etc/opt/nagios/plugins.ini | 143 | =item /usr/local/etc/nagios /etc/opt/nagios/plugins.ini |
139 | 144 | ||
140 | =item /etc/nagios-plugins.ini | 145 | =item /etc/nagios-plugins.ini |
141 | 146 | ||
142 | =item /usr/local/etc/nagios-plugins.ini | 147 | =item /usr/local/etc/nagios-plugins.ini |
143 | 148 | ||
144 | =item /etc/opt/nagios-plugins.ini | 149 | =item /etc/opt/nagios-plugins.ini |
145 | 150 | ||
146 | =back | 151 | =back |
147 | 152 | ||
148 | To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable | 153 | To use a custom location, set a C<NAGIOS_CONFIG_PATH> environment variable |
149 | to the set of directories that should be checked. The first C<plugins.ini> or | 154 | to the set of directories that should be checked. The first C<plugins.ini> or |
150 | C<nagios-plugins.ini> file found will be used. | 155 | C<nagios-plugins.ini> file found will be used. |
151 | 156 | ||
@@ -154,21 +159,19 @@ C<nagios-plugins.ini> file found will be used. | |||
154 | 159 | ||
155 | =head1 SEE ALSO | 160 | =head1 SEE ALSO |
156 | 161 | ||
157 | L<Config::Tiny>, L<Nagios::Plugin> | 162 | L<Config::Tiny>, L<Monitoring::Plugin> |
158 | 163 | ||
159 | 164 | ||
160 | =head1 AUTHORS | 165 | =head1 AUTHOR |
161 | 166 | ||
162 | This code is maintained by the Nagios Plugin Development Team: | 167 | This code is maintained by the Monitoring Plugin Development Team: see |
163 | L<http://nagiosplug.sourceforge.net>. | 168 | https://monitoring-plugins.org |
164 | 169 | ||
170 | =head1 COPYRIGHT AND LICENSE | ||
165 | 171 | ||
166 | =head1 COPYRIGHT and LICENCE | 172 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
167 | |||
168 | Copyright (C) 2006-2007 by Nagios Plugin Development Team | ||
169 | 173 | ||
170 | This library is free software; you can redistribute it and/or modify | 174 | This library is free software; you can redistribute it and/or modify |
171 | it under the same terms as Perl itself. | 175 | it under the same terms as Perl itself. |
172 | 176 | ||
173 | =cut | 177 | =cut |
174 | |||
diff --git a/lib/Monitoring/Plugin/ExitResult.pm b/lib/Monitoring/Plugin/ExitResult.pm new file mode 100644 index 0000000..aa9f5da --- /dev/null +++ b/lib/Monitoring/Plugin/ExitResult.pm | |||
@@ -0,0 +1,71 @@ | |||
1 | # Tiny helper class to return both output and return_code when testing | ||
2 | |||
3 | package Monitoring::Plugin::ExitResult; | ||
4 | |||
5 | use strict; | ||
6 | |||
7 | # Stringify to message | ||
8 | use overload '""' => sub { shift->{message} }; | ||
9 | |||
10 | # Constructor | ||
11 | sub new { | ||
12 | my $class = shift; | ||
13 | return bless { return_code => $_[0], message => $_[1] }, $class; | ||
14 | } | ||
15 | |||
16 | # Accessors | ||
17 | sub message { shift->{message} } | ||
18 | sub return_code { shift->{return_code} } | ||
19 | sub code { shift->{return_code} } | ||
20 | |||
21 | 1; | ||
22 | |||
23 | __END__ | ||
24 | |||
25 | =head1 NAME | ||
26 | |||
27 | Monitoring::Plugin::ExitResult - Helper class for returning both output and | ||
28 | return codes when testing. | ||
29 | |||
30 | =head1 SYNOPSIS | ||
31 | |||
32 | use Test::More; | ||
33 | use Monitoring::Plugin::Functions; | ||
34 | |||
35 | # In a test file somewhere | ||
36 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
37 | |||
38 | # Later ... | ||
39 | $e = plugin_exit( CRITICAL, 'aiiii ...' ); | ||
40 | print $e->message; | ||
41 | print $e->return_code; | ||
42 | |||
43 | # MP::ExitResult also stringifies to the message output | ||
44 | like(plugin_exit( WARNING, 'foobar'), qr/^foo/, 'matches!'); | ||
45 | |||
46 | |||
47 | |||
48 | =head1 DESCRIPTION | ||
49 | |||
50 | Monitoring::Plugin::ExitResult is a tiny helper class intended for use | ||
51 | when testing other Monitoring::Plugin modules. A Monitoring::Plugin::ExitResult | ||
52 | object is returned by plugin_exit() and friends when | ||
53 | Monitoring::Plugin::Functions::_fake_exit has been set, instead of doing a | ||
54 | conventional print + exit. | ||
55 | |||
56 | =head1 AUTHOR | ||
57 | |||
58 | This code is maintained by the Monitoring Plugin Development Team: see | ||
59 | https://monitoring-plugins.org | ||
60 | |||
61 | Originally: | ||
62 | Gavin Carr , E<lt>gavin@openfusion.com.auE<gt> | ||
63 | |||
64 | =head1 COPYRIGHT AND LICENSE | ||
65 | |||
66 | Copyright (C) 2006-2014 Monitoring Plugin Development Team | ||
67 | |||
68 | This library is free software; you can redistribute it and/or modify | ||
69 | it under the same terms as Perl itself. | ||
70 | |||
71 | =cut | ||
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm index 14fe661..d2856e8 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Monitoring/Plugin/Functions.pm | |||
@@ -1,7 +1,7 @@ | |||
1 | # Functional interface to basic Nagios::Plugin constants, exports, | 1 | # Functional interface to basic Monitoring::Plugin constants, exports, |
2 | # and functions | 2 | # and functions |
3 | 3 | ||
4 | package Nagios::Plugin::Functions; | 4 | package Monitoring::Plugin::Functions; |
5 | 5 | ||
6 | use 5.006; | 6 | use 5.006; |
7 | 7 | ||
@@ -11,19 +11,19 @@ use File::Basename; | |||
11 | use Params::Validate qw(:types validate); | 11 | use Params::Validate qw(:types validate); |
12 | use Math::Calc::Units; | 12 | use Math::Calc::Units; |
13 | 13 | ||
14 | # Remember to update Nagios::Plugins as well | 14 | # Remember to update Monitoring::Plugins as well |
15 | our $VERSION = "0.36"; | 15 | our $VERSION = "0.37"; |
16 | 16 | ||
17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | 17 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); |
18 | 18 | ||
19 | require Exporter; | 19 | require Exporter; |
20 | our @ISA = qw(Exporter); | 20 | our @ISA = qw(Exporter); |
21 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); | 21 | our @EXPORT = (@STATUS_CODES, qw(plugin_exit plugin_die check_messages)); |
22 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re); | 22 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re); |
23 | our %EXPORT_TAGS = ( | 23 | our %EXPORT_TAGS = ( |
24 | all => [ @EXPORT, @EXPORT_OK ], | 24 | all => [ @EXPORT, @EXPORT_OK ], |
25 | codes => [ @STATUS_CODES ], | 25 | codes => [ @STATUS_CODES ], |
26 | functions => [ qw(nagios_exit nagios_die check_messages max_state max_state_alt convert) ], | 26 | functions => [ qw(plugin_exit plugin_die check_messages max_state max_state_alt convert) ], |
27 | ); | 27 | ); |
28 | 28 | ||
29 | use constant OK => 0; | 29 | use constant OK => 0; |
@@ -61,7 +61,7 @@ sub get_shortname { | |||
61 | return $arg->{shortname} if (defined($arg->{shortname})); | 61 | return $arg->{shortname} if (defined($arg->{shortname})); |
62 | $shortname = $arg->{plugin} if (defined( $arg->{plugin})); | 62 | $shortname = $arg->{plugin} if (defined( $arg->{plugin})); |
63 | 63 | ||
64 | $shortname = uc basename($shortname || $ENV{NAGIOS_PLUGIN} || $0); | 64 | $shortname = uc basename($shortname || $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0); |
65 | $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_] | 65 | $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_] |
66 | $shortname =~ s/\..*$//; # Remove any trailing suffix | 66 | $shortname =~ s/\..*$//; # Remove any trailing suffix |
67 | return $shortname; | 67 | return $shortname; |
@@ -85,8 +85,8 @@ sub max_state_alt { | |||
85 | return UNKNOWN; | 85 | return UNKNOWN; |
86 | } | 86 | } |
87 | 87 | ||
88 | # nagios_exit( $code, $message ) | 88 | # plugin_exit( $code, $message ) |
89 | sub nagios_exit { | 89 | sub plugin_exit { |
90 | my ($code, $message, $arg) = @_; | 90 | my ($code, $message, $arg) = @_; |
91 | 91 | ||
92 | # Handle named parameters | 92 | # Handle named parameters |
@@ -124,21 +124,21 @@ sub nagios_exit { | |||
124 | $output = "$shortname $output" if $shortname; | 124 | $output = "$shortname $output" if $shortname; |
125 | if ($arg->{plugin}) { | 125 | if ($arg->{plugin}) { |
126 | my $plugin = $arg->{plugin}; | 126 | my $plugin = $arg->{plugin}; |
127 | $output .= " | ". $plugin->all_perfoutput | 127 | $output .= " | ". $plugin->all_perfoutput |
128 | if $plugin->perfdata && $plugin->all_perfoutput; | 128 | if $plugin->perfdata && $plugin->all_perfoutput; |
129 | } | 129 | } |
130 | $output .= "\n"; | 130 | $output .= "\n"; |
131 | 131 | ||
132 | # Don't actually exit if _fake_exit set | 132 | # Don't actually exit if _fake_exit set |
133 | if ($_fake_exit) { | 133 | if ($_fake_exit) { |
134 | require Nagios::Plugin::ExitResult; | 134 | require Monitoring::Plugin::ExitResult; |
135 | return Nagios::Plugin::ExitResult->new($code, $output); | 135 | return Monitoring::Plugin::ExitResult->new($code, $output); |
136 | } | 136 | } |
137 | 137 | ||
138 | _nagios_exit($code, $output); | 138 | _plugin_exit($code, $output); |
139 | } | 139 | } |
140 | 140 | ||
141 | sub _nagios_exit { | 141 | sub _plugin_exit { |
142 | my ($code, $output) = @_; | 142 | my ($code, $output) = @_; |
143 | # Print output and exit; die if flag set and called via a die in stack backtrace | 143 | # Print output and exit; die if flag set and called via a die in stack backtrace |
144 | if ($_use_die) { | 144 | if ($_use_die) { |
@@ -155,34 +155,34 @@ sub _nagios_exit { | |||
155 | exit $code; | 155 | exit $code; |
156 | } | 156 | } |
157 | 157 | ||
158 | # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) | 158 | # plugin_die( $message, [ $code ]) OR plugin_die( $code, $message ) |
159 | # Default $code: UNKNOWN | 159 | # Default $code: UNKNOWN |
160 | sub nagios_die { | 160 | sub plugin_die { |
161 | my ($arg1, $arg2, $rest) = @_; | 161 | my ($arg1, $arg2, $rest) = @_; |
162 | 162 | ||
163 | # Named parameters | 163 | # Named parameters |
164 | if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) { | 164 | if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) { |
165 | return nagios_exit(@_); | 165 | return plugin_exit(@_); |
166 | } | 166 | } |
167 | 167 | ||
168 | # ($code, $message) | 168 | # ($code, $message) |
169 | elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) { | 169 | elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) { |
170 | return nagios_exit(@_); | 170 | return plugin_exit(@_); |
171 | } | 171 | } |
172 | 172 | ||
173 | # ($message, $code) | 173 | # ($message, $code) |
174 | elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) { | 174 | elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) { |
175 | return nagios_exit($arg2, $arg1, $rest); | 175 | return plugin_exit($arg2, $arg1, $rest); |
176 | } | 176 | } |
177 | 177 | ||
178 | # Else just assume $arg1 is the message and hope for the best | 178 | # Else just assume $arg1 is the message and hope for the best |
179 | else { | 179 | else { |
180 | return nagios_exit( UNKNOWN, $arg1, $arg2 ); | 180 | return plugin_exit( UNKNOWN, $arg1, $arg2 ); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | # For backwards compatibility | 184 | # For backwards compatibility |
185 | sub die { nagios_die(@_); } | 185 | sub die { plugin_die(@_); } |
186 | 186 | ||
187 | 187 | ||
188 | # ------------------------------------------------------------------------ | 188 | # ------------------------------------------------------------------------ |
@@ -197,9 +197,9 @@ sub convert | |||
197 | } | 197 | } |
198 | 198 | ||
199 | # ------------------------------------------------------------------------ | 199 | # ------------------------------------------------------------------------ |
200 | # check_messages - return a status and/or message based on a set of | 200 | # check_messages - return a status and/or message based on a set of |
201 | # message arrays. | 201 | # message arrays. |
202 | # Returns a nagios status code in scalar context. | 202 | # Returns a nagios status code in scalar context. |
203 | # Returns a code and a message in list context. | 203 | # Returns a code and a message in list context. |
204 | # The message is join($join, @array) for the relevant array for the code, | 204 | # The message is join($join, @array) for the relevant array for the code, |
205 | # or join($join_all, $message) for all arrays if $join_all is set. | 205 | # or join($join_all, $message) for all arrays if $join_all is set. |
@@ -222,18 +222,18 @@ sub check_messages { | |||
222 | # Compose message | 222 | # Compose message |
223 | my $message = ''; | 223 | my $message = ''; |
224 | if ($arg{join_all}) { | 224 | if ($arg{join_all}) { |
225 | $message = join( $arg{join_all}, | 225 | $message = join( $arg{join_all}, |
226 | map { @$_ ? join( $arg{'join'}, @$_) : () } | 226 | map { @$_ ? join( $arg{'join'}, @$_) : () } |
227 | $arg{critical}, | 227 | $arg{critical}, |
228 | $arg{warning}, | 228 | $arg{warning}, |
229 | $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] | 229 | $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] |
230 | ); | 230 | ); |
231 | } | 231 | } |
232 | 232 | ||
233 | else { | 233 | else { |
234 | $message ||= join( $arg{'join'}, @{$arg{critical}} ) | 234 | $message ||= join( $arg{'join'}, @{$arg{critical}} ) |
235 | if $code == CRITICAL; | 235 | if $code == CRITICAL; |
236 | $message ||= join( $arg{'join'}, @{$arg{warning}} ) | 236 | $message ||= join( $arg{'join'}, @{$arg{warning}} ) |
237 | if $code == WARNING; | 237 | if $code == WARNING; |
238 | $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} | 238 | $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} |
239 | if $arg{ok}; | 239 | if $arg{ok}; |
@@ -252,28 +252,28 @@ __END__ | |||
252 | 252 | ||
253 | =head1 NAME | 253 | =head1 NAME |
254 | 254 | ||
255 | Nagios::Plugin::Functions - functions to simplify the creation of | 255 | Monitoring::Plugin::Functions - functions to simplify the creation of |
256 | Nagios plugins | 256 | Nagios plugins |
257 | 257 | ||
258 | =head1 SYNOPSIS | 258 | =head1 SYNOPSIS |
259 | 259 | ||
260 | # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default | 260 | # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default |
261 | use Nagios::Plugin::Functions; | 261 | use Monitoring::Plugin::Functions; |
262 | 262 | ||
263 | # nagios_exit( CODE, $message ) - exit with error code CODE, | 263 | # plugin_exit( CODE, $message ) - exit with error code CODE, |
264 | # and message "PLUGIN CODE - $message" | 264 | # and message "PLUGIN CODE - $message" |
265 | nagios_exit( CRITICAL, $critical_error ) if $critical_error; | 265 | plugin_exit( CRITICAL, $critical_error ) if $critical_error; |
266 | nagios_exit( WARNING, $warning_error ) if $warning_error; | 266 | plugin_exit( WARNING, $warning_error ) if $warning_error; |
267 | nagios_exit( OK, $result ); | 267 | plugin_exit( OK, $result ); |
268 | 268 | ||
269 | # nagios_die( $message, [$CODE] ) - just like nagios_exit(), | 269 | # plugin_die( $message, [$CODE] ) - just like plugin_exit(), |
270 | # but CODE is optional, defaulting to UNKNOWN | 270 | # but CODE is optional, defaulting to UNKNOWN |
271 | do_something() | 271 | do_something() |
272 | or nagios_die("do_something() failed horribly"); | 272 | or plugin_die("do_something() failed horribly"); |
273 | do_something_critical() | 273 | do_something_critical() |
274 | or nagios_die("do_something_critical() failed", CRITICAL); | 274 | or plugin_die("do_something_critical() failed", CRITICAL); |
275 | 275 | ||
276 | # check_messages - check a set of message arrays, returning a | 276 | # check_messages - check a set of message arrays, returning a |
277 | # CODE and/or a result message | 277 | # CODE and/or a result message |
278 | $code = check_messages(critical => \@crit, warning => \@warn); | 278 | $code = check_messages(critical => \@crit, warning => \@warn); |
279 | ($code, $message) = check_messages( | 279 | ($code, $message) = check_messages( |
@@ -281,18 +281,18 @@ Nagios plugins | |||
281 | ok => \@ok ); | 281 | ok => \@ok ); |
282 | 282 | ||
283 | # get_shortname - return the default short name for this plugin | 283 | # get_shortname - return the default short name for this plugin |
284 | # (as used by nagios_exit/die; not exported by default) | 284 | # (as used by plugin_exit/die; not exported by default) |
285 | $shortname = get_shortname(); | 285 | $shortname = get_shortname(); |
286 | 286 | ||
287 | 287 | ||
288 | =head1 DESCRIPTION | 288 | =head1 DESCRIPTION |
289 | 289 | ||
290 | This module is part of the Nagios::Plugin family, a set of modules | 290 | This module is part of the Monitoring::Plugin family, a set of modules |
291 | for simplifying the creation of Nagios plugins. This module exports | 291 | for simplifying the creation of Nagios plugins. This module exports |
292 | convenience functions for the class methods provided by | 292 | convenience functions for the class methods provided by |
293 | Nagios::Plugin. It is intended for those who prefer a simpler | 293 | Monitoring::Plugin. It is intended for those who prefer a simpler |
294 | functional interface, and who do not need the additional | 294 | functional interface, and who do not need the additional |
295 | functionality of Nagios::Plugin. | 295 | functionality of Monitoring::Plugin. |
296 | 296 | ||
297 | =head2 EXPORTS | 297 | =head2 EXPORTS |
298 | 298 | ||
@@ -306,8 +306,8 @@ Nagios status code constants are exported by default: | |||
306 | 306 | ||
307 | as are the following functions: | 307 | as are the following functions: |
308 | 308 | ||
309 | nagios_exit | 309 | plugin_exit |
310 | nagios_die | 310 | plugin_die |
311 | check_messages | 311 | check_messages |
312 | 312 | ||
313 | The following variables and functions are exported only on request: | 313 | The following variables and functions are exported only on request: |
@@ -325,14 +325,14 @@ The following functions are supported: | |||
325 | 325 | ||
326 | =over 4 | 326 | =over 4 |
327 | 327 | ||
328 | =item nagios_exit( <CODE>, $message ) | 328 | =item plugin_exit( <CODE>, $message ) |
329 | 329 | ||
330 | Exit with return code CODE, and a standard nagios message of the | 330 | Exit with return code CODE, and a standard nagios message of the |
331 | form "PLUGIN CODE - $message". | 331 | form "PLUGIN CODE - $message". |
332 | 332 | ||
333 | =item nagios_die( $message, [CODE] ) | 333 | =item plugin_die( $message, [CODE] ) |
334 | 334 | ||
335 | Same as nagios_exit(), except that CODE is optional, defaulting | 335 | Same as plugin_exit(), except that CODE is optional, defaulting |
336 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. | 336 | to UNKNOWN. NOTE: exceptions are not raised by default to calling code. |
337 | Set C<$_use_die> flag if this functionality is required (see test code). | 337 | Set C<$_use_die> flag if this functionality is required (see test code). |
338 | 338 | ||
@@ -354,7 +354,7 @@ check_messages() accepts the following named arguments: | |||
354 | 354 | ||
355 | =item critical => ARRAYREF | 355 | =item critical => ARRAYREF |
356 | 356 | ||
357 | An arrayref of critical error messages - check_messages() returns | 357 | An arrayref of critical error messages - check_messages() returns |
358 | CRITICAL if this arrayref is non-empty. Mandatory. | 358 | CRITICAL if this arrayref is non-empty. Mandatory. |
359 | 359 | ||
360 | =item warning => ARRAYREF | 360 | =item warning => ARRAYREF |
@@ -371,7 +371,7 @@ are empty. Optional. | |||
371 | 371 | ||
372 | =item join => SCALAR | 372 | =item join => SCALAR |
373 | 373 | ||
374 | A string used to join the relevant array to generate the message | 374 | A string used to join the relevant array to generate the message |
375 | string returned in list context i.e. if the 'critical' array @crit | 375 | string returned in list context i.e. if the 'critical' array @crit |
376 | is non-empty, check_messages would return: | 376 | is non-empty, check_messages would return: |
377 | 377 | ||
@@ -383,9 +383,9 @@ as the result message. Optional; default: ' ' (space). | |||
383 | 383 | ||
384 | By default, only one set of messages are joined and returned in the | 384 | By default, only one set of messages are joined and returned in the |
385 | result message i.e. if the result is CRITICAL, only the 'critical' | 385 | result message i.e. if the result is CRITICAL, only the 'critical' |
386 | messages are included in the result; if WARNING, only the 'warning' | 386 | messages are included in the result; if WARNING, only the 'warning' |
387 | messages are included; if OK, the 'ok' messages are included (if | 387 | messages are included; if OK, the 'ok' messages are included (if |
388 | supplied) i.e. the default is to return an 'errors-only' type | 388 | supplied) i.e. the default is to return an 'errors-only' type |
389 | message. | 389 | message. |
390 | 390 | ||
391 | If join_all is supplied, however, it will be used as a string to | 391 | If join_all is supplied, however, it will be used as a string to |
@@ -397,9 +397,9 @@ all messages are joined and returned. | |||
397 | =item get_shortname | 397 | =item get_shortname |
398 | 398 | ||
399 | Return the default shortname used for this plugin i.e. the first | 399 | Return the default shortname used for this plugin i.e. the first |
400 | token reported by nagios_exit/nagios_die. The default is basically | 400 | token reported by plugin_exit/plugin_die. The default is basically |
401 | 401 | ||
402 | uc basename( $ENV{NAGIOS_PLUGIN} || $0 ) | 402 | uc basename( $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0 ) |
403 | 403 | ||
404 | with any leading 'CHECK_' and trailing file suffixes removed. | 404 | with any leading 'CHECK_' and trailing file suffixes removed. |
405 | 405 | ||
@@ -427,18 +427,17 @@ internal tests performed can return UNKNOWN. | |||
427 | 427 | ||
428 | =head1 SEE ALSO | 428 | =head1 SEE ALSO |
429 | 429 | ||
430 | Nagios::Plugin; the nagios plugin developer guidelines at | 430 | Monitoring::Plugin; the nagios plugin developer guidelines at |
431 | http://nagiosplug.sourceforge.net/developer-guidelines.html. | 431 | https://www.monitoring-plugins.org/doc/guidelines.html. |
432 | 432 | ||
433 | =head1 AUTHOR | ||
433 | 434 | ||
434 | =head1 AUTHORS | 435 | This code is maintained by the Monitoring Plugin Development Team: see |
435 | 436 | https://monitoring-plugins.org | |
436 | This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net | ||
437 | |||
438 | 437 | ||
439 | =head1 COPYRIGHT AND LICENSE | 438 | =head1 COPYRIGHT AND LICENSE |
440 | 439 | ||
441 | Copyright (C) 2006 by Nagios Plugin Development Team | 440 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
442 | 441 | ||
443 | This library is free software; you can redistribute it and/or modify | 442 | This library is free software; you can redistribute it and/or modify |
444 | it under the same terms as Perl itself. | 443 | it under the same terms as Perl itself. |
diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm index 22ff642..ce1c0f9 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Monitoring/Plugin/Getopt.pm | |||
@@ -1,9 +1,9 @@ | |||
1 | # | 1 | # |
2 | # Nagios::Plugin::Getopt - OO perl module providing standardised argument | 2 | # Monitoring::Plugin::Getopt - OO perl module providing standardised argument |
3 | # processing for nagios plugins | 3 | # processing for nagios plugins |
4 | # | 4 | # |
5 | 5 | ||
6 | package Nagios::Plugin::Getopt; | 6 | package Monitoring::Plugin::Getopt; |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use File::Basename; | 9 | use File::Basename; |
@@ -12,18 +12,18 @@ use Carp; | |||
12 | use Params::Validate qw(:all); | 12 | use Params::Validate qw(:all); |
13 | use base qw(Class::Accessor); | 13 | use base qw(Class::Accessor); |
14 | 14 | ||
15 | use Nagios::Plugin::Functions; | 15 | use Monitoring::Plugin::Functions; |
16 | use Nagios::Plugin::Config; | 16 | use Monitoring::Plugin::Config; |
17 | use vars qw($VERSION); | 17 | use vars qw($VERSION); |
18 | $VERSION = $Nagios::Plugin::Functions::VERSION; | 18 | $VERSION = $Monitoring::Plugin::Functions::VERSION; |
19 | 19 | ||
20 | # Standard defaults | 20 | # Standard defaults |
21 | my %DEFAULT = ( | 21 | my %DEFAULT = ( |
22 | timeout => 15, | 22 | timeout => 15, |
23 | verbose => 0, | 23 | verbose => 0, |
24 | license => | 24 | license => |
25 | "This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. | 25 | "This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. |
26 | It may be used, redistributed and/or modified under the terms of the GNU | 26 | It may be used, redistributed and/or modified under the terms of the GNU |
27 | General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", | 27 | General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).", |
28 | ); | 28 | ); |
29 | # Standard arguments | 29 | # Standard arguments |
@@ -60,7 +60,7 @@ sub _die | |||
60 | my $self = shift; | 60 | my $self = shift; |
61 | my ($msg) = @_; | 61 | my ($msg) = @_; |
62 | $msg .= "\n" unless substr($msg, -1) eq "\n"; | 62 | $msg .= "\n" unless substr($msg, -1) eq "\n"; |
63 | Nagios::Plugin::Functions::_nagios_exit(3, $msg); | 63 | Monitoring::Plugin::Functions::_plugin_exit(3, $msg); |
64 | } | 64 | } |
65 | 65 | ||
66 | # Return the given attribute, if set, including a final newline | 66 | # Return the given attribute, if set, including a final newline |
@@ -182,7 +182,7 @@ sub _help | |||
182 | } | 182 | } |
183 | 183 | ||
184 | # Return a Getopt::Long-compatible option array from the current set of specs | 184 | # Return a Getopt::Long-compatible option array from the current set of specs |
185 | sub _process_specs_getopt_long | 185 | sub _process_specs_getopt_long |
186 | { | 186 | { |
187 | my $self = shift; | 187 | my $self = shift; |
188 | 188 | ||
@@ -217,7 +217,7 @@ sub _check_required_opts | |||
217 | } | 217 | } |
218 | } | 218 | } |
219 | if (@missing) { | 219 | if (@missing) { |
220 | $self->_die($self->_usage . "\n" . | 220 | $self->_die($self->_usage . "\n" . |
221 | join("\n", map { sprintf "Missing argument: %s", $_ } @missing) . "\n"); | 221 | join("\n", map { sprintf "Missing argument: %s", $_ } @missing) . "\n"); |
222 | } | 222 | } |
223 | } | 223 | } |
@@ -243,7 +243,7 @@ sub _load_config_section | |||
243 | $section ||= $self->{_attr}->{plugin}; | 243 | $section ||= $self->{_attr}->{plugin}; |
244 | 244 | ||
245 | my $Config; | 245 | my $Config; |
246 | eval { $Config = Nagios::Plugin::Config->read($file); }; | 246 | eval { $Config = Monitoring::Plugin::Config->read($file); }; |
247 | $self->_die($@) if ($@); #TODO: add test? | 247 | $self->_die($@) if ($@); #TODO: add test? |
248 | 248 | ||
249 | # TODO: is this check sane? Does --extra-opts=foo require a [foo] section? | 249 | # TODO: is this check sane? Does --extra-opts=foo require a [foo] section? |
@@ -295,7 +295,7 @@ sub _cmdline | |||
295 | next if $key =~ m/^_/; | 295 | next if $key =~ m/^_/; |
296 | 296 | ||
297 | # Skip defaults and internals | 297 | # Skip defaults and internals |
298 | next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key}; | 298 | next if exists $DEFAULT{$key} && $hash->{$key} eq $DEFAULT{$key}; |
299 | next if grep { $key eq $_ } qw(help usage version extra-opts); | 299 | next if grep { $key eq $_ } qw(help usage version extra-opts); |
300 | next unless defined $hash->{$key}; | 300 | next unless defined $hash->{$key}; |
301 | 301 | ||
@@ -307,7 +307,7 @@ sub _cmdline | |||
307 | $value = $self->_cmdline_value($value); | 307 | $value = $self->_cmdline_value($value); |
308 | if (length($key) > 1) { | 308 | if (length($key) > 1) { |
309 | push @args, sprintf "--%s=%s", $key, $value; | 309 | push @args, sprintf "--%s=%s", $key, $value; |
310 | } | 310 | } |
311 | else { | 311 | else { |
312 | push @args, "-$key", $value; | 312 | push @args, "-$key", $value; |
313 | } | 313 | } |
@@ -445,7 +445,7 @@ sub _init | |||
445 | my $self = shift; | 445 | my $self = shift; |
446 | 446 | ||
447 | # Check params | 447 | # Check params |
448 | my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0); | 448 | my $plugin = basename($ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0); |
449 | my %attr = validate( @_, { | 449 | my %attr = validate( @_, { |
450 | usage => 1, | 450 | usage => 1, |
451 | version => 0, | 451 | version => 0, |
@@ -470,7 +470,7 @@ sub _init | |||
470 | $self | 470 | $self |
471 | } | 471 | } |
472 | 472 | ||
473 | sub new | 473 | sub new |
474 | { | 474 | { |
475 | my $class = shift; | 475 | my $class = shift; |
476 | my $self = bless {}, $class; | 476 | my $self = bless {}, $class; |
@@ -485,20 +485,20 @@ __END__ | |||
485 | 485 | ||
486 | =head1 NAME | 486 | =head1 NAME |
487 | 487 | ||
488 | Nagios::Plugin::Getopt - OO perl module providing standardised argument | 488 | Monitoring::Plugin::Getopt - OO perl module providing standardised argument |
489 | processing for Nagios plugins | 489 | processing for Nagios plugins |
490 | 490 | ||
491 | 491 | ||
492 | =head1 SYNOPSIS | 492 | =head1 SYNOPSIS |
493 | 493 | ||
494 | use Nagios::Plugin::Getopt; | 494 | use Monitoring::Plugin::Getopt; |
495 | 495 | ||
496 | # Instantiate object (usage is mandatory) | 496 | # Instantiate object (usage is mandatory) |
497 | $ng = Nagios::Plugin::Getopt->new( | 497 | $ng = Monitoring::Plugin::Getopt->new( |
498 | usage => "Usage: %s -H <host> -w <warning> -c <critical>", | 498 | usage => "Usage: %s -H <host> -w <warning> -c <critical>", |
499 | version => '0.1', | 499 | version => '0.1', |
500 | url => 'http://www.openfusion.com.au/labs/nagios/', | 500 | url => 'http://www.openfusion.com.au/labs/nagios/', |
501 | blurb => 'This plugin tests various stuff.', | 501 | blurb => 'This plugin tests various stuff.', |
502 | ); | 502 | ); |
503 | 503 | ||
504 | # Add argument - named parameters (spec and help are mandatory) | 504 | # Add argument - named parameters (spec and help are mandatory) |
@@ -509,7 +509,7 @@ processing for Nagios plugins | |||
509 | default => 10, | 509 | default => 10, |
510 | ); | 510 | ); |
511 | 511 | ||
512 | # Add argument - positional parameters - arg spec, help text, | 512 | # Add argument - positional parameters - arg spec, help text, |
513 | # default value, required? (first two mandatory) | 513 | # default value, required? (first two mandatory) |
514 | $ng->arg( | 514 | $ng->arg( |
515 | 'warning|w=i', | 515 | 'warning|w=i', |
@@ -528,23 +528,23 @@ processing for Nagios plugins | |||
528 | 528 | ||
529 | =head1 DESCRIPTION | 529 | =head1 DESCRIPTION |
530 | 530 | ||
531 | Nagios::Plugin::Getopt is an OO perl module providing standardised and | 531 | Monitoring::Plugin::Getopt is an OO perl module providing standardised and |
532 | simplified argument processing for Nagios plugins. It implements | 532 | simplified argument processing for Nagios plugins. It implements |
533 | a number of standard arguments itself (--help, --version, | 533 | a number of standard arguments itself (--help, --version, |
534 | --usage, --timeout, --verbose, and their short form counterparts), | 534 | --usage, --timeout, --verbose, and their short form counterparts), |
535 | produces standardised nagios plugin help output, and allows | 535 | produces standardised nagios plugin help output, and allows |
536 | additional arguments to be easily defined. | 536 | additional arguments to be easily defined. |
537 | 537 | ||
538 | 538 | ||
539 | =head2 CONSTRUCTOR | 539 | =head2 CONSTRUCTOR |
540 | 540 | ||
541 | # Instantiate object (usage is mandatory) | 541 | # Instantiate object (usage is mandatory) |
542 | $ng = Nagios::Plugin::Getopt->new( | 542 | $ng = Monitoring::Plugin::Getopt->new( |
543 | usage => 'Usage: %s --hello', | 543 | usage => 'Usage: %s --hello', |
544 | version => '0.01', | 544 | version => '0.01', |
545 | ); | 545 | ); |
546 | 546 | ||
547 | The Nagios::Plugin::Getopt constructor accepts the following named | 547 | The Monitoring::Plugin::Getopt constructor accepts the following named |
548 | arguments: | 548 | arguments: |
549 | 549 | ||
550 | =over 4 | 550 | =over 4 |
@@ -573,7 +573,7 @@ the longer --help output. e.g. | |||
573 | 573 | ||
574 | =item url | 574 | =item url |
575 | 575 | ||
576 | URL for info about this plugin, included in the --version/-V output, | 576 | URL for info about this plugin, included in the --version/-V output, |
577 | and in the longer --help output (see preceding 'version' example). | 577 | and in the longer --help output (see preceding 'version' example). |
578 | 578 | ||
579 | =item blurb | 579 | =item blurb |
@@ -583,20 +583,20 @@ Short plugin description, included in the longer --help output | |||
583 | 583 | ||
584 | =item license | 584 | =item license |
585 | 585 | ||
586 | License text, included in the longer --help output (see below for an | 586 | License text, included in the longer --help output (see below for an |
587 | example). By default, this is set to the standard nagios plugins | 587 | example). By default, this is set to the standard nagios plugins |
588 | GPL license text: | 588 | GPL license text: |
589 | 589 | ||
590 | This nagios plugin is free software, and comes with ABSOLUTELY | 590 | This nagios plugin is free software, and comes with ABSOLUTELY |
591 | NO WARRANTY. It may be used, redistributed and/or modified under | 591 | NO WARRANTY. It may be used, redistributed and/or modified under |
592 | the terms of the GNU General Public Licence (see | 592 | the terms of the GNU General Public Licence (see |
593 | http://www.fsf.org/licensing/licenses/gpl.txt). | 593 | http://www.fsf.org/licensing/licenses/gpl.txt). |
594 | 594 | ||
595 | Provide your own to replace this text in the help output. | 595 | Provide your own to replace this text in the help output. |
596 | 596 | ||
597 | =item extra | 597 | =item extra |
598 | 598 | ||
599 | Extra text to be appended at the end of the longer --help output. | 599 | Extra text to be appended at the end of the longer --help output. |
600 | 600 | ||
601 | =item plugin | 601 | =item plugin |
602 | 602 | ||
@@ -605,7 +605,7 @@ usually correct, but you can set it explicitly if not. | |||
605 | 605 | ||
606 | =item timeout | 606 | =item timeout |
607 | 607 | ||
608 | Timeout period in seconds, overriding the standard timeout default | 608 | Timeout period in seconds, overriding the standard timeout default |
609 | (15 seconds). | 609 | (15 seconds). |
610 | 610 | ||
611 | =back | 611 | =back |
@@ -630,8 +630,8 @@ example: | |||
630 | $ ./check_tcp_range -h | 630 | $ ./check_tcp_range -h |
631 | check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/] | 631 | check_tcp_range 0.2 [http://www.openfusion.com.au/labs/nagios/] |
632 | 632 | ||
633 | This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. | 633 | This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. |
634 | It may be used, redistributed and/or modified under the terms of the GNU | 634 | It may be used, redistributed and/or modified under the terms of the GNU |
635 | General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt). | 635 | General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt). |
636 | 636 | ||
637 | This plugin tests arbitrary ranges/sets of tcp ports for a host. | 637 | This plugin tests arbitrary ranges/sets of tcp ports for a host. |
@@ -647,7 +647,7 @@ example: | |||
647 | Host name or IP address | 647 | Host name or IP address |
648 | -p, --ports=STRING | 648 | -p, --ports=STRING |
649 | Port numbers to check. Format: comma-separated, colons for ranges, | 649 | Port numbers to check. Format: comma-separated, colons for ranges, |
650 | no spaces e.g. 8700:8705,8710:8715,8760 | 650 | no spaces e.g. 8700:8705,8710:8715,8760 |
651 | -t, --timeout=INTEGER | 651 | -t, --timeout=INTEGER |
652 | Seconds before plugin times out (default: 15) | 652 | Seconds before plugin times out (default: 15) |
653 | -v, --verbose | 653 | -v, --verbose |
@@ -656,14 +656,14 @@ example: | |||
656 | 656 | ||
657 | =head2 ARGUMENTS | 657 | =head2 ARGUMENTS |
658 | 658 | ||
659 | You can define arguments for your plugin using the arg() method, which | 659 | You can define arguments for your plugin using the arg() method, which |
660 | supports both named and positional arguments. In both cases | 660 | supports both named and positional arguments. In both cases |
661 | the C<spec> and C<help> arguments are required, while the C<label>, | 661 | the C<spec> and C<help> arguments are required, while the C<label>, |
662 | C<default>, and C<required> arguments are optional: | 662 | C<default>, and C<required> arguments are optional: |
663 | 663 | ||
664 | # Define --hello argument (named parameters) | 664 | # Define --hello argument (named parameters) |
665 | $ng->arg( | 665 | $ng->arg( |
666 | spec => 'hello|h=s', | 666 | spec => 'hello|h=s', |
667 | help => "Hello string", | 667 | help => "Hello string", |
668 | required => 1, | 668 | required => 1, |
669 | ); | 669 | ); |
@@ -710,12 +710,12 @@ The help string is munged in two ways: | |||
710 | 710 | ||
711 | =item | 711 | =item |
712 | 712 | ||
713 | First, if the help string does NOT begins with a '-' sign, it is prefixed | 713 | First, if the help string does NOT begins with a '-' sign, it is prefixed |
714 | by an expanded form of the C<spec> argument. For instance, the following | 714 | by an expanded form of the C<spec> argument. For instance, the following |
715 | hello argument: | 715 | hello argument: |
716 | 716 | ||
717 | $ng->arg( | 717 | $ng->arg( |
718 | spec => 'hello|h=s', | 718 | spec => 'hello|h=s', |
719 | help => "Hello string", | 719 | help => "Hello string", |
720 | ); | 720 | ); |
721 | 721 | ||
@@ -727,9 +727,9 @@ would be displayed in the help output as: | |||
727 | where the '-h, --hello=STRING' part is derived from the spec definition | 727 | where the '-h, --hello=STRING' part is derived from the spec definition |
728 | (by convention with short args first, then long, then label/type, if any). | 728 | (by convention with short args first, then long, then label/type, if any). |
729 | 729 | ||
730 | =item | 730 | =item |
731 | 731 | ||
732 | Second, if the string contains a '%s' it will be formatted via | 732 | Second, if the string contains a '%s' it will be formatted via |
733 | C<sprintf> with the 'default' as the argument i.e. | 733 | C<sprintf> with the 'default' as the argument i.e. |
734 | 734 | ||
735 | sprintf($help, $default) | 735 | sprintf($help, $default) |
@@ -756,18 +756,18 @@ would be displayed in the help output as: | |||
756 | Exit with WARNING status if less than PERCENT of disk space is free | 756 | Exit with WARNING status if less than PERCENT of disk space is free |
757 | 757 | ||
758 | Note that in this case we've also specified explicit labels in another | 758 | Note that in this case we've also specified explicit labels in another |
759 | arrayref corresponding to the C<help> one - if this had been omitted | 759 | arrayref corresponding to the C<help> one - if this had been omitted |
760 | the types would have defaulted to 'STRING', instead of 'BYTES' and | 760 | the types would have defaulted to 'STRING', instead of 'BYTES' and |
761 | 'PERCENT%'. | 761 | 'PERCENT%'. |
762 | 762 | ||
763 | 763 | ||
764 | =item label | 764 | =item label |
765 | 765 | ||
766 | The C<label> argument is a scalar or an arrayref (see 'Multi-line help' | 766 | The C<label> argument is a scalar or an arrayref (see 'Multi-line help' |
767 | description above) that overrides the standard type expansion when generating | 767 | description above) that overrides the standard type expansion when generating |
768 | help text from the spec definition. By default, C<spec=i> arguments are | 768 | help text from the spec definition. By default, C<spec=i> arguments are |
769 | labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled | 769 | labelled as C<=INTEGER> in the help text, and C<spec=s> arguments are labelled |
770 | as C<=STRING>. By supplying your own C<label> argument you can override these | 770 | as C<=STRING>. By supplying your own C<label> argument you can override these |
771 | standard 'INTEGER' and 'STRING' designations. | 771 | standard 'INTEGER' and 'STRING' designations. |
772 | 772 | ||
773 | For multi-line help, you can supply an ordered list (arrayref) of labels to | 773 | For multi-line help, you can supply an ordered list (arrayref) of labels to |
@@ -789,13 +789,13 @@ if none is explicitly supplied. | |||
789 | 789 | ||
790 | =item required | 790 | =item required |
791 | 791 | ||
792 | The C<required> argument is a boolean used to indicate that this argument | 792 | The C<required> argument is a boolean used to indicate that this argument |
793 | is mandatory (Nagios::Plugin::Getopt will exit with your usage message and | 793 | is mandatory (Monitoring::Plugin::Getopt will exit with your usage message and |
794 | a 'Missing argument' indicator if any required arguments are not supplied). | 794 | a 'Missing argument' indicator if any required arguments are not supplied). |
795 | 795 | ||
796 | =back | 796 | =back |
797 | 797 | ||
798 | Note that --help lists your arguments in the order they are defined, so | 798 | Note that --help lists your arguments in the order they are defined, so |
799 | you should order your C<arg()> calls accordingly. | 799 | you should order your C<arg()> calls accordingly. |
800 | 800 | ||
801 | 801 | ||
@@ -809,7 +809,7 @@ method, which takes no arguments: | |||
809 | 809 | ||
810 | This parses the command line arguments passed to your plugin using | 810 | This parses the command line arguments passed to your plugin using |
811 | Getopt::Long and the builtin and provided argument specifications. | 811 | Getopt::Long and the builtin and provided argument specifications. |
812 | Flags and argument values are recorded within the object, and can | 812 | Flags and argument values are recorded within the object, and can |
813 | be accessed either using the generic get() accessor, or using named | 813 | be accessed either using the generic get() accessor, or using named |
814 | accessors corresponding to your argument names. For example: | 814 | accessors corresponding to your argument names. For example: |
815 | 815 | ||
@@ -824,14 +824,14 @@ accessors corresponding to your argument names. For example: | |||
824 | # ... | 824 | # ... |
825 | } | 825 | } |
826 | 826 | ||
827 | Note that where you have defined alternate argument names, the first is | 827 | Note that where you have defined alternate argument names, the first is |
828 | considered the citation form. All the builtin arguments are available | 828 | considered the citation form. All the builtin arguments are available |
829 | using their long variant names. | 829 | using their long variant names. |
830 | 830 | ||
831 | 831 | ||
832 | =head2 BUILTIN PROCESSING | 832 | =head2 BUILTIN PROCESSING |
833 | 833 | ||
834 | The C<getopts()> method also handles processing of the immediate builtin | 834 | The C<getopts()> method also handles processing of the immediate builtin |
835 | arguments, namely --usage, --version, --help, as well as checking all | 835 | arguments, namely --usage, --version, --help, as well as checking all |
836 | required arguments have been supplied, so you don't have to handle | 836 | required arguments have been supplied, so you don't have to handle |
837 | those yourself. This means that your plugin will exit from the getopts() | 837 | 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 | |||
842 | 842 | ||
843 | alarm $ng->timeout; | 843 | alarm $ng->timeout; |
844 | 844 | ||
845 | around any blocking operations within your plugin (which you are free | 845 | around any blocking operations within your plugin (which you are free |
846 | to override if you want to use a custom timeout message). | 846 | to override if you want to use a custom timeout message). |
847 | 847 | ||
848 | 848 | ||
849 | =head1 SEE ALSO | 849 | =head1 SEE ALSO |
850 | 850 | ||
851 | Nagios::Plugin, Getopt::Long | 851 | Monitoring::Plugin, Getopt::Long |
852 | 852 | ||
853 | 853 | ||
854 | =head1 AUTHOR | 854 | =head1 AUTHOR |
855 | 855 | ||
856 | Gavin Carr <gavin@openfusion.com.au> | 856 | This code is maintained by the Monitoring Plugin Development Team: see |
857 | https://monitoring-plugins.org | ||
857 | 858 | ||
859 | Originally: | ||
860 | Gavin Carr <gavin@openfusion.com.au> | ||
858 | 861 | ||
859 | =head1 COPYRIGHT AND LICENSE | 862 | =head1 COPYRIGHT AND LICENSE |
860 | 863 | ||
861 | Copyright (C) 2006-2007 by the Nagios Plugin Development Team. | 864 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
862 | 865 | ||
863 | This module is free software. It may be used, redistributed | 866 | This library is free software; you can redistribute it and/or modify |
864 | and/or modified under either the terms of the Perl Artistic | 867 | it under the same terms as Perl itself. |
865 | License (see http://www.perl.com/perl/misc/Artistic.html) | ||
866 | or the GNU General Public Licence (see | ||
867 | http://www.fsf.org/licensing/licenses/gpl.txt). | ||
868 | 868 | ||
869 | =cut | 869 | =cut |
870 | |||
871 | # arch-tag: c917effc-7400-4ee5-a5d6-baa9316a3abf | ||
872 | # vim:smartindent:sw=2:et | ||
873 | |||
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Monitoring/Plugin/Performance.pm index 9248fea..90fc9f4 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Monitoring/Plugin/Performance.pm | |||
@@ -1,4 +1,4 @@ | |||
1 | package Nagios::Plugin::Performance; | 1 | package Monitoring::Plugin::Performance; |
2 | 2 | ||
3 | use 5.006; | 3 | use 5.006; |
4 | 4 | ||
@@ -11,15 +11,15 @@ __PACKAGE__->mk_ro_accessors( | |||
11 | qw(label value uom warning critical min max) | 11 | qw(label value uom warning critical min max) |
12 | ); | 12 | ); |
13 | 13 | ||
14 | use Nagios::Plugin::Functions; | 14 | use Monitoring::Plugin::Functions; |
15 | use Nagios::Plugin::Threshold; | 15 | use Monitoring::Plugin::Threshold; |
16 | use Nagios::Plugin::Range; | 16 | use Monitoring::Plugin::Range; |
17 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 17 | our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
18 | 18 | ||
19 | sub import { | 19 | sub import { |
20 | my ($class, %attr) = @_; | 20 | my ($class, %attr) = @_; |
21 | $_ = $attr{use_die} || 0; | 21 | $_ = $attr{use_die} || 0; |
22 | Nagios::Plugin::Functions::_use_die($_); | 22 | Monitoring::Plugin::Functions::_use_die($_); |
23 | } | 23 | } |
24 | 24 | ||
25 | # This is NOT the same as N::P::Functions::value_re. We leave that to be the strict | 25 | # This is NOT the same as N::P::Functions::value_re. We leave that to be the strict |
@@ -46,7 +46,7 @@ sub _parse { | |||
46 | return undef if $not_value; | 46 | return undef if $not_value; |
47 | } | 47 | } |
48 | my $p = $class->new( | 48 | my $p = $class->new( |
49 | label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4], | 49 | label => $info[0], value => $performance_value, uom => $info[2], warning => $info[3], critical => $info[4], |
50 | min => $info[5], max => $info[6] | 50 | min => $info[5], max => $info[6] |
51 | ); | 51 | ); |
52 | return $p; | 52 | return $p; |
@@ -128,13 +128,13 @@ sub clean_label { | |||
128 | sub threshold | 128 | sub threshold |
129 | { | 129 | { |
130 | my $self = shift; | 130 | my $self = shift; |
131 | return Nagios::Plugin::Threshold->set_thresholds( | 131 | return Monitoring::Plugin::Threshold->set_thresholds( |
132 | warning => $self->warning, critical => $self->critical | 132 | warning => $self->warning, critical => $self->critical |
133 | ); | 133 | ); |
134 | } | 134 | } |
135 | 135 | ||
136 | # Constructor - unpack thresholds, map args to hashref | 136 | # Constructor - unpack thresholds, map args to hashref |
137 | sub new | 137 | sub new |
138 | { | 138 | { |
139 | my $class = shift; | 139 | my $class = shift; |
140 | my %arg = @_; | 140 | my %arg = @_; |
@@ -154,15 +154,15 @@ __END__ | |||
154 | 154 | ||
155 | =head1 NAME | 155 | =head1 NAME |
156 | 156 | ||
157 | Nagios::Plugin::Performance - class for handling Nagios::Plugin | 157 | Monitoring::Plugin::Performance - class for handling Monitoring::Plugin |
158 | performance data. | 158 | performance data. |
159 | 159 | ||
160 | =head1 SYNOPSIS | 160 | =head1 SYNOPSIS |
161 | 161 | ||
162 | use Nagios::Plugin::Performance use_die => 1; | 162 | use Monitoring::Plugin::Performance use_die => 1; |
163 | 163 | ||
164 | # Constructor (also accepts a 'threshold' obj instead of warning/critical) | 164 | # Constructor (also accepts a 'threshold' obj instead of warning/critical) |
165 | $p = Nagios::Plugin::Performance->new( | 165 | $p = Monitoring::Plugin::Performance->new( |
166 | label => 'size', | 166 | label => 'size', |
167 | value => $value, | 167 | value => $value, |
168 | uom => "kB", | 168 | uom => "kB", |
@@ -173,9 +173,9 @@ performance data. | |||
173 | ); | 173 | ); |
174 | 174 | ||
175 | # Parser | 175 | # Parser |
176 | @perf = Nagios::Plugin::Performance->parse_perfstring( | 176 | @perf = Monitoring::Plugin::Performance->parse_perfstring( |
177 | "/=382MB;15264;15269;; /var=218MB;9443;9448" | 177 | "/=382MB;15264;15269;; /var=218MB;9443;9448" |
178 | ) | 178 | ) |
179 | or warn("Failed to parse perfstring"); | 179 | or warn("Failed to parse perfstring"); |
180 | 180 | ||
181 | # Accessors | 181 | # Accessors |
@@ -197,14 +197,14 @@ performance data. | |||
197 | 197 | ||
198 | =head1 DESCRIPTION | 198 | =head1 DESCRIPTION |
199 | 199 | ||
200 | Nagios::Plugin class for handling performance data. This is a public | 200 | Monitoring::Plugin class for handling performance data. This is a public |
201 | interface because it could be used by performance graphing routines, | 201 | interface because it could be used by performance graphing routines, |
202 | such as nagiostat (http://nagiostat.sourceforge.net), perfparse | 202 | such as nagiostat (http://nagiostat.sourceforge.net), perfparse |
203 | (http://perfparse.sourceforge.net), nagiosgraph | 203 | (http://perfparse.sourceforge.net), nagiosgraph |
204 | (http://nagiosgraph.sourceforge.net) or NagiosGrapher | 204 | (http://nagiosgraph.sourceforge.net) or NagiosGrapher |
205 | (http://www.nagiosexchange.org/NagiosGrapher.84.0.html). | 205 | (http://www.nagiosexchange.org/NagiosGrapher.84.0.html). |
206 | 206 | ||
207 | Nagios::Plugin::Performance offers both a parsing interface (via | 207 | Monitoring::Plugin::Performance offers both a parsing interface (via |
208 | parse_perfstring), for turning nagios performance output strings into | 208 | parse_perfstring), for turning nagios performance output strings into |
209 | their components, and a composition interface (via new), for turning | 209 | their components, and a composition interface (via new), for turning |
210 | components into perfdata strings. | 210 | components into perfdata strings. |
@@ -213,7 +213,7 @@ components into perfdata strings. | |||
213 | 213 | ||
214 | If you are using this module for the purposes of parsing perf data, you | 214 | If you are using this module for the purposes of parsing perf data, you |
215 | will probably want to set use_die => 1 at use time. This forces | 215 | will probably want to set use_die => 1 at use time. This forces |
216 | &Nagios::Plugin::Functions::nagios_exit to call die() - rather than exit() - | 216 | &Monitoring::Plugin::Functions::plugin_exit to call die() - rather than exit() - |
217 | when an error occurs. This is then trappable by an eval. If you don't set use_die, | 217 | when an error occurs. This is then trappable by an eval. If you don't set use_die, |
218 | then an error in these modules will cause your script to exit | 218 | then an error in these modules will cause your script to exit |
219 | 219 | ||
@@ -221,14 +221,14 @@ then an error in these modules will cause your script to exit | |||
221 | 221 | ||
222 | =over 4 | 222 | =over 4 |
223 | 223 | ||
224 | =item Nagios::Plugin::Performance->new(%attributes) | 224 | =item Monitoring::Plugin::Performance->new(%attributes) |
225 | 225 | ||
226 | Instantiates a new Nagios::Plugin::Performance object with the given | 226 | Instantiates a new Monitoring::Plugin::Performance object with the given |
227 | attributes. | 227 | attributes. |
228 | 228 | ||
229 | =item Nagios::Plugin::Performance->parse_perfstring($string) | 229 | =item Monitoring::Plugin::Performance->parse_perfstring($string) |
230 | 230 | ||
231 | Returns an array of Nagios::Plugin::Performance objects based on the string | 231 | Returns an array of Monitoring::Plugin::Performance objects based on the string |
232 | entered. If there is an error parsing the string - which may consists of several | 232 | entered. If there is an error parsing the string - which may consists of several |
233 | sets of data - will return an array with all the successfully parsed sets. | 233 | sets of data - will return an array with all the successfully parsed sets. |
234 | 234 | ||
@@ -247,18 +247,18 @@ These all return scalars. min and max are not well supported yet. | |||
247 | 247 | ||
248 | =item threshold | 248 | =item threshold |
249 | 249 | ||
250 | Returns a Nagios::Plugin::Threshold object holding the warning and critical | 250 | Returns a Monitoring::Plugin::Threshold object holding the warning and critical |
251 | ranges for this performance data (if any). | 251 | ranges for this performance data (if any). |
252 | 252 | ||
253 | =item rrdlabel | 253 | =item rrdlabel |
254 | 254 | ||
255 | Returns a string based on 'label' that is suitable for use as dataset name of | 255 | Returns a string based on 'label' that is suitable for use as dataset name of |
256 | an RRD i.e. munges label to be 1-19 characters long with only characters | 256 | an RRD i.e. munges label to be 1-19 characters long with only characters |
257 | [a-zA-Z0-9_]. | 257 | [a-zA-Z0-9_]. |
258 | 258 | ||
259 | This calls $self->clean_label and then truncates to 19 characters. | 259 | This calls $self->clean_label and then truncates to 19 characters. |
260 | 260 | ||
261 | There is no guarantee that multiple N:P:Performance objects will have unique | 261 | There is no guarantee that multiple N:P:Performance objects will have unique |
262 | rrdlabels. | 262 | rrdlabels. |
263 | 263 | ||
264 | =item clean_label | 264 | =item clean_label |
@@ -270,25 +270,25 @@ It also converts "/" to "root" and "/{name}" to "{name}". | |||
270 | 270 | ||
271 | =item perfoutput | 271 | =item perfoutput |
272 | 272 | ||
273 | Outputs the data in Nagios::Plugin perfdata format i.e. | 273 | Outputs the data in Monitoring::Plugin perfdata format i.e. |
274 | label=value[uom];[warn];[crit];[min];[max]. | 274 | label=value[uom];[warn];[crit];[min];[max]. |
275 | 275 | ||
276 | =back | 276 | =back |
277 | 277 | ||
278 | =head1 SEE ALSO | 278 | =head1 SEE ALSO |
279 | 279 | ||
280 | Nagios::Plugin, Nagios::Plugin::Threshold, http://nagiosplug.sourceforge.net. | 280 | Monitoring::Plugin, Monitoring::Plugin::Threshold, https://www.monitoring-plugins.org/doc/guidelines.html |
281 | 281 | ||
282 | =head1 AUTHOR | 282 | =head1 AUTHOR |
283 | 283 | ||
284 | This code is maintained by the Nagios Plugin Development Team: see | 284 | This code is maintained by the Monitoring Plugin Development Team: see |
285 | http://nagiosplug.sourceforge.net. | 285 | https://monitoring-plugins.org |
286 | 286 | ||
287 | =head1 COPYRIGHT AND LICENSE | 287 | =head1 COPYRIGHT AND LICENSE |
288 | 288 | ||
289 | Copyright (C) 2006-2007 Nagios Plugin Development Team | 289 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
290 | 290 | ||
291 | This library is free software; you can redistribute it and/or modify | 291 | This library is free software; you can redistribute it and/or modify |
292 | it under the same terms as Perl itself. | 292 | it under the same terms as Perl itself. |
293 | 293 | ||
294 | =cut | 294 | =cut |
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Monitoring/Plugin/Range.pm index 536f6bb..af19577 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Monitoring/Plugin/Range.pm | |||
@@ -1,4 +1,4 @@ | |||
1 | package Nagios::Plugin::Range; | 1 | package Monitoring::Plugin::Range; |
2 | 2 | ||
3 | use 5.006; | 3 | use 5.006; |
4 | 4 | ||
@@ -11,8 +11,8 @@ __PACKAGE__->mk_accessors( | |||
11 | qw(start end start_infinity end_infinity alert_on) | 11 | qw(start end start_infinity end_infinity alert_on) |
12 | ); | 12 | ); |
13 | 13 | ||
14 | use Nagios::Plugin::Functions qw(:DEFAULT $value_re); | 14 | use Monitoring::Plugin::Functions qw(:DEFAULT $value_re); |
15 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 15 | our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
16 | 16 | ||
17 | use overload | 17 | use overload |
18 | 'eq' => sub { shift->_stringify }, | 18 | 'eq' => sub { shift->_stringify }, |
@@ -26,7 +26,7 @@ sub _stringify { | |||
26 | my $self = shift; | 26 | my $self = shift; |
27 | return "" unless $self->is_set; | 27 | return "" unless $self->is_set; |
28 | return (($self->alert_on) ? "@" : "") . | 28 | return (($self->alert_on) ? "@" : "") . |
29 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . | 29 | (($self->start_infinity == 1) ? "~:" : (($self->start == 0)?"":$self->start.":")) . |
30 | (($self->end_infinity == 1) ? "" : $self->end); | 30 | (($self->end_infinity == 1) ? "" : $self->end); |
31 | } | 31 | } |
32 | 32 | ||
@@ -47,7 +47,7 @@ sub _set_range_end { | |||
47 | $self->end_infinity(0); | 47 | $self->end_infinity(0); |
48 | } | 48 | } |
49 | 49 | ||
50 | # Returns a N::P::Range object if the string is a conforms to a Nagios Plugin range string, otherwise null | 50 | # Returns a N::P::Range object if the string is a conforms to a Monitoring Plugin range string, otherwise null |
51 | sub parse_range_string { | 51 | sub parse_range_string { |
52 | my ($class, $string) = @_; | 52 | my ($class, $string) = @_; |
53 | my $valid = 0; | 53 | my $valid = 0; |
@@ -118,7 +118,7 @@ sub check_range { | |||
118 | } | 118 | } |
119 | 119 | ||
120 | # Constructor - map args to hashref for SUPER | 120 | # Constructor - map args to hashref for SUPER |
121 | sub new | 121 | sub new |
122 | { | 122 | { |
123 | shift->SUPER::new({ @_ }); | 123 | shift->SUPER::new({ @_ }); |
124 | } | 124 | } |
@@ -129,18 +129,18 @@ __END__ | |||
129 | 129 | ||
130 | =head1 NAME | 130 | =head1 NAME |
131 | 131 | ||
132 | Nagios::Plugin::Range - class for handling Nagios::Plugin range data. | 132 | Monitoring::Plugin::Range - class for handling Monitoring::Plugin range data. |
133 | 133 | ||
134 | =head1 SYNOPSIS | 134 | =head1 SYNOPSIS |
135 | 135 | ||
136 | # NB: This is an internal Nagios::Plugin class. | 136 | # NB: This is an internal Monitoring::Plugin class. |
137 | # See Nagios::Plugin itself for public interfaces. | 137 | # See Monitoring::Plugin itself for public interfaces. |
138 | 138 | ||
139 | # Instantiate an empty range object | 139 | # Instantiate an empty range object |
140 | $r = Nagios::Plugin::Range->new; | 140 | $r = Monitoring::Plugin::Range->new; |
141 | 141 | ||
142 | # Instantiate by parsing a standard nagios range string | 142 | # Instantiate by parsing a standard nagios range string |
143 | $r = Nagios::Plugin::Range->parse_range_string( $range_str ); | 143 | $r = Monitoring::Plugin::Range->parse_range_string( $range_str ); |
144 | 144 | ||
145 | # Returns true if the range is defined/non-empty | 145 | # Returns true if the range is defined/non-empty |
146 | $r->is_set; | 146 | $r->is_set; |
@@ -151,17 +151,17 @@ Nagios::Plugin::Range - class for handling Nagios::Plugin range data. | |||
151 | 151 | ||
152 | =head1 DESCRIPTION | 152 | =head1 DESCRIPTION |
153 | 153 | ||
154 | Internal Nagios::Plugin class for handling common range data. See | 154 | Internal Monitoring::Plugin class for handling common range data. See |
155 | Nagios::Plugin for public interfaces. | 155 | Monitoring::Plugin for public interfaces. |
156 | 156 | ||
157 | =head1 AUTHOR | 157 | =head1 AUTHOR |
158 | 158 | ||
159 | This code is maintained by the Nagios Plugin Development Team: see | 159 | This code is maintained by the Monitoring Plugin Development Team: see |
160 | http://nagiosplug.sourceforge.net. | 160 | https://monitoring-plugins.org |
161 | 161 | ||
162 | =head1 COPYRIGHT AND LICENSE | 162 | =head1 COPYRIGHT AND LICENSE |
163 | 163 | ||
164 | Copyright (C) 2006-2007 Nagios Plugin Development Team | 164 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
165 | 165 | ||
166 | This library is free software; you can redistribute it and/or modify | 166 | This library is free software; you can redistribute it and/or modify |
167 | it under the same terms as Perl itself. | 167 | it under the same terms as Perl itself. |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Monitoring/Plugin/Threshold.pm index 95a089b..e71e21b 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Monitoring/Plugin/Threshold.pm | |||
@@ -1,4 +1,4 @@ | |||
1 | package Nagios::Plugin::Threshold; | 1 | package Monitoring::Plugin::Threshold; |
2 | 2 | ||
3 | use 5.006; | 3 | use 5.006; |
4 | 4 | ||
@@ -8,11 +8,11 @@ use warnings; | |||
8 | use base qw(Class::Accessor::Fast); | 8 | use base qw(Class::Accessor::Fast); |
9 | __PACKAGE__->mk_accessors(qw(warning critical)); | 9 | __PACKAGE__->mk_accessors(qw(warning critical)); |
10 | 10 | ||
11 | use Nagios::Plugin::Range; | 11 | use Monitoring::Plugin::Range; |
12 | use Nagios::Plugin::Functions qw(:codes nagios_die); | 12 | use Monitoring::Plugin::Functions qw(:codes plugin_die); |
13 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; | 13 | our ($VERSION) = $Monitoring::Plugin::Functions::VERSION; |
14 | 14 | ||
15 | sub get_status | 15 | sub get_status |
16 | { | 16 | { |
17 | my ($self, $value) = @_; | 17 | my ($self, $value) = @_; |
18 | 18 | ||
@@ -22,7 +22,7 @@ sub get_status | |||
22 | return CRITICAL if $self->critical->check_range($v); | 22 | return CRITICAL if $self->critical->check_range($v); |
23 | } | 23 | } |
24 | } | 24 | } |
25 | foreach my $v (@$value) { | 25 | foreach my $v (@$value) { |
26 | if ($self->warning->is_set) { | 26 | if ($self->warning->is_set) { |
27 | return WARNING if $self->warning->check_range($v); | 27 | return WARNING if $self->warning->check_range($v); |
28 | } | 28 | } |
@@ -35,21 +35,21 @@ sub _inflate | |||
35 | my ($self, $value, $key) = @_; | 35 | my ($self, $value, $key) = @_; |
36 | 36 | ||
37 | # Return an undefined range if $value is undef | 37 | # Return an undefined range if $value is undef |
38 | return Nagios::Plugin::Range->new if ! defined $value; | 38 | return Monitoring::Plugin::Range->new if ! defined $value; |
39 | 39 | ||
40 | # For refs, check isa N::P::Range | 40 | # For refs, check isa N::P::Range |
41 | if (ref $value) { | 41 | if (ref $value) { |
42 | nagios_die("Invalid $key object: type " . ref $value) | 42 | plugin_die("Invalid $key object: type " . ref $value) |
43 | unless $value->isa("Nagios::Plugin::Range"); | 43 | unless $value->isa("Monitoring::Plugin::Range"); |
44 | return $value; | 44 | return $value; |
45 | } | 45 | } |
46 | 46 | ||
47 | # Another quick exit if $value is an empty string | 47 | # Another quick exit if $value is an empty string |
48 | return Nagios::Plugin::Range->new if $value eq ""; | 48 | return Monitoring::Plugin::Range->new if $value eq ""; |
49 | 49 | ||
50 | # Otherwise parse $value | 50 | # Otherwise parse $value |
51 | my $range = Nagios::Plugin::Range->parse_range_string($value); | 51 | my $range = Monitoring::Plugin::Range->parse_range_string($value); |
52 | nagios_die("Cannot parse $key range: '$value'") unless(defined($range)); | 52 | plugin_die("Cannot parse $key range: '$value'") unless(defined($range)); |
53 | return $range; | 53 | return $range; |
54 | } | 54 | } |
55 | 55 | ||
@@ -70,9 +70,9 @@ sub set | |||
70 | my ($key, $value) = @_; | 70 | my ($key, $value) = @_; |
71 | $self->SUPER::set($key, $self->_inflate($value, $key)); | 71 | $self->SUPER::set($key, $self->_inflate($value, $key)); |
72 | } | 72 | } |
73 | 73 | ||
74 | # Constructor - inflate scalars to N::P::Range objects | 74 | # Constructor - inflate scalars to N::P::Range objects |
75 | sub new | 75 | sub new |
76 | { | 76 | { |
77 | my ($self, %arg) = @_; | 77 | my ($self, %arg) = @_; |
78 | $self->SUPER::new({ | 78 | $self->SUPER::new({ |
@@ -86,15 +86,15 @@ __END__ | |||
86 | 86 | ||
87 | =head1 NAME | 87 | =head1 NAME |
88 | 88 | ||
89 | Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds. | 89 | Monitoring::Plugin::Threshold - class for handling Monitoring::Plugin thresholds. |
90 | 90 | ||
91 | =head1 SYNOPSIS | 91 | =head1 SYNOPSIS |
92 | 92 | ||
93 | # NB: This is an internal Nagios::Plugin class. | 93 | # NB: This is an internal Monitoring::Plugin class. |
94 | # See Nagios::Plugin itself for public interfaces. | 94 | # See Monitoring::Plugin itself for public interfaces. |
95 | 95 | ||
96 | # Constructor | 96 | # Constructor |
97 | $t = Nagios::Plugin::Threshold->set_thresholds( | 97 | $t = Monitoring::Plugin::Threshold->set_thresholds( |
98 | warning => $warning_range_string, | 98 | warning => $warning_range_string, |
99 | critical => $critical_range_string, | 99 | critical => $critical_range_string, |
100 | ); | 100 | ); |
@@ -110,10 +110,10 @@ Nagios::Plugin::Threshold - class for handling Nagios::Plugin thresholds. | |||
110 | 110 | ||
111 | =head1 DESCRIPTION | 111 | =head1 DESCRIPTION |
112 | 112 | ||
113 | Internal Nagios::Plugin class for handling threshold data. See | 113 | Internal Monitoring::Plugin class for handling threshold data. See |
114 | Nagios::Plugin for public interfaces. | 114 | Monitoring::Plugin for public interfaces. |
115 | 115 | ||
116 | A threshold object contains (typically) a pair of ranges, associated | 116 | A threshold object contains (typically) a pair of ranges, associated |
117 | with a particular severity e.g. | 117 | with a particular severity e.g. |
118 | 118 | ||
119 | warning => range1 | 119 | warning => range1 |
@@ -121,12 +121,12 @@ with a particular severity e.g. | |||
121 | 121 | ||
122 | =head1 AUTHOR | 122 | =head1 AUTHOR |
123 | 123 | ||
124 | This code is maintained by the Nagios Plugin Development Team: see | 124 | This code is maintained by the Monitoring Plugin Development Team: see |
125 | http://nagiosplug.sourceforge.net. | 125 | https://monitoring-plugins.org |
126 | 126 | ||
127 | =head1 COPYRIGHT AND LICENSE | 127 | =head1 COPYRIGHT AND LICENSE |
128 | 128 | ||
129 | Copyright (C) 2006-2007 Nagios Plugin Development Team | 129 | Copyright (C) 2006-2014 Monitoring Plugin Development Team |
130 | 130 | ||
131 | This library is free software; you can redistribute it and/or modify | 131 | This library is free software; you can redistribute it and/or modify |
132 | it under the same terms as Perl itself. | 132 | 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 @@ | |||
1 | # Tiny helper class to return both output and return_code when testing | ||
2 | |||
3 | package Nagios::Plugin::ExitResult; | ||
4 | |||
5 | use strict; | ||
6 | |||
7 | # Stringify to message | ||
8 | use overload '""' => sub { shift->{message} }; | ||
9 | |||
10 | # Constructor | ||
11 | sub new { | ||
12 | my $class = shift; | ||
13 | return bless { return_code => $_[0], message => $_[1] }, $class; | ||
14 | } | ||
15 | |||
16 | # Accessors | ||
17 | sub message { shift->{message} } | ||
18 | sub return_code { shift->{return_code} } | ||
19 | sub code { shift->{return_code} } | ||
20 | |||
21 | 1; | ||
22 | |||
23 | __END__ | ||
24 | |||
25 | =head1 NAME | ||
26 | |||
27 | Nagios::Plugin::ExitResult - Helper class for returning both output and | ||
28 | return codes when testing. | ||
29 | |||
30 | =head1 SYNOPSIS | ||
31 | |||
32 | use Test::More; | ||
33 | use Nagios::Plugin::Functions; | ||
34 | |||
35 | # In a test file somewhere | ||
36 | Nagios::Plugin::Functions::_fake_exit(1); | ||
37 | |||
38 | # Later ... | ||
39 | $e = nagios_exit( CRITICAL, 'aiiii ...' ); | ||
40 | print $e->message; | ||
41 | print $e->return_code; | ||
42 | |||
43 | # NP::ExitResult also stringifies to the message output | ||
44 | like(nagios_exit( WARNING, 'foobar'), qr/^foo/, 'matches!'); | ||
45 | |||
46 | |||
47 | |||
48 | =head1 DESCRIPTION | ||
49 | |||
50 | Nagios::Plugin::ExitResult is a tiny helper class intended for use | ||
51 | when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult | ||
52 | object is returned by nagios_exit() and friends when | ||
53 | Nagios::Plugin::Functions::_fake_exit has been set, instead of doing a | ||
54 | conventional print + exit. | ||
55 | |||
56 | =head1 AUTHOR | ||
57 | |||
58 | Gavin Carr , E<lt>gavin@openfusion.com.auE<gt> | ||
59 | |||
60 | =head1 COPYRIGHT AND LICENSE | ||
61 | |||
62 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
63 | |||
64 | This library is free software; you can redistribute it and/or modify | ||
65 | it under the same terms as Perl itself. | ||
66 | |||
67 | =cut | ||
diff --git a/t/Nagios-Plugin-01.t b/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 @@ | |||
1 | # Nagios::Plugin original test cases | 1 | # Monitoring::Plugin original test cases |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | use Test::More tests => 15; | 4 | use Test::More tests => 15; |
5 | 5 | ||
6 | BEGIN { use_ok('Nagios::Plugin') }; | 6 | BEGIN { use_ok('Monitoring::Plugin') }; |
7 | 7 | ||
8 | use Nagios::Plugin::Functions; | 8 | use Monitoring::Plugin::Functions; |
9 | Nagios::Plugin::Functions::_fake_exit(1); | 9 | Monitoring::Plugin::Functions::_fake_exit(1); |
10 | 10 | ||
11 | diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n" | 11 | diag "\nusing Monitoring::Plugin revision ". $Monitoring::Plugin::VERSION . "\n" |
12 | if $ENV{TEST_VERBOSE}; | 12 | if $ENV{TEST_VERBOSE}; |
13 | 13 | ||
14 | my $p = Nagios::Plugin->new(); | 14 | my $p = Monitoring::Plugin->new(); |
15 | isa_ok( $p, "Nagios::Plugin"); | 15 | isa_ok( $p, "Monitoring::Plugin"); |
16 | 16 | ||
17 | $p->shortname("PAGESIZE"); | 17 | $p->shortname("PAGESIZE"); |
18 | is($p->shortname, "PAGESIZE", "shortname explicitly set correctly"); | 18 | is($p->shortname, "PAGESIZE", "shortname explicitly set correctly"); |
19 | 19 | ||
20 | $p = Nagios::Plugin->new(); | 20 | $p = Monitoring::Plugin->new(); |
21 | is($p->shortname, "NAGIOS-PLUGIN-01", "shortname should default on new"); | 21 | is($p->shortname, "MONITORING-PLUGIN-01", "shortname should default on new"); |
22 | 22 | ||
23 | $p = Nagios::Plugin->new( shortname => "SIZE", () ); | 23 | $p = Monitoring::Plugin->new( shortname => "SIZE", () ); |
24 | is($p->shortname, "SIZE", "shortname set correctly on new"); | 24 | is($p->shortname, "SIZE", "shortname set correctly on new"); |
25 | 25 | ||
26 | $p = Nagios::Plugin->new( plugin => "check_stuff", () ); | 26 | $p = Monitoring::Plugin->new( plugin => "check_stuff", () ); |
27 | is($p->shortname, "STUFF", "shortname uses plugin name as default"); | 27 | is($p->shortname, "STUFF", "shortname uses plugin name as default"); |
28 | 28 | ||
29 | $p = Nagios::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () ); | 29 | $p = Monitoring::Plugin->new( shortname => "SIZE", plugin => "check_stuff", () ); |
30 | is($p->shortname, "SIZE", "shortname is not overriden by default"); | 30 | is($p->shortname, "SIZE", "shortname is not overriden by default"); |
31 | 31 | ||
32 | diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; | 32 | diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; |
@@ -37,10 +37,10 @@ use Data::Dumper; | |||
37 | #diag "dumping perfdata: ". Dumper $p->perfdata; | 37 | #diag "dumping perfdata: ". Dumper $p->perfdata; |
38 | 38 | ||
39 | 39 | ||
40 | $p->add_perfdata( | 40 | $p->add_perfdata( |
41 | label => "size", | 41 | label => "size", |
42 | value => 1, | 42 | value => 1, |
43 | uom => "kB", | 43 | uom => "kB", |
44 | threshold => $t, | 44 | threshold => $t, |
45 | ); | 45 | ); |
46 | 46 | ||
@@ -69,4 +69,3 @@ foreach (sort {$a<=>$b} keys %$expected) { | |||
69 | qr/$expected->{$_}/, | 69 | qr/$expected->{$_}/, |
70 | "Output okay. $_ = $expected->{$_}" ; | 70 | "Output okay. $_ = $expected->{$_}" ; |
71 | } | 71 | } |
72 | |||
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 @@ | |||
1 | # Monitoring::Plugin test set 2, testing MP::Functions wrapping | ||
2 | |||
3 | use strict; | ||
4 | use Test::More tests => 103; | ||
5 | |||
6 | BEGIN { use_ok("Monitoring::Plugin") } | ||
7 | require Monitoring::Plugin::Functions; | ||
8 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
9 | |||
10 | # Hardcoded checks of constants | ||
11 | my %ERRORS = %Monitoring::Plugin::Functions::ERRORS; | ||
12 | is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); | ||
13 | is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}"); | ||
14 | is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}"); | ||
15 | is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}"); | ||
16 | is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}"); | ||
17 | |||
18 | my $plugin = 'TEST_PLUGIN'; | ||
19 | my $np = Monitoring::Plugin->new( shortname => $plugin ); | ||
20 | is($np->shortname, $plugin, "shortname() is $plugin"); | ||
21 | |||
22 | # Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg ) | ||
23 | my $r; | ||
24 | my @ok = ( | ||
25 | [ OK, "OK", 'test the first', ], | ||
26 | [ WARNING, "WARNING", 'test the second', ], | ||
27 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
28 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
29 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
30 | ); | ||
31 | for (@ok) { | ||
32 | # CONSTANT | ||
33 | $r = $np->plugin_exit($_->[0], $_->[2]); | ||
34 | is($r->return_code, $_->[0], | ||
35 | sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
36 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
37 | sprintf('plugin_exit(%s, $msg) output matched "%s"', $_->[1], | ||
38 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
39 | |||
40 | # $string | ||
41 | $r = $np->plugin_exit($_->[1], $_->[2]); | ||
42 | is($r->return_code, $_->[0], | ||
43 | sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
44 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
45 | sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1], | ||
46 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
47 | like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
48 | sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1], | ||
49 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
50 | } | ||
51 | |||
52 | # plugin_exit code corner cases | ||
53 | my @ugly1 = ( | ||
54 | [ -1, 'testing code -1' ], | ||
55 | [ 7, 'testing code 7' ], | ||
56 | [ undef, 'testing code undef' ], | ||
57 | [ '', qq(testing code '') ], | ||
58 | [ 'string', qq(testing code 'string') ], | ||
59 | ); | ||
60 | for (@ugly1) { | ||
61 | $r = $np->plugin_exit($_->[0], $_->[1]); | ||
62 | my $display = defined $_->[0] ? "'$_->[0]'" : 'undef'; | ||
63 | is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN); | ||
64 | like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/, | ||
65 | sprintf('plugin_exit(%s, $msg) output matched "%s"', | ||
66 | $display, 'UNKNOWN.*' . $_->[1])); | ||
67 | } | ||
68 | |||
69 | # plugin_exit message corner cases | ||
70 | my @ugly2 = ( | ||
71 | [ '' ], | ||
72 | [ undef ], | ||
73 | [ UNKNOWN ], | ||
74 | ); | ||
75 | for (@ugly2) { | ||
76 | $r = $np->plugin_exit(CRITICAL, $_->[0]); | ||
77 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
78 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
79 | like($r->message, qr/CRITICAL\b.*\b$display2$/, | ||
80 | sprintf('plugin_exit(%s, $msg) output matched "%s"', | ||
81 | $display1, "CRITICAL.*$display2")); | ||
82 | } | ||
83 | |||
84 | # Test plugin_die( $msg ) | ||
85 | my @msg = ( | ||
86 | [ 'die you dog' ], | ||
87 | [ '' ], | ||
88 | [ undef ], | ||
89 | ); | ||
90 | for (@msg) { | ||
91 | $r = $np->plugin_die($_->[0]); | ||
92 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
93 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
94 | is($r->return_code, UNKNOWN, | ||
95 | sprintf('plugin_die(%s) returned UNKNOWN', $display1)); | ||
96 | like($r->message, qr/UNKNOWN\b.*\b$display2$/, | ||
97 | sprintf('plugin_die(%s) output matched "%s"', $display1, | ||
98 | "UNKNOWN.*$display2")); | ||
99 | } | ||
100 | |||
101 | # Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ), | ||
102 | # plugin_die( $string, $msg ), and plugin_die( $msg, $string ) | ||
103 | @ok = ( | ||
104 | [ OK, "OK", 'test the first', ], | ||
105 | [ WARNING, "WARNING", 'test the second', ], | ||
106 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
107 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
108 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
109 | ); | ||
110 | for (@ok) { | ||
111 | # CONSTANT, $msg | ||
112 | $r = $np->plugin_die($_->[0], $_->[2]); | ||
113 | is($r->return_code, $_->[0], | ||
114 | sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
115 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
116 | sprintf('plugin_die(%s, $msg) output matched "%s"', | ||
117 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
118 | |||
119 | # $msg, CONSTANT | ||
120 | $r = $np->plugin_die($_->[2], $_->[0]); | ||
121 | is($r->return_code, $_->[0], | ||
122 | sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0])); | ||
123 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
124 | sprintf('plugin_die($msg, %s) output matched "%s"', | ||
125 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
126 | |||
127 | # $string, $msg | ||
128 | $r = $np->plugin_die($_->[1], $_->[2]); | ||
129 | is($r->return_code, $_->[0], | ||
130 | sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
131 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
132 | sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1], | ||
133 | $_->[1] . '.*' . $_->[2])); | ||
134 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
135 | sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1], | ||
136 | $_->[1] . '.*' . $_->[2])); | ||
137 | |||
138 | # $string, $msg | ||
139 | $r = $np->plugin_die($_->[2], $_->[1]); | ||
140 | is($r->return_code, $_->[0], | ||
141 | sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0])); | ||
142 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
143 | sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1], | ||
144 | $_->[1] . '.*' . $_->[2])); | ||
145 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
146 | sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1], | ||
147 | $_->[1] . '.*' . $_->[2])); | ||
148 | } | ||
149 | |||
150 | |||
151 | # shortname testing | ||
152 | SKIP: { | ||
153 | skip "requires File::Basename", 2 unless eval { require File::Basename }; | ||
154 | $np = Monitoring::Plugin->new( version => "1"); | ||
155 | $plugin = uc File::Basename::basename($0); | ||
156 | $plugin =~ s/\..*$//; | ||
157 | is($np->shortname, $plugin, "shortname() is '$plugin'"); | ||
158 | $r = $np->plugin_exit(OK, "foobar"); | ||
159 | like($r->message, qr/^$plugin OK/, "message begins with '$plugin OK'"); | ||
160 | } | ||
diff --git a/t/Nagios-Plugin-03.t b/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 @@ | |||
3 | use strict; | 3 | use strict; |
4 | use Test::More tests => 61; | 4 | use Test::More tests => 61; |
5 | 5 | ||
6 | BEGIN { | 6 | BEGIN { |
7 | use_ok("Nagios::Plugin"); | 7 | use_ok("Monitoring::Plugin"); |
8 | use_ok("Nagios::Plugin::Functions", ":all"); | 8 | use_ok("Monitoring::Plugin::Functions", ":all"); |
9 | } | 9 | } |
10 | Nagios::Plugin::Functions::_fake_exit(1); | 10 | Monitoring::Plugin::Functions::_fake_exit(1); |
11 | 11 | ||
12 | my $plugin = 'NP_CHECK_MESSAGES_03'; | 12 | my $plugin = 'MP_CHECK_MESSAGES_03'; |
13 | my $np = Nagios::Plugin->new( shortname => $plugin, () ); | 13 | my $np = Monitoring::Plugin->new( shortname => $plugin, () ); |
14 | is($np->shortname, $plugin, "shortname() is $plugin"); | 14 | is($np->shortname, $plugin, "shortname() is $plugin"); |
15 | 15 | ||
16 | my ($code, $message); | 16 | my ($code, $message); |
17 | 17 | ||
@@ -113,11 +113,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message") | |||
113 | # ------------------------------------------------------------------------- | 113 | # ------------------------------------------------------------------------- |
114 | # join_all messages | 114 | # join_all messages |
115 | my $join_all = ' :: '; | 115 | my $join_all = ' :: '; |
116 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } | 116 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } |
117 | qw(critical warning ok)); | 117 | qw(critical warning ok)); |
118 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } | 118 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } |
119 | qw(critical warning)); | 119 | qw(critical warning)); |
120 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } | 120 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } |
121 | qw(warning ok)); | 121 | qw(warning ok)); |
122 | 122 | ||
123 | # critical, warning, ok | 123 | # critical, warning, ok |
@@ -172,33 +172,33 @@ is($message, 'D E F', "join_all '$join_all' (critical, warning) message is $mess | |||
172 | # add_messages | 172 | # add_messages |
173 | 173 | ||
174 | # Constant codes | 174 | # Constant codes |
175 | $np = Nagios::Plugin->new(); | 175 | $np = Monitoring::Plugin->new(); |
176 | $np->add_message( CRITICAL, "A B C" ); | 176 | $np->add_message( CRITICAL, "A B C" ); |
177 | $np->add_message( WARNING, "D E F" ); | 177 | $np->add_message( WARNING, "D E F" ); |
178 | ($code, $message) = $np->check_messages(); | 178 | ($code, $message) = $np->check_messages(); |
179 | is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}"); | 179 | is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}"); |
180 | is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message"); | 180 | is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message"); |
181 | 181 | ||
182 | $np = Nagios::Plugin->new(); | 182 | $np = Monitoring::Plugin->new(); |
183 | $np->add_message( CRITICAL, "A B C" ); | 183 | $np->add_message( CRITICAL, "A B C" ); |
184 | ($code, $message) = $np->check_messages(); | 184 | ($code, $message) = $np->check_messages(); |
185 | is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}"); | 185 | is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}"); |
186 | is($message, $messages{critical}, "(CRITICAL) message is $message"); | 186 | is($message, $messages{critical}, "(CRITICAL) message is $message"); |
187 | 187 | ||
188 | $np = Nagios::Plugin->new(); | 188 | $np = Monitoring::Plugin->new(); |
189 | $np->add_message( WARNING, "D E F" ); | 189 | $np->add_message( WARNING, "D E F" ); |
190 | ($code, $message) = $np->check_messages(); | 190 | ($code, $message) = $np->check_messages(); |
191 | is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}"); | 191 | is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}"); |
192 | is($message, $messages{warning}, "(WARNING) message is $message"); | 192 | is($message, $messages{warning}, "(WARNING) message is $message"); |
193 | 193 | ||
194 | $np = Nagios::Plugin->new(); | 194 | $np = Monitoring::Plugin->new(); |
195 | $np->add_message( WARNING, "D E F" ); | 195 | $np->add_message( WARNING, "D E F" ); |
196 | $np->add_message( OK, "G H I" ); | 196 | $np->add_message( OK, "G H I" ); |
197 | ($code, $message) = $np->check_messages(); | 197 | ($code, $message) = $np->check_messages(); |
198 | is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}"); | 198 | is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}"); |
199 | is($message, $messages{warning}, "(WARNING, OK) message is $message"); | 199 | is($message, $messages{warning}, "(WARNING, OK) message is $message"); |
200 | 200 | ||
201 | $np = Nagios::Plugin->new(); | 201 | $np = Monitoring::Plugin->new(); |
202 | $np->add_message( OK, "G H I" ); | 202 | $np->add_message( OK, "G H I" ); |
203 | ($code, $message) = $np->check_messages(); | 203 | ($code, $message) = $np->check_messages(); |
204 | is($code, OK, "(OK) code is $STATUS_TEXT{$code}"); | 204 | is($code, OK, "(OK) code is $STATUS_TEXT{$code}"); |
@@ -206,33 +206,33 @@ is($message, $messages{ok}, "(OK) message is $message"); | |||
206 | 206 | ||
207 | 207 | ||
208 | # String codes | 208 | # String codes |
209 | $np = Nagios::Plugin->new(); | 209 | $np = Monitoring::Plugin->new(); |
210 | $np->add_message( critical => "A B C" ); | 210 | $np->add_message( critical => "A B C" ); |
211 | $np->add_message( warning => "D E F" ); | 211 | $np->add_message( warning => "D E F" ); |
212 | ($code, $message) = $np->check_messages(); | 212 | ($code, $message) = $np->check_messages(); |
213 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | 213 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); |
214 | is($message, $messages{critical}, "(critical, warning) message is $message"); | 214 | is($message, $messages{critical}, "(critical, warning) message is $message"); |
215 | 215 | ||
216 | $np = Nagios::Plugin->new(); | 216 | $np = Monitoring::Plugin->new(); |
217 | $np->add_message( critical => "A B C" ); | 217 | $np->add_message( critical => "A B C" ); |
218 | ($code, $message) = $np->check_messages(); | 218 | ($code, $message) = $np->check_messages(); |
219 | is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}"); | 219 | is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}"); |
220 | is($message, $messages{critical}, "(critical) message is $message"); | 220 | is($message, $messages{critical}, "(critical) message is $message"); |
221 | 221 | ||
222 | $np = Nagios::Plugin->new(); | 222 | $np = Monitoring::Plugin->new(); |
223 | $np->add_message( warning => "D E F" ); | 223 | $np->add_message( warning => "D E F" ); |
224 | ($code, $message) = $np->check_messages(); | 224 | ($code, $message) = $np->check_messages(); |
225 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | 225 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); |
226 | is($message, $messages{warning}, "(warning) message is $message"); | 226 | is($message, $messages{warning}, "(warning) message is $message"); |
227 | 227 | ||
228 | $np = Nagios::Plugin->new(); | 228 | $np = Monitoring::Plugin->new(); |
229 | $np->add_message( warning => "D E F" ); | 229 | $np->add_message( warning => "D E F" ); |
230 | $np->add_message( ok => "G H I" ); | 230 | $np->add_message( ok => "G H I" ); |
231 | ($code, $message) = $np->check_messages(); | 231 | ($code, $message) = $np->check_messages(); |
232 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | 232 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); |
233 | is($message, $messages{warning}, "(warning, ok) message is $message"); | 233 | is($message, $messages{warning}, "(warning, ok) message is $message"); |
234 | 234 | ||
235 | $np = Nagios::Plugin->new(); | 235 | $np = Monitoring::Plugin->new(); |
236 | $np->add_message( ok => "G H I" ); | 236 | $np->add_message( ok => "G H I" ); |
237 | ($code, $message) = $np->check_messages(); | 237 | ($code, $message) = $np->check_messages(); |
238 | is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); | 238 | is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); |
@@ -240,7 +240,7 @@ is($message, $messages{ok}, "(ok) message is $message"); | |||
240 | 240 | ||
241 | 241 | ||
242 | # No add_message | 242 | # No add_message |
243 | $np = Nagios::Plugin->new(); | 243 | $np = Monitoring::Plugin->new(); |
244 | ($code, $message) = $np->check_messages(); | 244 | ($code, $message) = $np->check_messages(); |
245 | is($code, OK, "() code is $STATUS_TEXT{$code}"); | 245 | is($code, OK, "() code is $STATUS_TEXT{$code}"); |
246 | is($message, '', "() message is ''"); | 246 | is($message, '', "() message is ''"); |
@@ -250,14 +250,13 @@ is($message, '', "() message is ''"); | |||
250 | # Error conditions | 250 | # Error conditions |
251 | 251 | ||
252 | # add_message errors | 252 | # add_message errors |
253 | $np = Nagios::Plugin->new(); | 253 | $np = Monitoring::Plugin->new(); |
254 | ok(! defined eval { $np->add_message( foobar => 'hi mum' ) }, | 254 | ok(! defined eval { $np->add_message( foobar => 'hi mum' ) }, |
255 | 'add_message dies on invalid code'); | 255 | 'add_message dies on invalid code'); |
256 | ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) }, | 256 | ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) }, |
257 | 'add_message dies on invalid code'); | 257 | 'add_message dies on invalid code'); |
258 | # UNKNOWN and DEPENDENT error codes | 258 | # UNKNOWN and DEPENDENT error codes |
259 | ok(! defined eval { $np->add_message( unknown => 'hi mum' ) }, | 259 | ok(! defined eval { $np->add_message( unknown => 'hi mum' ) }, |
260 | 'add_message dies on UNKNOWN code'); | 260 | 'add_message dies on UNKNOWN code'); |
261 | ok(! defined eval { $np->add_message( dependent => 'hi mum' ) }, | 261 | ok(! defined eval { $np->add_message( dependent => 'hi mum' ) }, |
262 | 'add_message dies on DEPENDENT code'); | 262 | 'add_message dies on DEPENDENT code'); |
263 | |||
diff --git a/t/Nagios-Plugin-04.t b/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; | |||
5 | #use Test::More 'no_plan'; | 5 | #use Test::More 'no_plan'; |
6 | use Test::More tests=>30; | 6 | use Test::More tests=>30; |
7 | 7 | ||
8 | BEGIN { use_ok('Nagios::Plugin') }; | 8 | BEGIN { use_ok('Monitoring::Plugin') }; |
9 | use Nagios::Plugin::Functions; | 9 | use Monitoring::Plugin::Functions; |
10 | Nagios::Plugin::Functions::_fake_exit(1); | 10 | Monitoring::Plugin::Functions::_fake_exit(1); |
11 | 11 | ||
12 | 12 | ||
13 | eval { Nagios::Plugin->new(); }; | 13 | eval { Monitoring::Plugin->new(); }; |
14 | ok(! $@, "constructor DOESN'T die without usage"); | 14 | ok(! $@, "constructor DOESN'T die without usage"); |
15 | 15 | ||
16 | my $p = Nagios::Plugin->new(); | 16 | my $p = Monitoring::Plugin->new(); |
17 | eval { $p->add_arg('warning', 'warning') }; | 17 | eval { $p->add_arg('warning', 'warning') }; |
18 | ok($@, "add_arg() dies if you haven't instantiated with usage"); | 18 | ok($@, "add_arg() dies if you haven't instantiated with usage"); |
19 | eval { $p->getopts }; | 19 | eval { $p->getopts }; |
20 | ok($@, "getopts() dies if you haven't instantiated with usage"); | 20 | ok($@, "getopts() dies if you haven't instantiated with usage"); |
21 | 21 | ||
22 | $p = Nagios::Plugin->new( usage => "dummy usage statement" ); | 22 | $p = Monitoring::Plugin->new( usage => "dummy usage statement" ); |
23 | 23 | ||
24 | # option accessors work | 24 | # option accessors work |
25 | can_ok $p, 'opts'; | 25 | can_ok $p, 'opts'; |
26 | isa_ok $p->opts, 'Nagios::Plugin::Getopt', "Getopt object is defined"; | 26 | isa_ok $p->opts, 'Monitoring::Plugin::Getopt', "Getopt object is defined"; |
27 | 27 | ||
28 | $p->add_arg('warning|w=s', "warning"); | 28 | $p->add_arg('warning|w=s', "warning"); |
29 | $p->add_arg('critical|c=s', "critical"); | 29 | $p->add_arg('critical|c=s', "critical"); |
@@ -35,11 +35,11 @@ is $p->opts->critical, "10", "critical opt is accessible"; | |||
35 | 35 | ||
36 | 36 | ||
37 | can_ok $p, 'perfdata'; | 37 | can_ok $p, 'perfdata'; |
38 | #isa_ok $p->perfdata, 'Nagios::Plugin::Performance', "perfdata object is defined"; | 38 | #isa_ok $p->perfdata, 'Monitoring::Plugin::Performance', "perfdata object is defined"; |
39 | 39 | ||
40 | 40 | ||
41 | can_ok $p, 'threshold'; | 41 | can_ok $p, 'threshold'; |
42 | #isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined"; | 42 | #isa_ok $p->threshold, 'Monitoring::Plugin::Threshold', "threshold object is defined"; |
43 | 43 | ||
44 | 44 | ||
45 | eval { $p->check_threshold() }; | 45 | eval { $p->check_threshold() }; |
@@ -60,20 +60,20 @@ is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL w | |||
60 | 60 | ||
61 | # thresholds set explicitly | 61 | # thresholds set explicitly |
62 | is $p->check_threshold( | 62 | is $p->check_threshold( |
63 | check => 2, | 63 | check => 2, |
64 | warning => 50, | 64 | warning => 50, |
65 | critical => 100 | 65 | critical => 100 |
66 | ), OK, "check_threshold explicit OK"; | 66 | ), OK, "check_threshold explicit OK"; |
67 | 67 | ||
68 | is $p->check_threshold( | 68 | is $p->check_threshold( |
69 | check => 66, | 69 | check => 66, |
70 | warning => 50, | 70 | warning => 50, |
71 | critical => 100 | 71 | critical => 100 |
72 | ), WARNING, "check_threshold explicit WARNING"; | 72 | ), WARNING, "check_threshold explicit WARNING"; |
73 | 73 | ||
74 | 74 | ||
75 | is $p->check_threshold( | 75 | is $p->check_threshold( |
76 | check => -1, | 76 | check => -1, |
77 | warning => 5, | 77 | warning => 5, |
78 | critical => '0:5', | 78 | critical => '0:5', |
79 | ), CRITICAL, "check_threshold explicit CRITICAL"; | 79 | ), CRITICAL, "check_threshold explicit CRITICAL"; |
@@ -82,7 +82,7 @@ is $p->check_threshold( | |||
82 | 82 | ||
83 | # what happens if you forget to define warning or critical thresholds? | 83 | # what happens if you forget to define warning or critical thresholds? |
84 | $p = undef; | 84 | $p = undef; |
85 | $p = Nagios::Plugin->new(); | 85 | $p = Monitoring::Plugin->new(); |
86 | 86 | ||
87 | is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN"; | 87 | is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN"; |
88 | is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN"; | 88 | is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN"; |
diff --git a/t/Nagios-Plugin-05.t b/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 @@ | |||
1 | # Check for exported vars | 1 | # Check for exported vars |
2 | # Can't include Nagios::Plugin::Functions because it also exports %STATUS_TEXT | 2 | # Can't include Monitoring::Plugin::Functions because it also exports %STATUS_TEXT |
3 | 3 | ||
4 | use strict; | 4 | use strict; |
5 | use Test::More tests=>4; | 5 | use Test::More tests=>4; |
6 | 6 | ||
7 | BEGIN { use_ok('Nagios::Plugin') }; | 7 | BEGIN { use_ok('Monitoring::Plugin') }; |
8 | 8 | ||
9 | eval ' $_ = $STATUS_TEXT{0} '; | 9 | eval ' $_ = $STATUS_TEXT{0} '; |
10 | like( $@, '/Global symbol "%STATUS_TEXT" requires explicit package name/' ); | 10 | like( $@, '/Global symbol "%STATUS_TEXT" requires explicit package name/' ); |
11 | 11 | ||
12 | use_ok("Nagios::Plugin", qw(%STATUS_TEXT)); | 12 | use_ok("Monitoring::Plugin", qw(%STATUS_TEXT)); |
13 | 13 | ||
14 | eval ' $_ = $STATUS_TEXT{0} '; | 14 | eval ' $_ = $STATUS_TEXT{0} '; |
15 | is( $@, '' ); | 15 | is( $@, '' ); |
16 | |||
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 @@ | |||
1 | |||
2 | use strict; | ||
3 | use Test::More tests => 113; | ||
4 | |||
5 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); } | ||
6 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
7 | |||
8 | my $this_version=$Monitoring::Plugin::Functions::VERSION; | ||
9 | foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { | ||
10 | my $mod = "Monitoring::Plugin$m"; | ||
11 | use_ok($mod); | ||
12 | # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing | ||
13 | my $v = "$mod"."::VERSION"; | ||
14 | my $a = eval "\$$v"; | ||
15 | is($a, $this_version, "Version number for $mod the same as Functions: $this_version"); | ||
16 | } | ||
17 | |||
18 | # check get_shortname | ||
19 | is(get_shortname, "MONITORING-PLUGIN-FUNCTIONS-01", "get_shortname ok"); | ||
20 | |||
21 | # Hardcoded checks of constants | ||
22 | ok(%ERRORS, '%ERRORS defined'); | ||
23 | is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); | ||
24 | is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}"); | ||
25 | is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}"); | ||
26 | is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}"); | ||
27 | is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}"); | ||
28 | |||
29 | # Test plugin_exit( CONSTANT, $msg ), plugin_exit( $string, $msg ) | ||
30 | my $r; | ||
31 | my @ok = ( | ||
32 | [ OK, "OK", 'test the first', ], | ||
33 | [ WARNING, "WARNING", 'test the second', ], | ||
34 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
35 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
36 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
37 | ); | ||
38 | for (@ok) { | ||
39 | # CONSTANT | ||
40 | $r = plugin_exit($_->[0], $_->[2]); | ||
41 | is($r->return_code, $_->[0], | ||
42 | sprintf('plugin_exit(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
43 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
44 | sprintf('plugin_exit(%s, $msg) output matched "%s"', | ||
45 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
46 | |||
47 | # $string | ||
48 | $r = plugin_exit($_->[1], $_->[2]); | ||
49 | is($r->return_code, $_->[0], | ||
50 | sprintf('plugin_exit("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
51 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
52 | sprintf('plugin_exit("%s", $msg) output matched "%s"', $_->[1], | ||
53 | $_->[1] . '.*' . $_->[2])); | ||
54 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
55 | sprintf('plugin_exit("%s", $msg) stringified matched "%s"', $_->[1], | ||
56 | $_->[1] . '.*' . $_->[2])); | ||
57 | } | ||
58 | |||
59 | # plugin_exit code corner cases | ||
60 | my @ugly1 = ( | ||
61 | [ -1, 'testing code -1' ], | ||
62 | [ 7, 'testing code 7' ], | ||
63 | [ undef, 'testing code undef' ], | ||
64 | [ '', qq(testing code '') ], | ||
65 | [ 'string', qq(testing code 'string') ], | ||
66 | ); | ||
67 | for (@ugly1) { | ||
68 | $r = plugin_exit($_->[0], $_->[1]); | ||
69 | my $display = defined $_->[0] ? "'$_->[0]'" : 'undef'; | ||
70 | is($r->return_code, UNKNOWN, "plugin_exit($display, \$msg) returned ". UNKNOWN); | ||
71 | like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/, | ||
72 | sprintf('plugin_exit(%s, $msg) output matched "%s"', | ||
73 | $display, 'UNKNOWN.*' . $_->[1])); | ||
74 | } | ||
75 | |||
76 | # plugin_exit message corner cases | ||
77 | my @ugly2 = ( | ||
78 | [ '' ], | ||
79 | [ undef ], | ||
80 | [ UNKNOWN ], | ||
81 | ); | ||
82 | for (@ugly2) { | ||
83 | $r = plugin_exit(CRITICAL, $_->[0]); | ||
84 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
85 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
86 | like($r->message, qr/CRITICAL\b.*\b$display2$/, | ||
87 | sprintf('plugin_exit(%s, $msg) output matched "%s"', | ||
88 | $display1, "CRITICAL.*$display2")); | ||
89 | } | ||
90 | |||
91 | # Test plugin_die( $msg ) | ||
92 | my @msg = ( | ||
93 | [ 'die you dog' ], | ||
94 | [ '' ], | ||
95 | [ undef ], | ||
96 | ); | ||
97 | for (@msg) { | ||
98 | $r = plugin_die($_->[0]); | ||
99 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
100 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
101 | is($r->return_code, UNKNOWN, | ||
102 | sprintf('plugin_die(%s) returned UNKNOWN', $display1)); | ||
103 | like($r->message, qr/UNKNOWN\b.*\b$display2$/, | ||
104 | sprintf('plugin_die(%s) output matched "%s"', $display1, | ||
105 | "UNKNOWN.*$display2")); | ||
106 | } | ||
107 | |||
108 | # Test plugin_die( CONSTANT, $msg ), plugin_die( $msg, CONSTANT ), | ||
109 | # plugin_die( $string, $msg ), and plugin_die( $msg, $string ) | ||
110 | @ok = ( | ||
111 | [ OK, "OK", 'test the first', ], | ||
112 | [ WARNING, "WARNING", 'test the second', ], | ||
113 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
114 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
115 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
116 | ); | ||
117 | for (@ok) { | ||
118 | # CONSTANT, $msg | ||
119 | $r = plugin_die($_->[0], $_->[2]); | ||
120 | is($r->return_code, $_->[0], | ||
121 | sprintf('plugin_die(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
122 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
123 | sprintf('plugin_die(%s, $msg) output matched "%s"', | ||
124 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
125 | |||
126 | # $msg, CONSTANT | ||
127 | $r = plugin_die($_->[2], $_->[0]); | ||
128 | is($r->return_code, $_->[0], | ||
129 | sprintf('plugin_die($msg, %s) returned %s', $_->[1], $_->[0])); | ||
130 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
131 | sprintf('plugin_die($msg, %s) output matched "%s"', | ||
132 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
133 | |||
134 | # $string, $msg | ||
135 | $r = plugin_die($_->[1], $_->[2]); | ||
136 | is($r->return_code, $_->[0], | ||
137 | sprintf('plugin_die("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
138 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
139 | sprintf('plugin_die("%s", $msg) output matched "%s"', $_->[1], | ||
140 | $_->[1] . '.*' . $_->[2])); | ||
141 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
142 | sprintf('plugin_die("%s", $msg) stringified matched "%s"', $_->[1], | ||
143 | $_->[1] . '.*' . $_->[2])); | ||
144 | |||
145 | # $string, $msg | ||
146 | $r = plugin_die($_->[2], $_->[1]); | ||
147 | is($r->return_code, $_->[0], | ||
148 | sprintf('plugin_die($msg, "%s") returned %s', $_->[1], $_->[0])); | ||
149 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
150 | sprintf('plugin_die($msg, "%s") output matched "%s"', $_->[1], | ||
151 | $_->[1] . '.*' . $_->[2])); | ||
152 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
153 | sprintf('plugin_die($msg, "%s") stringified matched "%s"', $_->[1], | ||
154 | $_->[1] . '.*' . $_->[2])); | ||
155 | } | ||
156 | |||
157 | # Check that _use_die set to 1 will catch exceptions correctly | ||
158 | Monitoring::Plugin::Functions::_fake_exit(0); | ||
159 | Monitoring::Plugin::Functions::_use_die(1); | ||
160 | eval { plugin_die("Using die") }; | ||
161 | 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 index 1a9351b..3796210 100644 --- a/t/Nagios-Plugin-Functions-02.t +++ b/t/Monitoring-Plugin-Functions-02.t | |||
@@ -3,7 +3,7 @@ | |||
3 | use strict; | 3 | use strict; |
4 | use Test::More tests => 37; | 4 | use Test::More tests => 37; |
5 | 5 | ||
6 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } | 6 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") } |
7 | 7 | ||
8 | my ($code, $message); | 8 | my ($code, $message); |
9 | 9 | ||
@@ -105,11 +105,11 @@ is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message") | |||
105 | # ------------------------------------------------------------------------- | 105 | # ------------------------------------------------------------------------- |
106 | # join_all messages | 106 | # join_all messages |
107 | my $join_all = ' :: '; | 107 | my $join_all = ' :: '; |
108 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } | 108 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } |
109 | qw(critical warning ok)); | 109 | qw(critical warning ok)); |
110 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } | 110 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } |
111 | qw(critical warning)); | 111 | qw(critical warning)); |
112 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } | 112 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } |
113 | qw(warning ok)); | 113 | qw(warning ok)); |
114 | 114 | ||
115 | # critical, warning, ok | 115 | # critical, warning, ok |
@@ -175,4 +175,3 @@ ok(! defined eval { ($code, $message) = check_messages(critical => $arrays{criti | |||
175 | 175 | ||
176 | ok(defined eval { ($code, $message) = check_messages(critical => $arrays{critical}, warning => $arrays{warning}) }, | 176 | ok(defined eval { ($code, $message) = check_messages(critical => $arrays{critical}, warning => $arrays{warning}) }, |
177 | "check_messages ok with 'critical' and 'warning' messages"); | 177 | "check_messages ok with 'critical' and 'warning' messages"); |
178 | |||
diff --git a/t/Nagios-Plugin-Functions-03.t b/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 @@ | |||
3 | use strict; | 3 | use strict; |
4 | use Test::More tests => 8; | 4 | use Test::More tests => 8; |
5 | 5 | ||
6 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } | 6 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") } |
7 | 7 | ||
8 | my $new_state = max_state( OK, WARNING ); | 8 | my $new_state = max_state( OK, WARNING ); |
9 | 9 | ||
diff --git a/t/Nagios-Plugin-Functions-04.t b/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 @@ | |||
3 | use strict; | 3 | use strict; |
4 | use Test::More tests => 8; | 4 | use Test::More tests => 8; |
5 | 5 | ||
6 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } | 6 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all") } |
7 | 7 | ||
8 | my $new_state = max_state_alt( OK, WARNING ); | 8 | my $new_state = max_state_alt( OK, WARNING ); |
9 | 9 | ||
diff --git a/t/Nagios-Plugin-Getopt-01.t b/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 @@ | |||
1 | # Nagios::Plugin::Getopt basic tests | 1 | # Monitoring::Plugin::Getopt basic tests |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | 4 | ||
5 | use Test::More tests => 76; | 5 | use Test::More tests => 76; |
6 | BEGIN { use_ok('Nagios::Plugin::Getopt') }; | 6 | BEGIN { use_ok('Monitoring::Plugin::Getopt') }; |
7 | 7 | ||
8 | # Needed to get evals to work in testing | 8 | # Needed to get evals to work in testing |
9 | Nagios::Plugin::Functions::_use_die(1); | 9 | Monitoring::Plugin::Functions::_use_die(1); |
10 | 10 | ||
11 | my %PARAM = ( | 11 | my %PARAM = ( |
12 | version => '0.01', | 12 | version => '0.01', |
13 | url => 'http://www.openfusion.com.au/labs/nagios/', | 13 | url => 'http://www.openfusion.com.au/labs/nagios/', |
14 | blurb => 'This plugin tests various stuff.', | 14 | blurb => 'This plugin tests various stuff.', |
15 | usage => "Usage: %s -H <host> -w <warning_threshold> | 15 | usage => "Usage: %s -H <host> -w <warning_threshold> |
16 | -c <critical threshold>", | 16 | -c <critical threshold>", |
17 | plugin => 'test_plugin', | 17 | plugin => 'test_plugin', |
18 | ); | 18 | ); |
19 | 19 | ||
20 | sub setup | 20 | sub setup |
21 | { | 21 | { |
22 | # Instantiate object | 22 | # Instantiate object |
23 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | 23 | my $ng = Monitoring::Plugin::Getopt->new(%PARAM); |
24 | ok($ng, 'constructor ok'); | 24 | ok($ng, 'constructor ok'); |
25 | 25 | ||
26 | # Add argument - short form - arg spec, help text, default, required? | 26 | # Add argument - short form - arg spec, help text, default, required? |
27 | $ng->arg('warning|w=s' => | 27 | $ng->arg('warning|w=s' => |
28 | qq(-w, --warning=INTEGER\n Exit with WARNING status if less than INTEGER foobars are free), | 28 | qq(-w, --warning=INTEGER\n Exit with WARNING status if less than INTEGER foobars are free), |
29 | 5); | 29 | 5); |
30 | 30 | ||
31 | # Add argument - named version | 31 | # Add argument - named version |
32 | $ng->arg( | 32 | $ng->arg( |
33 | spec => 'critical|c=i', | 33 | spec => 'critical|c=i', |
@@ -147,4 +147,3 @@ like($@, qr/--verbose/, 'help includes default options 2'); | |||
147 | like($@, qr/--warning/, 'help includes custom option 1'); | 147 | like($@, qr/--warning/, 'help includes custom option 1'); |
148 | like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args'); | 148 | like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args'); |
149 | unlike($@, qr/Missing arg/, 'no missing arguments'); | 149 | unlike($@, qr/Missing arg/, 'no missing arguments'); |
150 | |||
diff --git a/t/Nagios-Plugin-Getopt-02.t b/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 @@ | |||
1 | # Nagios::Plugin::Getopt timeout tests | 1 | # Monitoring::Plugin::Getopt timeout tests |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | 4 | ||
5 | use Test::More tests => 14; | 5 | use Test::More tests => 14; |
6 | BEGIN { use_ok('Nagios::Plugin::Getopt') }; | 6 | BEGIN { use_ok('Monitoring::Plugin::Getopt') }; |
7 | 7 | ||
8 | # Needed to get evals to work in testing | 8 | # Needed to get evals to work in testing |
9 | Nagios::Plugin::Functions::_use_die(1); | 9 | Monitoring::Plugin::Functions::_use_die(1); |
10 | 10 | ||
11 | my %PARAM = ( | 11 | my %PARAM = ( |
12 | version => '0.01', | 12 | version => '0.01', |
13 | url => 'http://www.openfusion.com.au/labs/nagios/', | 13 | url => 'http://www.openfusion.com.au/labs/nagios/', |
14 | blurb => 'This plugin tests various stuff.', | 14 | blurb => 'This plugin tests various stuff.', |
15 | usage => "Usage: %s -H <host> -w <warning_threshold> | 15 | usage => "Usage: %s -H <host> -w <warning_threshold> |
16 | -c <critical threshold>", | 16 | -c <critical threshold>", |
17 | plugin => 'test_plugin', | 17 | plugin => 'test_plugin', |
18 | timeout => 18, | 18 | timeout => 18, |
19 | ); | 19 | ); |
20 | 20 | ||
21 | sub setup | 21 | sub setup |
22 | { | 22 | { |
23 | # Instantiate object | 23 | # Instantiate object |
24 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | 24 | my $ng = Monitoring::Plugin::Getopt->new(%PARAM); |
25 | ok($ng, 'constructor ok'); | 25 | ok($ng, 'constructor ok'); |
26 | return $ng; | 26 | return $ng; |
27 | } | 27 | } |
@@ -61,4 +61,3 @@ alarm($ng->timeout); | |||
61 | # Loop | 61 | # Loop |
62 | ok(! defined eval { 1 while 1 }, 'loop timed out'); | 62 | ok(! defined eval { 1 while 1 }, 'loop timed out'); |
63 | like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok'); | 63 | like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok'); |
64 | |||
diff --git a/t/Nagios-Plugin-Getopt-03.t b/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 @@ | |||
1 | # Nagios::Plugin::Getopt --extra-opts tests | 1 | # Monitoring::Plugin::Getopt --extra-opts tests |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | use File::Spec; | 4 | use File::Spec; |
@@ -6,15 +6,15 @@ use File::Basename; | |||
6 | use IO::File; | 6 | use IO::File; |
7 | 7 | ||
8 | use Test::More qw(no_plan); | 8 | use Test::More qw(no_plan); |
9 | BEGIN { use_ok('Nagios::Plugin::Getopt') }; | 9 | BEGIN { use_ok('Monitoring::Plugin::Getopt') }; |
10 | 10 | ||
11 | # Needed to get evals to work in testing | 11 | # Needed to get evals to work in testing |
12 | Nagios::Plugin::Functions::_use_die(1); | 12 | Monitoring::Plugin::Functions::_use_die(1); |
13 | 13 | ||
14 | my $tdir = 'npg03'; | 14 | my $tdir = 'npg03'; |
15 | if (! -d $tdir) { | 15 | if (! -d $tdir) { |
16 | my $ttdir = File::Spec->catdir('t', $tdir); | 16 | my $ttdir = File::Spec->catdir('t', $tdir); |
17 | die "missing '$tdir' directory\n" unless -d $ttdir; | 17 | die "missing '$tdir' directory\n" unless -d $ttdir; |
18 | $tdir = $ttdir; | 18 | $tdir = $ttdir; |
19 | } | 19 | } |
20 | 20 | ||
@@ -30,22 +30,22 @@ for my $efile (glob File::Spec->catfile($tdir, 'expected', '*')) { | |||
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | # Override NAGIOS_CONFIG_PATH to use our test plugins.ini file | 33 | # Override MONITORING_CONFIG_PATH to use our test plugins.ini file |
34 | $ENV{NAGIOS_CONFIG_PATH} = "/random/bogus/path:$tdir"; | 34 | $ENV{MONITORING_CONFIG_PATH} = "/random/bogus/path:$tdir"; |
35 | 35 | ||
36 | my %PARAM = ( | 36 | my %PARAM = ( |
37 | version => '0.01', | 37 | version => '0.01', |
38 | blurb => 'This plugin tests various stuff.', | 38 | blurb => 'This plugin tests various stuff.', |
39 | usage => "Usage: %s -H <host> -w <warning_threshold> | 39 | usage => "Usage: %s -H <host> -w <warning_threshold> |
40 | -c <critical threshold>", | 40 | -c <critical threshold>", |
41 | ); | 41 | ); |
42 | 42 | ||
43 | sub ng_setup | 43 | sub ng_setup |
44 | { | 44 | { |
45 | my $arg = shift; | 45 | my $arg = shift; |
46 | 46 | ||
47 | # Instantiate object | 47 | # Instantiate object |
48 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | 48 | my $ng = Monitoring::Plugin::Getopt->new(%PARAM); |
49 | 49 | ||
50 | if (ref $arg eq 'ARRAY' && @$arg) { | 50 | if (ref $arg eq 'ARRAY' && @$arg) { |
51 | $ng->arg(%$_) foreach @$arg; | 51 | $ng->arg(%$_) foreach @$arg; |
@@ -54,7 +54,7 @@ sub ng_setup | |||
54 | return $ng; | 54 | return $ng; |
55 | } | 55 | } |
56 | 56 | ||
57 | # Setup our Nagios::Plugin::Getopt object | 57 | # Setup our Monitoring::Plugin::Getopt object |
58 | my $ng; | 58 | my $ng; |
59 | my $arg = [ | 59 | my $arg = [ |
60 | { spec => 'S', help => '-S' }, | 60 | { spec => 'S', help => '-S' }, |
@@ -85,9 +85,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) { | |||
85 | $cmd =~ s/^\s+//; | 85 | $cmd =~ s/^\s+//; |
86 | my ($plugin, @args) = split /\s+/, $cmd; | 86 | my ($plugin, @args) = split /\s+/, $cmd; |
87 | 87 | ||
88 | # Fake out the plugin name | 88 | # Fake out the plugin name |
89 | $ng->{_attr}->{plugin} = $plugin; | 89 | $ng->{_attr}->{plugin} = $plugin; |
90 | 90 | ||
91 | # Parse the options | 91 | # Parse the options |
92 | SKIP: { | 92 | SKIP: { |
93 | skip "Skipping ..." if $SKIP{$infile}; | 93 | skip "Skipping ..." if $SKIP{$infile}; |
@@ -99,10 +99,9 @@ for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) { | |||
99 | ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)"); | 99 | ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)"); |
100 | is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/); | 100 | is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/); |
101 | } | 101 | } |
102 | else { | 102 | else { |
103 | is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile); | 103 | is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile); |
104 | } | 104 | } |
105 | } | 105 | } |
106 | } | 106 | } |
107 | } | 107 | } |
108 | |||
diff --git a/t/Nagios-Plugin-Getopt-04.t b/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 @@ | |||
1 | # Nagios::Plugin::Getopt spec-to-help generation tests | 1 | # Monitoring::Plugin::Getopt spec-to-help generation tests |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | 4 | ||
5 | use Test::More tests => 11; | 5 | use Test::More tests => 11; |
6 | BEGIN { use_ok('Nagios::Plugin::Getopt') }; | 6 | BEGIN { use_ok('Monitoring::Plugin::Getopt') }; |
7 | 7 | ||
8 | # Needed to get evals to work in testing | 8 | # Needed to get evals to work in testing |
9 | Nagios::Plugin::Functions::_use_die(1); | 9 | Monitoring::Plugin::Functions::_use_die(1); |
10 | 10 | ||
11 | my %PARAM = ( | 11 | my %PARAM = ( |
12 | version => '0.01', | 12 | version => '0.01', |
13 | usage => "Don't use this plugin!", | 13 | usage => "Don't use this plugin!", |
14 | ); | 14 | ); |
15 | 15 | ||
16 | sub setup | 16 | sub setup |
17 | { | 17 | { |
18 | # Instantiate object | 18 | # Instantiate object |
19 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | 19 | my $ng = Monitoring::Plugin::Getopt->new(%PARAM); |
20 | ok($ng, 'constructor ok'); | 20 | ok($ng, 'constructor ok'); |
21 | 21 | ||
22 | # Positional args, no short arguments, INTEGER | 22 | # Positional args, no short arguments, INTEGER |
23 | $ng->arg('warning=i' => | 23 | $ng->arg('warning=i' => |
24 | qq(Exit with WARNING status if less than INTEGER foobars are free), | 24 | qq(Exit with WARNING status if less than INTEGER foobars are free), |
25 | 5); | 25 | 5); |
26 | 26 | ||
27 | # Named args, long + short arguments, INTEGER | 27 | # Named args, long + short arguments, INTEGER |
28 | $ng->arg( | 28 | $ng->arg( |
29 | spec => 'critical|c=i', | 29 | spec => 'critical|c=i', |
@@ -35,7 +35,7 @@ sub setup | |||
35 | $ng->arg( | 35 | $ng->arg( |
36 | spec => 'x|y|z=s', | 36 | spec => 'x|y|z=s', |
37 | help => qq(Foobar. Default: %s), | 37 | help => qq(Foobar. Default: %s), |
38 | default => "XYZ", | 38 | default => "XYZ", |
39 | ); | 39 | ); |
40 | 40 | ||
41 | # Named args, multiple mixed, no label | 41 | # Named args, multiple mixed, no label |
@@ -95,4 +95,3 @@ like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok'); | |||
95 | 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'); | 95 | 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'); |
96 | like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok'); | 96 | like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok'); |
97 | #print $@; | 97 | #print $@; |
98 | |||
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 @@ | |||
1 | |||
2 | use strict; | ||
3 | use Test::More tests => 3; | ||
4 | use_ok("Monitoring::Plugin::Performance", use_die => 1); | ||
5 | |||
6 | eval { Monitoring::Plugin::Functions::plugin_die("Testing") }; | ||
7 | is( $@, "MONITORING-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import"); | ||
8 | |||
9 | |||
10 | use_ok("Monitoring::Plugin::Performance"); | ||
11 | eval { Monitoring::Plugin::Functions::plugin_die("Test OK exit", 0) }; | ||
12 | |||
13 | 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 index 8dce336..bedb2e2 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Monitoring-Plugin-Performance.t | |||
@@ -2,61 +2,61 @@ | |||
2 | use warnings; | 2 | use warnings; |
3 | use strict; | 3 | use strict; |
4 | use Test::More; | 4 | use Test::More; |
5 | use Nagios::Plugin::Functions; | 5 | use Monitoring::Plugin::Functions; |
6 | Nagios::Plugin::Functions::_fake_exit(1); | 6 | Monitoring::Plugin::Functions::_fake_exit(1); |
7 | 7 | ||
8 | 8 | ||
9 | my (@p, $p); | 9 | my (@p, $p); |
10 | my @test = ( | 10 | my @test = ( |
11 | { | 11 | { |
12 | perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root", | 12 | perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768, clean_label => "root", |
13 | }, { | 13 | }, { |
14 | perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var", | 14 | perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef, clean_label => "var", |
15 | }, { | 15 | }, { |
16 | 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', | 16 | 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', |
17 | }, { | 17 | }, { |
18 | perfoutput => "'page file'=36%;80;90;", | 18 | perfoutput => "'page file'=36%;80;90;", |
19 | expected_perfoutput => "'page file'=36%;80;90", | 19 | expected_perfoutput => "'page file'=36%;80;90", |
20 | label => 'page file', | 20 | label => 'page file', |
21 | rrdlabel => 'page_file', | 21 | rrdlabel => 'page_file', |
22 | value => '36', | 22 | value => '36', |
23 | uom => '%', | 23 | uom => '%', |
24 | warning => 80, | 24 | warning => 80, |
25 | critical => 90, | 25 | critical => 90, |
26 | min => undef, | 26 | min => undef, |
27 | max => undef, | 27 | max => undef, |
28 | clean_label => 'page_file', | 28 | clean_label => 'page_file', |
29 | }, { | 29 | }, { |
30 | perfoutput => "'data'=5;;;;", | 30 | perfoutput => "'data'=5;;;;", |
31 | expected_perfoutput => "data=5;;", | 31 | expected_perfoutput => "data=5;;", |
32 | label => 'data', | 32 | label => 'data', |
33 | rrdlabel => 'data', | 33 | rrdlabel => 'data', |
34 | value => 5, | 34 | value => 5, |
35 | uom => "", | 35 | uom => "", |
36 | warning => undef, | 36 | warning => undef, |
37 | critical => undef, | 37 | critical => undef, |
38 | min => undef, | 38 | min => undef, |
39 | max => undef, | 39 | max => undef, |
40 | clean_label => 'data', | 40 | clean_label => 'data', |
41 | }, | 41 | }, |
42 | ); | 42 | ); |
43 | 43 | ||
44 | plan tests => (11 * scalar @test) + 176; | 44 | plan tests => (11 * scalar @test) + 176; |
45 | 45 | ||
46 | use_ok('Nagios::Plugin::Performance'); | 46 | use_ok('Monitoring::Plugin::Performance'); |
47 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | 47 | diag "\nusing Monitoring::Plugin::Performance revision ". $Monitoring::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
48 | 48 | ||
49 | # Round-trip tests | 49 | # Round-trip tests |
50 | for my $t (@test) { | 50 | for my $t (@test) { |
51 | # Parse to components | 51 | # Parse to components |
52 | ($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput}); | 52 | ($p) = Monitoring::Plugin::Performance->parse_perfstring($t->{perfoutput}); |
53 | is ($p->value, $t->{value}, "value okay $t->{value}"); | 53 | is ($p->value, $t->{value}, "value okay $t->{value}"); |
54 | is ($p->label, $t->{label}, "label okay $t->{label}"); | 54 | is ($p->label, $t->{label}, "label okay $t->{label}"); |
55 | is ($p->uom, $t->{uom}, "uom okay $t->{uom}"); | 55 | is ($p->uom, $t->{uom}, "uom okay $t->{uom}"); |
56 | 56 | ||
57 | # Construct from components | 57 | # Construct from components |
58 | my @construct = qw(label value uom warning critical min max); | 58 | my @construct = qw(label value uom warning critical min max); |
59 | $p = Nagios::Plugin::Performance->new(map { $_ => $t->{$_} } @construct); | 59 | $p = Monitoring::Plugin::Performance->new(map { $_ => $t->{$_} } @construct); |
60 | my $expected_perfoutput = $t->{perfoutput}; | 60 | my $expected_perfoutput = $t->{perfoutput}; |
61 | if (exists $t->{expected_perfoutput}) { | 61 | if (exists $t->{expected_perfoutput}) { |
62 | $expected_perfoutput = $t->{expected_perfoutput}; | 62 | $expected_perfoutput = $t->{expected_perfoutput}; |
@@ -75,9 +75,9 @@ for my $t (@test) { | |||
75 | 75 | ||
76 | # Construct using threshold | 76 | # Construct using threshold |
77 | @construct = qw(label value uom min max); | 77 | @construct = qw(label value uom min max); |
78 | $p = Nagios::Plugin::Performance->new( | 78 | $p = Monitoring::Plugin::Performance->new( |
79 | map({ $_ => $t->{$_} } @construct), | 79 | map({ $_ => $t->{$_} } @construct), |
80 | threshold => Nagios::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}), | 80 | threshold => Monitoring::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}), |
81 | ); | 81 | ); |
82 | is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)"); | 82 | is($p->perfoutput, $expected_perfoutput, "perfoutput okay ($expected_perfoutput)"); |
83 | # Check warning/critical accessors | 83 | # Check warning/critical accessors |
@@ -92,7 +92,7 @@ for my $t (@test) { | |||
92 | 92 | ||
93 | 93 | ||
94 | # Test multiple parse_perfstrings | 94 | # Test multiple parse_perfstrings |
95 | @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | 95 | @p = Monitoring::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); |
96 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | 96 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); |
97 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); | 97 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); |
98 | cmp_ok( $p[0]->value, '==', 382, "value okay"); | 98 | cmp_ok( $p[0]->value, '==', 382, "value okay"); |
@@ -109,14 +109,14 @@ cmp_ok( $p[1]->uom, 'eq', "MB", "uom okay"); | |||
109 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); | 109 | cmp_ok( $p[1]->threshold->warning->end, "==", 9443, "warn okay"); |
110 | cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); | 110 | cmp_ok( $p[1]->threshold->critical->end, "==", 9448, "crit okay"); |
111 | 111 | ||
112 | @p = Nagios::Plugin::Performance->parse_perfstring("rubbish"); | 112 | @p = Monitoring::Plugin::Performance->parse_perfstring("rubbish"); |
113 | ok( ! @p, "Errors correctly"); | 113 | ok( ! @p, "Errors correctly"); |
114 | ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); | 114 | ok( ! Monitoring::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); |
115 | 115 | ||
116 | 116 | ||
117 | 117 | ||
118 | # Check 1 bad with 1 good format output | 118 | # Check 1 bad with 1 good format output |
119 | @p = Nagios::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); | 119 | @p = Monitoring::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); |
120 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | 120 | is( scalar @p, 1, "One bad piece of data - only one returned" ); |
121 | is( $p[0]->label, "pl", "label okay for different numeric"); | 121 | is( $p[0]->label, "pl", "label okay for different numeric"); |
122 | is( $p[0]->value, 0, "value okay"); | 122 | is( $p[0]->value, 0, "value okay"); |
@@ -127,7 +127,7 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | |||
127 | is( $p[0]->threshold->critical, "60", "warn okay"); | 127 | is( $p[0]->threshold->critical, "60", "warn okay"); |
128 | 128 | ||
129 | # Same as above, but order swapped | 129 | # Same as above, but order swapped |
130 | @p = Nagios::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); | 130 | @p = Monitoring::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); |
131 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | 131 | is( scalar @p, 1, "One bad piece of data - only one returned" ); |
132 | is( $p[0]->label, "pl", "label okay for different numeric"); | 132 | is( $p[0]->label, "pl", "label okay for different numeric"); |
133 | is( $p[0]->value, 0, "value okay"); | 133 | is( $p[0]->value, 0, "value okay"); |
@@ -140,7 +140,7 @@ is( $p[0]->threshold->critical, "60", "warn okay"); | |||
140 | 140 | ||
141 | 141 | ||
142 | 142 | ||
143 | @p = Nagios::Plugin::Performance->parse_perfstring( | 143 | @p = Monitoring::Plugin::Performance->parse_perfstring( |
144 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); | 144 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); |
145 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | 145 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); |
146 | cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); | 146 | cmp_ok( $p[0]->value, "==", 0.001229, "value okay"); |
@@ -150,27 +150,27 @@ cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | |||
150 | 150 | ||
151 | 151 | ||
152 | 152 | ||
153 | @p = Nagios::Plugin::Performance->parse_perfstring( | 153 | @p = Monitoring::Plugin::Performance->parse_perfstring( |
154 | "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); | 154 | "load1=0.000;5.000;9.000;0; load5=0.000;5.000;9.000;0; load15=0.000;5.000;9.000;0;"); |
155 | cmp_ok( $p[0]->label, "eq", "load1", "label okay"); | 155 | cmp_ok( $p[0]->label, "eq", "load1", "label okay"); |
156 | cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); | 156 | cmp_ok( $p[0]->value, "eq", "0", "value okay with 0 as string"); |
157 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | 157 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); |
158 | cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); | 158 | cmp_ok( $p[0]->threshold->warning, "eq", "5", "warn okay"); |
159 | cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); | 159 | cmp_ok( $p[0]->threshold->critical, "eq", "9", "crit okay"); |
160 | cmp_ok( $p[1]->label, "eq", "load5", "label okay"); | 160 | cmp_ok( $p[1]->label, "eq", "load5", "label okay"); |
161 | cmp_ok( $p[2]->label, "eq", "load15", "label okay"); | 161 | cmp_ok( $p[2]->label, "eq", "load15", "label okay"); |
162 | 162 | ||
163 | @p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); | 163 | @p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0" ); |
164 | cmp_ok( $p[0]->label, "eq", "users", "label okay"); | 164 | cmp_ok( $p[0]->label, "eq", "users", "label okay"); |
165 | cmp_ok( $p[0]->value, "==", 4, "value okay"); | 165 | cmp_ok( $p[0]->value, "==", 4, "value okay"); |
166 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); | 166 | cmp_ok( $p[0]->uom, "eq", "", "uom empty"); |
167 | cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); | 167 | cmp_ok( $p[0]->threshold->warning, 'eq', "20", "warn okay"); |
168 | cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); | 168 | cmp_ok( $p[0]->threshold->critical, 'eq', "50", "crit okay"); |
169 | 169 | ||
170 | @p = Nagios::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" ); | 170 | @p = Monitoring::Plugin::Performance->parse_perfstring( "users=4;20;50;0\n" ); |
171 | ok( @p, "parse correctly with linefeed at end (nagiosgraph)"); | 171 | ok( @p, "parse correctly with linefeed at end (nagiosgraph)"); |
172 | 172 | ||
173 | @p = Nagios::Plugin::Performance->parse_perfstring( | 173 | @p = Monitoring::Plugin::Performance->parse_perfstring( |
174 | "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); | 174 | "time=0.215300s;5.000000;10.000000;0.000000 size=426B;;;0" ); |
175 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | 175 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); |
176 | cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); | 176 | cmp_ok( $p[0]->value, "eq", "0.2153", "value okay"); |
@@ -184,21 +184,21 @@ cmp_ok( $p[1]->uom, "eq", "B", "uom okay"); | |||
184 | ok( ! $p[1]->threshold->critical->is_set, "crit okay"); | 184 | ok( ! $p[1]->threshold->critical->is_set, "crit okay"); |
185 | 185 | ||
186 | # Edge cases | 186 | # Edge cases |
187 | @p = Nagios::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20"); | 187 | @p = Monitoring::Plugin::Performance->parse_perfstring("/home/a-m=0;0;0 shared-folder:big=20 12345678901234567890=20"); |
188 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); | 188 | cmp_ok( $p[0]->rrdlabel, "eq", "home_a_m", "changing / to _"); |
189 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | 189 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); |
190 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); | 190 | cmp_ok( $p[1]->rrdlabel, "eq", "shared_folder_big", "replacing bad characters"); |
191 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); | 191 | cmp_ok( $p[2]->rrdlabel, "eq", "1234567890123456789", "shortening rrd label"); |
192 | 192 | ||
193 | # turn off fake_exit and enable use_die so we pick up on errors via nagios_die | 193 | # turn off fake_exit and enable use_die so we pick up on errors via plugin_die |
194 | Nagios::Plugin::Functions::_use_die(1); | 194 | Monitoring::Plugin::Functions::_use_die(1); |
195 | Nagios::Plugin::Functions::_fake_exit(0); | 195 | Monitoring::Plugin::Functions::_fake_exit(0); |
196 | 196 | ||
197 | @p = Nagios::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000"); | 197 | @p = Monitoring::Plugin::Performance->parse_perfstring("time=0.002722s;0.000000;0.000000;0.000000;10.000000"); |
198 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | 198 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); |
199 | cmp_ok( $p[0]->value, "eq", "0.002722", "value okay"); | 199 | cmp_ok( $p[0]->value, "eq", "0.002722", "value okay"); |
200 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); | 200 | cmp_ok( $p[0]->uom, "eq", "s", "uom okay"); |
201 | ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set"); | 201 | ok( defined $p[0]->threshold->warning->is_set, "Warning range has been set"); |
202 | ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set"); | 202 | ok( defined $p[0]->threshold->critical->is_set, "Critical range has been set"); |
203 | # The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification | 203 | # The two below used to be cmp_ok, but Test::More 0.86 appears to have a problem with a stringification |
204 | # of 0. See http://rt.cpan.org/Ticket/Display.html?id=41109 | 204 | # 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"); | |||
206 | is( $p[0]->threshold->warning."", "0", "warn okay"); | 206 | is( $p[0]->threshold->warning."", "0", "warn okay"); |
207 | is( $p[0]->threshold->critical."", "0", "crit okay"); | 207 | is( $p[0]->threshold->critical."", "0", "crit okay"); |
208 | 208 | ||
209 | @p = Nagios::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95"); | 209 | @p = Monitoring::Plugin::Performance->parse_perfstring("pct_used=73.7%;90;95"); |
210 | cmp_ok( $p[0]->label, "eq", "pct_used", "label okay"); | 210 | cmp_ok( $p[0]->label, "eq", "pct_used", "label okay"); |
211 | cmp_ok( $p[0]->value, "eq", "73.7", "value okay"); | 211 | cmp_ok( $p[0]->value, "eq", "73.7", "value okay"); |
212 | cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); | 212 | cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); |
@@ -216,7 +216,7 @@ cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay"); | |||
216 | cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); | 216 | cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); |
217 | 217 | ||
218 | # Check ranges are parsed correctly | 218 | # Check ranges are parsed correctly |
219 | @p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); | 219 | @p = Monitoring::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); |
220 | is( $p[0]->label, "availability", "label okay"); | 220 | is( $p[0]->label, "availability", "label okay"); |
221 | is( $p[0]->value, "93.8", "value okay"); | 221 | is( $p[0]->value, "93.8", "value okay"); |
222 | is( $p[0]->uom, "%", "uom okay"); | 222 | is( $p[0]->uom, "%", "uom okay"); |
@@ -225,7 +225,7 @@ is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set"); | |||
225 | is( $p[0]->threshold->warning, "90:99", "warn okay"); | 225 | is( $p[0]->threshold->warning, "90:99", "warn okay"); |
226 | 226 | ||
227 | # Check that negative values are parsed correctly in value and ranges | 227 | # Check that negative values are parsed correctly in value and ranges |
228 | @p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); | 228 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); |
229 | is( $p[0]->label, "offset", "label okay"); | 229 | is( $p[0]->label, "offset", "label okay"); |
230 | is( $p[0]->value, "-0.004476", "value okay"); | 230 | is( $p[0]->value, "-0.004476", "value okay"); |
231 | is( $p[0]->uom, "s", "uom okay"); | 231 | is( $p[0]->uom, "s", "uom okay"); |
@@ -235,7 +235,7 @@ is( $p[0]->threshold->warning, "-60:-5", "warn okay"); | |||
235 | is( $p[0]->threshold->critical, "-120:-3", "crit okay"); | 235 | is( $p[0]->threshold->critical, "-120:-3", "crit okay"); |
236 | 236 | ||
237 | # Check infinity values are okay | 237 | # Check infinity values are okay |
238 | @p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:"); | 238 | @p = Monitoring::Plugin::Performance->parse_perfstring("salary=52GBP;~:23.5;45.2:"); |
239 | is( $p[0]->label, "salary", "label okay"); | 239 | is( $p[0]->label, "salary", "label okay"); |
240 | is( $p[0]->value, "52", "value okay"); | 240 | is( $p[0]->value, "52", "value okay"); |
241 | is( $p[0]->uom, "GBP", "uom okay"); | 241 | is( $p[0]->uom, "GBP", "uom okay"); |
@@ -245,7 +245,7 @@ is( $p[0]->threshold->warning, "~:23.5", "warn okay"); | |||
245 | is( $p[0]->threshold->critical, "45.2:", "warn okay"); | 245 | is( $p[0]->threshold->critical, "45.2:", "warn okay"); |
246 | 246 | ||
247 | # Check scientific notation | 247 | # Check scientific notation |
248 | @p = Nagios::Plugin::Performance->parse_perfstring("offset=1.120567322e-05"); | 248 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=1.120567322e-05"); |
249 | is( $p[0]->label, "offset", "label okay for scientific notation"); | 249 | is( $p[0]->label, "offset", "label okay for scientific notation"); |
250 | is( $p[0]->value, 1.120567322e-05, "value okay"); | 250 | is( $p[0]->value, 1.120567322e-05, "value okay"); |
251 | is( $p[0]->uom, "", "uom okay"); | 251 | is( $p[0]->uom, "", "uom okay"); |
@@ -254,7 +254,7 @@ ok( ! $p[0]->threshold->critical->is_set, "Critical range has not been set"); | |||
254 | 254 | ||
255 | 255 | ||
256 | # Check scientific notation with warnings and criticals | 256 | # Check scientific notation with warnings and criticals |
257 | @p = Nagios::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25"); | 257 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-1.120567322e-05unit;-1.1e-05:1.0e-03;4.3e+02:4.3e+25"); |
258 | is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals"); | 258 | is( $p[0]->label, "offset", "label okay for scientific notation in warnings and criticals"); |
259 | is( $p[0]->value, -1.120567322e-05, "value okay"); | 259 | is( $p[0]->value, -1.120567322e-05, "value okay"); |
260 | is( $p[0]->uom, "unit", "uom okay"); | 260 | is( $p[0]->uom, "unit", "uom okay"); |
@@ -266,7 +266,7 @@ is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); | |||
266 | 266 | ||
267 | 267 | ||
268 | # Check different collation with commas instead of periods | 268 | # Check different collation with commas instead of periods |
269 | @p = Nagios::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); | 269 | @p = Monitoring::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); |
270 | is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); | 270 | is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); |
271 | is( $p[0]->value, 1.391, "value okay"); | 271 | is( $p[0]->value, 1.391, "value okay"); |
272 | is( $p[0]->uom, "ms", "uom okay"); | 272 | is( $p[0]->uom, "ms", "uom okay"); |
@@ -284,7 +284,7 @@ is( $p[1]->threshold->critical, "60", "warn okay"); | |||
284 | 284 | ||
285 | 285 | ||
286 | # Another set of comma separated stuff | 286 | # Another set of comma separated stuff |
287 | @p = Nagios::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;"); | 287 | @p = Monitoring::Plugin::Performance->parse_perfstring("offset=-0,023545s;60,000000;120,000000;"); |
288 | is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods"); | 288 | is( $p[0]->label, "offset", "label okay for numeric with commas instead of periods"); |
289 | is( $p[0]->value, -0.023545, "value okay"); | 289 | is( $p[0]->value, -0.023545, "value okay"); |
290 | is( $p[0]->uom, "s", "uom okay"); | 290 | is( $p[0]->uom, "s", "uom okay"); |
@@ -294,14 +294,14 @@ is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | |||
294 | is( $p[0]->threshold->critical, 120, "warn okay"); | 294 | is( $p[0]->threshold->critical, 120, "warn okay"); |
295 | 295 | ||
296 | # Some values with funny commas | 296 | # Some values with funny commas |
297 | @p = Nagios::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6"); | 297 | @p = Monitoring::Plugin::Performance->parse_perfstring("time=1800,600,300,0,3600 other=45.6"); |
298 | is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6"); | 298 | is( $p[0]->label, "other", "Ignored time=1800,600,300,0,3600, but allowed other=45.6"); |
299 | is( $p[0]->value, 45.6, "value okay"); | 299 | is( $p[0]->value, 45.6, "value okay"); |
300 | is( $p[0]->uom, "", "uom okay"); | 300 | is( $p[0]->uom, "", "uom okay"); |
301 | 301 | ||
302 | 302 | ||
303 | # Test labels with spaces (returned by nsclient++) | 303 | # Test labels with spaces (returned by nsclient++) |
304 | @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"); | 304 | @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"); |
305 | is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e"); | 305 | is( $p[0]->label, "C:\ Label: Serial Number bc22aa2e"); |
306 | is( $p[0]->rrdlabel, "C__Label___Serial_N"); | 306 | is( $p[0]->rrdlabel, "C__Label___Serial_N"); |
307 | is( $p[0]->value, 8015, "value okay"); | 307 | is( $p[0]->value, 8015, "value okay"); |
@@ -322,7 +322,7 @@ is( $p[1]->max, 2048, "max ok"); | |||
322 | 322 | ||
323 | 323 | ||
324 | # Mix labels with and without quotes | 324 | # Mix labels with and without quotes |
325 | @p = Nagios::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 "); | 325 | @p = Monitoring::Plugin::Performance->parse_perfstring(" short=4 'C:\ Label: Serial Number bc22aa2e'=8015MB;16387;18435;0;20484 end=5 "); |
326 | is( $p[0]->label, "short" ); | 326 | is( $p[0]->label, "short" ); |
327 | is( $p[0]->rrdlabel, "short"); | 327 | is( $p[0]->rrdlabel, "short"); |
328 | is( $p[0]->value, 4, "value okay"); | 328 | is( $p[0]->value, 4, "value okay"); |
@@ -351,7 +351,7 @@ is( $p[2]->min, undef, "min ok"); | |||
351 | is( $p[2]->max, undef, "max ok"); | 351 | is( $p[2]->max, undef, "max ok"); |
352 | 352 | ||
353 | 353 | ||
354 | @p = Nagios::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9="); | 354 | @p = Monitoring::Plugin::Performance->parse_perfstring("processes=9;WKFLSV32.exe;9="); |
355 | is_deeply( \@p, [], "Fails parsing correctly"); | 355 | is_deeply( \@p, [], "Fails parsing correctly"); |
356 | 356 | ||
357 | # add_perfdata tests in t/Nagios-Plugin-01.t | 357 | # add_perfdata tests in t/Monitoring-Plugin-01.t |
diff --git a/t/Nagios-Plugin-Range.t b/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 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | #use Test::More qw(no_plan); | 3 | #use Test::More qw(no_plan); |
4 | use Test::More tests => 151; | 4 | use Test::More tests => 151; |
5 | 5 | ||
6 | BEGIN { | 6 | BEGIN { |
7 | use_ok('Nagios::Plugin::Range'); | 7 | use_ok('Monitoring::Plugin::Range'); |
8 | # Silence warnings unless TEST_VERBOSE is set | 8 | # Silence warnings unless TEST_VERBOSE is set |
9 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; | 9 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; |
10 | }; | 10 | }; |
11 | 11 | ||
12 | diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE}; | 12 | diag "\nusing Monitoring::Plugin::Range revision ". $Monitoring::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
13 | 13 | ||
14 | my $r; | 14 | my $r; |
15 | 15 | ||
@@ -25,14 +25,14 @@ foreach (qw( | |||
25 | 25 | ||
26 | ), '1,10' # avoid warning about using , inside qw() | 26 | ), '1,10' # avoid warning about using , inside qw() |
27 | ) { | 27 | ) { |
28 | $r =Nagios::Plugin::Range->parse_range_string($_); | 28 | $r =Monitoring::Plugin::Range->parse_range_string($_); |
29 | is $r, undef, "'$_' should not be a valid range" ; | 29 | is $r, undef, "'$_' should not be a valid range" ; |
30 | } | 30 | } |
31 | 31 | ||
32 | 32 | ||
33 | diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE}; | 33 | diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE}; |
34 | $r = Nagios::Plugin::Range->parse_range_string("6"); | 34 | $r = Monitoring::Plugin::Range->parse_range_string("6"); |
35 | isa_ok( $r, "Nagios::Plugin::Range"); | 35 | isa_ok( $r, "Monitoring::Plugin::Range"); |
36 | ok( defined $r, "'6' is valid range"); | 36 | ok( defined $r, "'6' is valid range"); |
37 | cmp_ok( $r->start, '==', 0, "Start correct"); | 37 | cmp_ok( $r->start, '==', 0, "Start correct"); |
38 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 38 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -53,7 +53,7 @@ sub test_expected { | |||
53 | my $r = shift; | 53 | my $r = shift; |
54 | my $expected = shift; | 54 | my $expected = shift; |
55 | foreach (sort {$a<=>$b} keys %$expected) { | 55 | foreach (sort {$a<=>$b} keys %$expected) { |
56 | is $r->check_range($_), $expected->{$_}, | 56 | is $r->check_range($_), $expected->{$_}, |
57 | " $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")"; | 57 | " $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")"; |
58 | } | 58 | } |
59 | } | 59 | } |
@@ -61,7 +61,7 @@ sub test_expected { | |||
61 | test_expected( $r, $expected ); | 61 | test_expected( $r, $expected ); |
62 | 62 | ||
63 | diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE}; | 63 | diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE}; |
64 | $r = Nagios::Plugin::Range->parse_range_string("-7:23"); | 64 | $r = Monitoring::Plugin::Range->parse_range_string("-7:23"); |
65 | ok( defined $r, "'-7:23' is valid range"); | 65 | ok( defined $r, "'-7:23' is valid range"); |
66 | cmp_ok( $r->start, '==', -7, "Start correct"); | 66 | cmp_ok( $r->start, '==', -7, "Start correct"); |
67 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 67 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -72,7 +72,7 @@ cmp_ok( $r, 'eq', "-7:23", "Stringification back to original"); | |||
72 | $expected = { | 72 | $expected = { |
73 | -23 => 1, | 73 | -23 => 1, |
74 | -7 => 0, | 74 | -7 => 0, |
75 | -1 => 0, | 75 | -1 => 0, |
76 | 0 => 0, | 76 | 0 => 0, |
77 | 4 => 0, | 77 | 4 => 0, |
78 | 23 => 0, | 78 | 23 => 0, |
@@ -83,7 +83,7 @@ test_expected( $r, $expected ); | |||
83 | 83 | ||
84 | 84 | ||
85 | diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE}; | 85 | diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE}; |
86 | $r = Nagios::Plugin::Range->parse_range_string(":5.75"); | 86 | $r = Monitoring::Plugin::Range->parse_range_string(":5.75"); |
87 | ok( defined $r, "':5.75' is valid range"); | 87 | ok( defined $r, "':5.75' is valid range"); |
88 | cmp_ok( $r->start, '==', 0, "Start correct"); | 88 | cmp_ok( $r->start, '==', 0, "Start correct"); |
89 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 89 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -105,7 +105,7 @@ test_expected( $r, $expected ); | |||
105 | 105 | ||
106 | 106 | ||
107 | diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE}; | 107 | diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE}; |
108 | $r = Nagios::Plugin::Range->parse_range_string("~:-95.99"); | 108 | $r = Monitoring::Plugin::Range->parse_range_string("~:-95.99"); |
109 | ok( defined $r, "'~:-95.99' is valid range"); | 109 | ok( defined $r, "'~:-95.99' is valid range"); |
110 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | 110 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); |
111 | cmp_ok( $r->end, '==', -95.99, "End correct"); | 111 | cmp_ok( $r->end, '==', -95.99, "End correct"); |
@@ -126,7 +126,7 @@ test_expected( $r, $expected ); | |||
126 | 126 | ||
127 | diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE}; | 127 | diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE}; |
128 | test_expected( $r, $expected ); | 128 | test_expected( $r, $expected ); |
129 | $r = Nagios::Plugin::Range->parse_range_string("10:"); | 129 | $r = Monitoring::Plugin::Range->parse_range_string("10:"); |
130 | ok( defined $r, "'10:' is valid range"); | 130 | ok( defined $r, "'10:' is valid range"); |
131 | cmp_ok( $r->start, '==', 10, "Start correct"); | 131 | cmp_ok( $r->start, '==', 10, "Start correct"); |
132 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 132 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -147,7 +147,7 @@ test_expected( $r, $expected ); | |||
147 | 147 | ||
148 | diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE}; | 148 | diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE}; |
149 | test_expected( $r, $expected ); | 149 | test_expected( $r, $expected ); |
150 | $r = Nagios::Plugin::Range->parse_range_string("123456789012345:"); | 150 | $r = Monitoring::Plugin::Range->parse_range_string("123456789012345:"); |
151 | ok( defined $r, "'123456789012345:' is valid range"); | 151 | ok( defined $r, "'123456789012345:' is valid range"); |
152 | cmp_ok( $r->start, '==', 123456789012345, "Start correct"); | 152 | cmp_ok( $r->start, '==', 123456789012345, "Start correct"); |
153 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 153 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -159,7 +159,7 @@ $expected = { | |||
159 | 0 => 1, | 159 | 0 => 1, |
160 | # The fractional values needs to be quoted, otherwise the hash rounds it up to ..345 | 160 | # The fractional values needs to be quoted, otherwise the hash rounds it up to ..345 |
161 | # and there is one less test run. | 161 | # and there is one less test run. |
162 | # I think some newer versions of perl use a higher precision value for the hash key. | 162 | # I think some newer versions of perl use a higher precision value for the hash key. |
163 | # This doesn't appear to affect the actual plugin though | 163 | # This doesn't appear to affect the actual plugin though |
164 | "123456789012344.91" => 1, | 164 | "123456789012344.91" => 1, |
165 | 123456789012345 => 0, | 165 | 123456789012345 => 0, |
@@ -170,7 +170,7 @@ test_expected( $r, $expected ); | |||
170 | 170 | ||
171 | 171 | ||
172 | diag "range: <= zero " if $ENV{TEST_VERBOSE}; | 172 | diag "range: <= zero " if $ENV{TEST_VERBOSE}; |
173 | $r = Nagios::Plugin::Range->parse_range_string("~:0"); | 173 | $r = Monitoring::Plugin::Range->parse_range_string("~:0"); |
174 | ok( defined $r, "'~:0' is valid range"); | 174 | ok( defined $r, "'~:0' is valid range"); |
175 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | 175 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); |
176 | cmp_ok( $r->end, '==', 0, "End correct"); | 176 | cmp_ok( $r->end, '==', 0, "End correct"); |
@@ -191,7 +191,7 @@ test_expected( $r, $expected ); | |||
191 | 191 | ||
192 | 192 | ||
193 | diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE}; | 193 | diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE}; |
194 | $r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567'); | 194 | $r = Monitoring::Plugin::Range->parse_range_string('@0:657.8210567'); |
195 | ok( defined $r, '"@0:657.8210567" is a valid range'); | 195 | ok( defined $r, '"@0:657.8210567" is a valid range'); |
196 | cmp_ok( $r->start, '==', 0, "Start correct"); | 196 | cmp_ok( $r->start, '==', 0, "Start correct"); |
197 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 197 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -216,7 +216,7 @@ test_expected( $r, $expected ); | |||
216 | 216 | ||
217 | 217 | ||
218 | diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE}; | 218 | diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE}; |
219 | $r = Nagios::Plugin::Range->parse_range_string('1:1'); | 219 | $r = Monitoring::Plugin::Range->parse_range_string('1:1'); |
220 | ok( defined $r, '"1:1" is a valid range'); | 220 | ok( defined $r, '"1:1" is a valid range'); |
221 | cmp_ok( $r->start, '==', 1, "Start correct"); | 221 | cmp_ok( $r->start, '==', 1, "Start correct"); |
222 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | 222 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); |
@@ -237,7 +237,7 @@ $expected = { | |||
237 | test_expected( $r, $expected ); | 237 | test_expected( $r, $expected ); |
238 | 238 | ||
239 | 239 | ||
240 | $r = Nagios::Plugin::Range->parse_range_string('2:1'); | 240 | $r = Monitoring::Plugin::Range->parse_range_string('2:1'); |
241 | ok( ! defined $r, '"2:1" is rejected'); | 241 | ok( ! defined $r, '"2:1" is rejected'); |
242 | 242 | ||
243 | # TODO: Need more tests for invalid data | 243 | # TODO: Need more tests for invalid data |
diff --git a/t/Nagios-Plugin-Threshold.t b/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 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 93; | 3 | use Test::More tests => 93; |
4 | BEGIN { | 4 | BEGIN { |
5 | use_ok('Nagios::Plugin::Threshold'); | 5 | use_ok('Monitoring::Plugin::Threshold'); |
6 | use_ok('Nagios::Plugin::Functions', ':all' ); | 6 | use_ok('Monitoring::Plugin::Functions', ':all' ); |
7 | # Silence warnings unless TEST_VERBOSE is set | 7 | # Silence warnings unless TEST_VERBOSE is set |
8 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; | 8 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; |
9 | } | 9 | } |
10 | 10 | ||
11 | diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n" | 11 | diag "\nusing Monitoring::Plugin::Threshold revision ". $Monitoring::Plugin::Threshold::VERSION . "\n" |
12 | if $ENV{TEST_VERBOSE}; | 12 | if $ENV{TEST_VERBOSE}; |
13 | 13 | ||
14 | Nagios::Plugin::Functions::_fake_exit(1); | 14 | Monitoring::Plugin::Functions::_fake_exit(1); |
15 | 15 | ||
16 | my $t; | 16 | my $t; |
17 | 17 | ||
18 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => undef, critical => undef); | 18 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => undef, critical => undef); |
19 | ok( defined $t, "two undefs" ); | 19 | ok( defined $t, "two undefs" ); |
20 | ok( ! $t->warning->is_set, "warning not set" ); | 20 | ok( ! $t->warning->is_set, "warning not set" ); |
21 | ok( ! $t->critical->is_set, "critical not set" ); | 21 | ok( ! $t->critical->is_set, "critical not set" ); |
22 | 22 | ||
23 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "", critical => ""); | 23 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "", critical => ""); |
24 | ok( defined $t, "two empty strings" ); | 24 | ok( defined $t, "two empty strings" ); |
25 | ok( ! $t->warning->is_set, "warning not set" ); | 25 | ok( ! $t->warning->is_set, "warning not set" ); |
26 | ok( ! $t->critical->is_set, "critical not set" ); | 26 | ok( ! $t->critical->is_set, "critical not set" ); |
27 | 27 | ||
28 | diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; | 28 | diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; |
29 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); | 29 | my $t = Monitoring::Plugin::Threshold->set_thresholds(critical => "80"); |
30 | ok( defined $t, "Threshold ('', '80') set"); | 30 | ok( defined $t, "Threshold ('', '80') set"); |
31 | ok( ! $t->warning->is_set, "Warning not set"); | 31 | ok( ! $t->warning->is_set, "Warning not set"); |
32 | cmp_ok( $t->critical->start, '==', 0, "Critical strat set correctly"); | 32 | cmp_ok( $t->critical->start, '==', 0, "Critical strat set correctly"); |
@@ -59,11 +59,11 @@ sub test_expected_statuses { | |||
59 | } | 59 | } |
60 | test_expected_statuses( $t, $expected ); | 60 | test_expected_statuses( $t, $expected ); |
61 | 61 | ||
62 | # GMC: this test seems bogus to me - either we've died, in which case internal | 62 | # GMC: this test seems bogus to me - either we've died, in which case internal |
63 | # state is undefined (and untestable!), or we should be returning a non-fatal error | 63 | # state is undefined (and untestable!), or we should be returning a non-fatal error |
64 | if (0) { | 64 | if (0) { |
65 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | 65 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; |
66 | eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; | 66 | eval { $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; |
67 | ok( defined $t, "Threshold ('5:33', '') set"); | 67 | ok( defined $t, "Threshold ('5:33', '') set"); |
68 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | 68 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); |
69 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | 69 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); |
@@ -72,7 +72,7 @@ if (0) { | |||
72 | 72 | ||
73 | # GC: same as previous test, except critical is undef instead of '' | 73 | # GC: same as previous test, except critical is undef instead of '' |
74 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | 74 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; |
75 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef); | 75 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef); |
76 | ok( defined $t, "Threshold ('5:33', '') set"); | 76 | ok( defined $t, "Threshold ('5:33', '') set"); |
77 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | 77 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); |
78 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | 78 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); |
@@ -91,7 +91,7 @@ $expected = { qw( | |||
91 | test_expected_statuses( $t, $expected ); | 91 | test_expected_statuses( $t, $expected ); |
92 | 92 | ||
93 | diag "threshold: warn if more than 30; critical if > 60" if $ENV{TEST_VERBOSE}; | 93 | diag "threshold: warn if more than 30; critical if > 60" if $ENV{TEST_VERBOSE}; |
94 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60"); | 94 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "~:30", critical => "~:60"); |
95 | ok( defined $t, "Threshold ('~:30', '~:60') set"); | 95 | ok( defined $t, "Threshold ('~:30', '~:60') set"); |
96 | cmp_ok( $t->warning->end, '==', 30, "Warning end set"); | 96 | cmp_ok( $t->warning->end, '==', 30, "Warning end set"); |
97 | cmp_ok( $t->critical->end, '==',60, "Critical end set"); | 97 | cmp_ok( $t->critical->end, '==',60, "Critical end set"); |
@@ -118,23 +118,23 @@ test_expected_statuses( $t, $expected ); | |||
118 | goto SKIP_DEATH; | 118 | goto SKIP_DEATH; |
119 | diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; | 119 | diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; |
120 | diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; | 120 | diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; |
121 | Nagios::Plugin::Functions->print_on_die(1); | 121 | Monitoring::Plugin::Functions->print_on_die(1); |
122 | Nagios::Plugin::Functions->exit_on_die(1); | 122 | Monitoring::Plugin::Functions->exit_on_die(1); |
123 | 123 | ||
124 | dies_ok( sub { | 124 | dies_ok( sub { |
125 | $t = Nagios::Plugin::Threshold->set_thresholds( | 125 | $t = Monitoring::Plugin::Threshold->set_thresholds( |
126 | warning => "total", | 126 | warning => "total", |
127 | critical => "rubbish" | 127 | critical => "rubbish" |
128 | ) | 128 | ) |
129 | }, "bad thresholds cause death" | 129 | }, "bad thresholds cause death" |
130 | ); | 130 | ); |
131 | Nagios::Plugin::Functions->print_on_die(0); | 131 | Monitoring::Plugin::Functions->print_on_die(0); |
132 | Nagios::Plugin::Functions->exit_on_die(0); | 132 | Monitoring::Plugin::Functions->exit_on_die(0); |
133 | SKIP_DEATH: | 133 | SKIP_DEATH: |
134 | 134 | ||
135 | 135 | ||
136 | diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE}; | 136 | diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE}; |
137 | $t = Nagios::Plugin::Threshold->set_thresholds( critical => "~:25" ); | 137 | $t = Monitoring::Plugin::Threshold->set_thresholds( critical => "~:25" ); |
138 | ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" ); | 138 | ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" ); |
139 | ok( ! $t->warning->is_set, "Warning not set"); | 139 | ok( ! $t->warning->is_set, "Warning not set"); |
140 | cmp_ok( $t->critical->end, '==',25, "Critical end set"); | 140 | cmp_ok( $t->critical->end, '==',25, "Critical end set"); |
@@ -145,14 +145,14 @@ $expected = { qw( | |||
145 | 4 OK | 145 | 4 OK |
146 | 10 OK | 146 | 10 OK |
147 | 14.21 OK | 147 | 14.21 OK |
148 | 25 OK | 148 | 25 OK |
149 | 25.01 CRITICAL | 149 | 25.01 CRITICAL |
150 | 31001 CRITICAL | 150 | 31001 CRITICAL |
151 | ) }; | 151 | ) }; |
152 | test_expected_statuses( $t, $expected); | 152 | test_expected_statuses( $t, $expected); |
153 | 153 | ||
154 | diag "threshold: warn if OUTSIDE {10..25} , critical if > 25 " if $ENV{TEST_VERBOSE}; | 154 | diag "threshold: warn if OUTSIDE {10..25} , critical if > 25 " if $ENV{TEST_VERBOSE}; |
155 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25"); | 155 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "10:25", critical => "~:25"); |
156 | ok( defined $t, "Threshold ('10:25', '~:25') set"); | 156 | ok( defined $t, "Threshold ('10:25', '~:25') set"); |
157 | cmp_ok( $t->warning->start, '==', 10, "Warning start set"); | 157 | cmp_ok( $t->warning->start, '==', 10, "Warning start set"); |
158 | cmp_ok( $t->warning->end, '==', 25, "Warning end set"); | 158 | cmp_ok( $t->warning->end, '==', 25, "Warning end set"); |
@@ -164,7 +164,7 @@ $expected = { qw( | |||
164 | 9.999999 WARNING | 164 | 9.999999 WARNING |
165 | 10 OK | 165 | 10 OK |
166 | 14.21 OK | 166 | 14.21 OK |
167 | 25 OK | 167 | 25 OK |
168 | 25.01 CRITICAL | 168 | 25.01 CRITICAL |
169 | 31001 CRITICAL | 169 | 31001 CRITICAL |
170 | ) }; | 170 | ) }; |
@@ -172,7 +172,7 @@ test_expected_statuses( $t, $expected ); | |||
172 | 172 | ||
173 | 173 | ||
174 | diag "warn if INSIDE {10..25} , critical if < 10 " if $ENV{TEST_VERBOSE}; | 174 | diag "warn if INSIDE {10..25} , critical if < 10 " if $ENV{TEST_VERBOSE}; |
175 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:"); | 175 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => "\@10:25", critical => "10:"); |
176 | $expected = { qw( | 176 | $expected = { qw( |
177 | -1 CRITICAL | 177 | -1 CRITICAL |
178 | 4 CRITICAL | 178 | 4 CRITICAL |
@@ -187,7 +187,7 @@ test_expected_statuses( $t, $expected ); | |||
187 | 187 | ||
188 | 188 | ||
189 | # GMC: as of 0.16, set_thresholds can also be called as a mutator | 189 | # GMC: as of 0.16, set_thresholds can also be called as a mutator |
190 | diag "threshold mutator: warn if more than 30; critical if > 60" | 190 | diag "threshold mutator: warn if more than 30; critical if > 60" |
191 | if $ENV{TEST_VERBOSE}; | 191 | if $ENV{TEST_VERBOSE}; |
192 | my $t1 = $t; | 192 | my $t1 = $t; |
193 | $t->set_thresholds(warning => "0:45", critical => "0:90"); | 193 | $t->set_thresholds(warning => "0:45", critical => "0:90"); |
@@ -200,16 +200,16 @@ is( $t->critical->end, 90, "Critical end ok"); | |||
200 | 200 | ||
201 | 201 | ||
202 | # Also as of 0.16, accepts N::P::Range objects as arguments | 202 | # Also as of 0.16, accepts N::P::Range objects as arguments |
203 | my $warning = Nagios::Plugin::Range->parse_range_string("50"); | 203 | my $warning = Monitoring::Plugin::Range->parse_range_string("50"); |
204 | my $critical = Nagios::Plugin::Range->parse_range_string("70:90"); | 204 | my $critical = Monitoring::Plugin::Range->parse_range_string("70:90"); |
205 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical); | 205 | $t = Monitoring::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical); |
206 | ok( defined $t, "Threshold from ranges ('50', '70:90') set"); | 206 | ok( defined $t, "Threshold from ranges ('50', '70:90') set"); |
207 | is( $t->warning->start, 0, "Warning start ok"); | 207 | is( $t->warning->start, 0, "Warning start ok"); |
208 | is( $t->warning->end, 50, "Warning end ok"); | 208 | is( $t->warning->end, 50, "Warning end ok"); |
209 | is( $t->critical->start, 70, "Critical start ok"); | 209 | is( $t->critical->start, 70, "Critical start ok"); |
210 | is( $t->critical->end, 90, "Critical end ok"); | 210 | is( $t->critical->end, 90, "Critical end ok"); |
211 | 211 | ||
212 | $critical = Nagios::Plugin::Range->parse_range_string("90:"); | 212 | $critical = Monitoring::Plugin::Range->parse_range_string("90:"); |
213 | $t->set_thresholds(warning => "~:20", critical => $critical); | 213 | $t->set_thresholds(warning => "~:20", critical => $critical); |
214 | ok( defined $t, "Threshold from string + range ('~:20', '90:') set"); | 214 | ok( defined $t, "Threshold from string + range ('~:20', '90:') set"); |
215 | ok( $t->warning->start_infinity, "Warning start ok (infinity)"); | 215 | 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 @@ | |||
1 | # Nagios::Plugin test set 2, testing NP::Functions wrapping | ||
2 | |||
3 | use strict; | ||
4 | use Test::More tests => 103; | ||
5 | |||
6 | BEGIN { use_ok("Nagios::Plugin") } | ||
7 | require Nagios::Plugin::Functions; | ||
8 | Nagios::Plugin::Functions::_fake_exit(1); | ||
9 | |||
10 | # Hardcoded checks of constants | ||
11 | my %ERRORS = %Nagios::Plugin::Functions::ERRORS; | ||
12 | is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); | ||
13 | is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}"); | ||
14 | is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}"); | ||
15 | is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}"); | ||
16 | is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}"); | ||
17 | |||
18 | my $plugin = 'TEST_PLUGIN'; | ||
19 | my $np = Nagios::Plugin->new( shortname => $plugin ); | ||
20 | is($np->shortname, $plugin, "shortname() is $plugin"); | ||
21 | |||
22 | # Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg ) | ||
23 | my $r; | ||
24 | my @ok = ( | ||
25 | [ OK, "OK", 'test the first', ], | ||
26 | [ WARNING, "WARNING", 'test the second', ], | ||
27 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
28 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
29 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
30 | ); | ||
31 | for (@ok) { | ||
32 | # CONSTANT | ||
33 | $r = $np->nagios_exit($_->[0], $_->[2]); | ||
34 | is($r->return_code, $_->[0], | ||
35 | sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
36 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
37 | sprintf('nagios_exit(%s, $msg) output matched "%s"', $_->[1], | ||
38 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
39 | |||
40 | # $string | ||
41 | $r = $np->nagios_exit($_->[1], $_->[2]); | ||
42 | is($r->return_code, $_->[0], | ||
43 | sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
44 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
45 | sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1], | ||
46 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
47 | like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
48 | sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1], | ||
49 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
50 | } | ||
51 | |||
52 | # nagios_exit code corner cases | ||
53 | my @ugly1 = ( | ||
54 | [ -1, 'testing code -1' ], | ||
55 | [ 7, 'testing code 7' ], | ||
56 | [ undef, 'testing code undef' ], | ||
57 | [ '', qq(testing code '') ], | ||
58 | [ 'string', qq(testing code 'string') ], | ||
59 | ); | ||
60 | for (@ugly1) { | ||
61 | $r = $np->nagios_exit($_->[0], $_->[1]); | ||
62 | my $display = defined $_->[0] ? "'$_->[0]'" : 'undef'; | ||
63 | is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN); | ||
64 | like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/, | ||
65 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
66 | $display, 'UNKNOWN.*' . $_->[1])); | ||
67 | } | ||
68 | |||
69 | # nagios_exit message corner cases | ||
70 | my @ugly2 = ( | ||
71 | [ '' ], | ||
72 | [ undef ], | ||
73 | [ UNKNOWN ], | ||
74 | ); | ||
75 | for (@ugly2) { | ||
76 | $r = $np->nagios_exit(CRITICAL, $_->[0]); | ||
77 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
78 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
79 | like($r->message, qr/CRITICAL\b.*\b$display2$/, | ||
80 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
81 | $display1, "CRITICAL.*$display2")); | ||
82 | } | ||
83 | |||
84 | # Test nagios_die( $msg ) | ||
85 | my @msg = ( | ||
86 | [ 'die you dog' ], | ||
87 | [ '' ], | ||
88 | [ undef ], | ||
89 | ); | ||
90 | for (@msg) { | ||
91 | $r = $np->nagios_die($_->[0]); | ||
92 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
93 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
94 | is($r->return_code, UNKNOWN, | ||
95 | sprintf('nagios_die(%s) returned UNKNOWN', $display1)); | ||
96 | like($r->message, qr/UNKNOWN\b.*\b$display2$/, | ||
97 | sprintf('nagios_die(%s) output matched "%s"', $display1, | ||
98 | "UNKNOWN.*$display2")); | ||
99 | } | ||
100 | |||
101 | # Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ), | ||
102 | # nagios_die( $string, $msg ), and nagios_die( $msg, $string ) | ||
103 | @ok = ( | ||
104 | [ OK, "OK", 'test the first', ], | ||
105 | [ WARNING, "WARNING", 'test the second', ], | ||
106 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
107 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
108 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
109 | ); | ||
110 | for (@ok) { | ||
111 | # CONSTANT, $msg | ||
112 | $r = $np->nagios_die($_->[0], $_->[2]); | ||
113 | is($r->return_code, $_->[0], | ||
114 | sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
115 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
116 | sprintf('nagios_die(%s, $msg) output matched "%s"', | ||
117 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
118 | |||
119 | # $msg, CONSTANT | ||
120 | $r = $np->nagios_die($_->[2], $_->[0]); | ||
121 | is($r->return_code, $_->[0], | ||
122 | sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0])); | ||
123 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
124 | sprintf('nagios_die($msg, %s) output matched "%s"', | ||
125 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
126 | |||
127 | # $string, $msg | ||
128 | $r = $np->nagios_die($_->[1], $_->[2]); | ||
129 | is($r->return_code, $_->[0], | ||
130 | sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
131 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
132 | sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1], | ||
133 | $_->[1] . '.*' . $_->[2])); | ||
134 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
135 | sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1], | ||
136 | $_->[1] . '.*' . $_->[2])); | ||
137 | |||
138 | # $string, $msg | ||
139 | $r = $np->nagios_die($_->[2], $_->[1]); | ||
140 | is($r->return_code, $_->[0], | ||
141 | sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0])); | ||
142 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
143 | sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1], | ||
144 | $_->[1] . '.*' . $_->[2])); | ||
145 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
146 | sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1], | ||
147 | $_->[1] . '.*' . $_->[2])); | ||
148 | } | ||
149 | |||
150 | |||
151 | # shortname testing | ||
152 | SKIP: { | ||
153 | skip "requires File::Basename", 2 unless eval { require File::Basename }; | ||
154 | $np = Nagios::Plugin->new( version => "1"); | ||
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 | |||
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 @@ | |||
1 | |||
2 | use strict; | ||
3 | use Test::More tests => 113; | ||
4 | |||
5 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); } | ||
6 | Nagios::Plugin::Functions::_fake_exit(1); | ||
7 | |||
8 | my $this_version=$Nagios::Plugin::Functions::VERSION; | ||
9 | foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { | ||
10 | my $mod = "Nagios::Plugin$m"; | ||
11 | use_ok($mod); | ||
12 | # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing | ||
13 | my $v = "$mod"."::VERSION"; | ||
14 | my $a = eval "\$$v"; | ||
15 | is($a, $this_version, "Version number for $mod the same as Functions: $this_version"); | ||
16 | } | ||
17 | |||
18 | # check get_shortname | ||
19 | is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok"); | ||
20 | |||
21 | # Hardcoded checks of constants | ||
22 | ok(defined %ERRORS, '%ERRORS defined'); | ||
23 | is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); | ||
24 | is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}"); | ||
25 | is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}"); | ||
26 | is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}"); | ||
27 | is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}"); | ||
28 | |||
29 | # Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg ) | ||
30 | my $r; | ||
31 | my @ok = ( | ||
32 | [ OK, "OK", 'test the first', ], | ||
33 | [ WARNING, "WARNING", 'test the second', ], | ||
34 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
35 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
36 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
37 | ); | ||
38 | for (@ok) { | ||
39 | # CONSTANT | ||
40 | $r = nagios_exit($_->[0], $_->[2]); | ||
41 | is($r->return_code, $_->[0], | ||
42 | sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
43 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
44 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
45 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
46 | |||
47 | # $string | ||
48 | $r = nagios_exit($_->[1], $_->[2]); | ||
49 | is($r->return_code, $_->[0], | ||
50 | sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
51 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
52 | sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1], | ||
53 | $_->[1] . '.*' . $_->[2])); | ||
54 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
55 | sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1], | ||
56 | $_->[1] . '.*' . $_->[2])); | ||
57 | } | ||
58 | |||
59 | # nagios_exit code corner cases | ||
60 | my @ugly1 = ( | ||
61 | [ -1, 'testing code -1' ], | ||
62 | [ 7, 'testing code 7' ], | ||
63 | [ undef, 'testing code undef' ], | ||
64 | [ '', qq(testing code '') ], | ||
65 | [ 'string', qq(testing code 'string') ], | ||
66 | ); | ||
67 | for (@ugly1) { | ||
68 | $r = nagios_exit($_->[0], $_->[1]); | ||
69 | my $display = defined $_->[0] ? "'$_->[0]'" : 'undef'; | ||
70 | is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN); | ||
71 | like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/, | ||
72 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
73 | $display, 'UNKNOWN.*' . $_->[1])); | ||
74 | } | ||
75 | |||
76 | # nagios_exit message corner cases | ||
77 | my @ugly2 = ( | ||
78 | [ '' ], | ||
79 | [ undef ], | ||
80 | [ UNKNOWN ], | ||
81 | ); | ||
82 | for (@ugly2) { | ||
83 | $r = nagios_exit(CRITICAL, $_->[0]); | ||
84 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
85 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
86 | like($r->message, qr/CRITICAL\b.*\b$display2$/, | ||
87 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
88 | $display1, "CRITICAL.*$display2")); | ||
89 | } | ||
90 | |||
91 | # Test nagios_die( $msg ) | ||
92 | my @msg = ( | ||
93 | [ 'die you dog' ], | ||
94 | [ '' ], | ||
95 | [ undef ], | ||
96 | ); | ||
97 | for (@msg) { | ||
98 | $r = nagios_die($_->[0]); | ||
99 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
100 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
101 | is($r->return_code, UNKNOWN, | ||
102 | sprintf('nagios_die(%s) returned UNKNOWN', $display1)); | ||
103 | like($r->message, qr/UNKNOWN\b.*\b$display2$/, | ||
104 | sprintf('nagios_die(%s) output matched "%s"', $display1, | ||
105 | "UNKNOWN.*$display2")); | ||
106 | } | ||
107 | |||
108 | # Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ), | ||
109 | # nagios_die( $string, $msg ), and nagios_die( $msg, $string ) | ||
110 | @ok = ( | ||
111 | [ OK, "OK", 'test the first', ], | ||
112 | [ WARNING, "WARNING", 'test the second', ], | ||
113 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
114 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
115 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
116 | ); | ||
117 | for (@ok) { | ||
118 | # CONSTANT, $msg | ||
119 | $r = nagios_die($_->[0], $_->[2]); | ||
120 | is($r->return_code, $_->[0], | ||
121 | sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
122 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
123 | sprintf('nagios_die(%s, $msg) output matched "%s"', | ||
124 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
125 | |||
126 | # $msg, CONSTANT | ||
127 | $r = nagios_die($_->[2], $_->[0]); | ||
128 | is($r->return_code, $_->[0], | ||
129 | sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0])); | ||
130 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
131 | sprintf('nagios_die($msg, %s) output matched "%s"', | ||
132 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
133 | |||
134 | # $string, $msg | ||
135 | $r = nagios_die($_->[1], $_->[2]); | ||
136 | is($r->return_code, $_->[0], | ||
137 | sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
138 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
139 | sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1], | ||
140 | $_->[1] . '.*' . $_->[2])); | ||
141 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
142 | sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1], | ||
143 | $_->[1] . '.*' . $_->[2])); | ||
144 | |||
145 | # $string, $msg | ||
146 | $r = nagios_die($_->[2], $_->[1]); | ||
147 | is($r->return_code, $_->[0], | ||
148 | sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0])); | ||
149 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
150 | sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1], | ||
151 | $_->[1] . '.*' . $_->[2])); | ||
152 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
153 | sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1], | ||
154 | $_->[1] . '.*' . $_->[2])); | ||
155 | } | ||
156 | |||
157 | # Check that _use_die set to 1 will catch exceptions correctly | ||
158 | Nagios::Plugin::Functions::_fake_exit(0); | ||
159 | Nagios::Plugin::Functions::_use_die(1); | ||
160 | eval { nagios_die("Using die") }; | ||
161 | 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 @@ | |||
1 | |||
2 | use strict; | ||
3 | use Test::More tests => 3; | ||
4 | use_ok("Nagios::Plugin::Performance", use_die => 1); | ||
5 | |||
6 | eval { Nagios::Plugin::Functions::nagios_die("Testing") }; | ||
7 | is( $@, "NAGIOS-PLUGIN-PERFORMANCE-02 UNKNOWN - Testing\n", "use_die correctly set on import"); | ||
8 | |||
9 | |||
10 | use_ok("Nagios::Plugin::Performance"); | ||
11 | eval { Nagios::Plugin::Functions::nagios_die("Test OK exit", 0) }; | ||
12 | |||
13 | 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 @@ | |||
2 | 2 | ||
3 | ### check_stuff.pl | 3 | ### check_stuff.pl |
4 | 4 | ||
5 | # an example Nagios plugin using the Nagios::Plugin modules. | 5 | # an example Monitoring plugin using the Monitoring::Plugin modules. |
6 | 6 | ||
7 | # Originally by Nathan Vonnahme, n8v at users dot sourceforge | 7 | # Originally by Nathan Vonnahme, n8v at users dot sourceforge |
8 | # dot net, July 19 2006 | 8 | # dot net, July 19 2006 |
9 | 9 | ||
10 | # Please modify to your heart's content and use as the basis for all | 10 | # Please modify to your heart's content and use as the basis for all |
11 | # the really cool Nagios monitoring scripts you're going to create. | 11 | # the really cool monitoring scripts you're going to create. |
12 | # You rock. | 12 | # You rock. |
13 | 13 | ||
14 | ############################################################################## | 14 | ############################################################################## |
15 | # prologue | 15 | # prologue |
16 | use strict; | 16 | use strict; |
17 | use warnings; | 17 | use warnings; |
18 | 18 | ||
19 | use Nagios::Plugin ; | 19 | use Monitoring::Plugin; |
20 | 20 | ||
21 | use vars qw($VERSION $PROGNAME $verbose $warn $critical $timeout $result); | 21 | use vars qw($VERSION $PROGNAME $verbose $warn $critical $timeout $result); |
22 | $VERSION = '1.0'; | 22 | $VERSION = '1.0'; |
@@ -28,18 +28,18 @@ $PROGNAME = basename($0); | |||
28 | 28 | ||
29 | ############################################################################## | 29 | ############################################################################## |
30 | # define and get the command line options. | 30 | # define and get the command line options. |
31 | # see the command line option guidelines at | 31 | # see the command line option guidelines at |
32 | # http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS | 32 | # https://www.monitoring-plugins.org/doc/guidelines.html#PLUGOPTIONS |
33 | 33 | ||
34 | 34 | ||
35 | # Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory) | 35 | # Instantiate Monitoring::Plugin object (the 'usage' parameter is mandatory) |
36 | my $p = Nagios::Plugin->new( | 36 | my $p = Monitoring::Plugin->new( |
37 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] | 37 | usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] |
38 | [ -c|--critical=<critical threshold> ] | 38 | [ -c|--critical=<critical threshold> ] |
39 | [ -w|--warning=<warning threshold> ] | 39 | [ -w|--warning=<warning threshold> ] |
40 | [ -r|--result = <INTEGER> ]", | 40 | [ -r|--result = <INTEGER> ]", |
41 | version => $VERSION, | 41 | version => $VERSION, |
42 | 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.', | 42 | 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.', |
43 | 43 | ||
44 | extra => " | 44 | extra => " |
45 | 45 | ||
@@ -47,11 +47,7 @@ THRESHOLDs for -w and -c are specified 'min:max' or 'min:' or ':max' | |||
47 | (or 'max'). If specified '\@min:max', a warning status will be generated | 47 | (or 'max'). If specified '\@min:max', a warning status will be generated |
48 | if the count *is* inside the specified range. | 48 | if the count *is* inside the specified range. |
49 | 49 | ||
50 | See more threshold examples at http | 50 | See more threshold examples at https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT |
51 | : // nagiosplug | ||
52 | . sourceforge | ||
53 | . net / developer-guidelines | ||
54 | . html #THRESHOLDFORMAT | ||
55 | 51 | ||
56 | Examples: | 52 | Examples: |
57 | 53 | ||
@@ -75,7 +71,7 @@ See more threshold examples at http | |||
75 | $p->add_arg( | 71 | $p->add_arg( |
76 | spec => 'warning|w=s', | 72 | spec => 'warning|w=s', |
77 | 73 | ||
78 | help => | 74 | help => |
79 | qq{-w, --warning=INTEGER:INTEGER | 75 | qq{-w, --warning=INTEGER:INTEGER |
80 | Minimum and maximum number of allowable result, outside of which a | 76 | Minimum and maximum number of allowable result, outside of which a |
81 | warning will be generated. If omitted, no warning is generated.}, | 77 | warning will be generated. If omitted, no warning is generated.}, |
@@ -86,7 +82,7 @@ qq{-w, --warning=INTEGER:INTEGER | |||
86 | 82 | ||
87 | $p->add_arg( | 83 | $p->add_arg( |
88 | spec => 'critical|c=s', | 84 | spec => 'critical|c=s', |
89 | help => | 85 | help => |
90 | qq{-c, --critical=INTEGER:INTEGER | 86 | qq{-c, --critical=INTEGER:INTEGER |
91 | Minimum and maximum number of the generated result, outside of | 87 | Minimum and maximum number of the generated result, outside of |
92 | which a critical will be generated. }, | 88 | which a critical will be generated. }, |
@@ -94,7 +90,7 @@ qq{-c, --critical=INTEGER:INTEGER | |||
94 | 90 | ||
95 | $p->add_arg( | 91 | $p->add_arg( |
96 | spec => 'result|r=f', | 92 | spec => 'result|r=f', |
97 | help => | 93 | help => |
98 | qq{-r, --result=INTEGER | 94 | qq{-r, --result=INTEGER |
99 | Specify the result on the command line rather than generating a | 95 | Specify the result on the command line rather than generating a |
100 | random number. For testing.}, | 96 | random number. For testing.}, |
@@ -106,11 +102,11 @@ $p->getopts; | |||
106 | 102 | ||
107 | # perform sanity checking on command line options | 103 | # perform sanity checking on command line options |
108 | if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { | 104 | if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { |
109 | $p->nagios_die( " invalid number supplied for the -r option " ); | 105 | $p->plugin_die( " invalid number supplied for the -r option " ); |
110 | } | 106 | } |
111 | 107 | ||
112 | unless ( defined $p->opts->warning || defined $p->opts->critical ) { | 108 | unless ( defined $p->opts->warning || defined $p->opts->critical ) { |
113 | $p->nagios_die( " you didn't supply a threshold argument " ); | 109 | $p->plugin_die( " you didn't supply a threshold argument " ); |
114 | } | 110 | } |
115 | 111 | ||
116 | 112 | ||
@@ -135,8 +131,7 @@ else { | |||
135 | ############################################################################## | 131 | ############################################################################## |
136 | # check the result against the defined warning and critical thresholds, | 132 | # check the result against the defined warning and critical thresholds, |
137 | # output the result and exit | 133 | # output the result and exit |
138 | $p->nagios_exit( | 134 | $p->plugin_exit( |
139 | return_code => $p->check_threshold($result), | 135 | return_code => $p->check_threshold($result), |
140 | message => " sample result was $result" | 136 | message => " sample result was $result" |
141 | ); | 137 | ); |
142 | |||
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 @@ | |||
1 | #!/usr/local/bin/perl | 1 | #!/usr/local/bin/perl |
2 | # | 2 | # |
3 | use strict; use warnings; | 3 | use strict; use warnings; |
4 | #use Test::More qw(no_plan); | 4 | #use Test::More qw(no_plan); |
5 | use Test::More tests => 14; | 5 | use Test::More tests => 14; |
@@ -10,7 +10,7 @@ $s = "$^X -Ilib $s"; | |||
10 | 10 | ||
11 | my $n = 'STUFF'; | 11 | my $n = 'STUFF'; |
12 | 12 | ||
13 | # Nagios status strings and exit codes | 13 | # Monitoring status strings and exit codes |
14 | my %e = qw( | 14 | my %e = qw( |
15 | OK 0 | 15 | OK 0 |
16 | WARNING 1 | 16 | WARNING 1 |
@@ -58,9 +58,3 @@ sub test_expected { | |||
58 | like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_"; | 58 | like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_"; |
59 | } | 59 | } |
60 | } | 60 | } |
61 | |||
62 | |||
63 | |||
64 | |||
65 | |||
66 | |||
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 @@ | |||
1 | Nagios-Plugin-Getopt-03.t automatically tests all cases defined in | 1 | Monitoring-Plugin-Getopt-03.t automatically tests all cases defined in |
2 | the 'input' directory and expects the output to match the | 2 | the 'input' directory and expects the output to match the |
3 | corresponding file in the 'expected' directory. To define a new test | 3 | corresponding file in the 'expected' directory. To define a new test |
4 | case, just create a new file in the 'input' directory containing the | 4 | case, just create a new file in the 'input' directory containing the |
5 | input command line, and a corresponding file in the 'expected' | 5 | input command line, and a corresponding file in the 'expected' |
6 | directory containing what you think the expanded command line should | 6 | directory containing what you think the expanded command line should |
7 | be. Note that this expansion is normalised as follows: | 7 | be. Note that this expansion is normalised as follows: |
8 | 8 | ||
9 | - command line arguments are reported in alphabetical order | 9 | - command line arguments are reported in alphabetical order |
10 | - extraneous white space is removed | 10 | - extraneous white space is removed |
11 | 11 | ||
12 | Also, if you use a completely new argument than those currently | 12 | Also, if you use a completely new argument than those currently |
13 | defined in Nagios-Plugin-Getopt-03.t you will need to define it | 13 | defined in Monitoring-Plugin-Getopt-03.t you will need to define it |
14 | there as well. | 14 | there as well. |
15 | 15 | ||