diff options
Diffstat (limited to 'lib/Nagios')
-rw-r--r-- | lib/Nagios/Plugin.pm | 6 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Base.pm | 196 | ||||
-rw-r--r-- | lib/Nagios/Plugin/ExitResult.pm | 6 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 344 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Getopt.pm | 6 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 4 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Range.pm | 4 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Threshold.pm | 4 |
8 files changed, 359 insertions, 211 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 41bff91..5ff6709 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
@@ -11,7 +11,7 @@ struct "Nagios::__::Plugin" => { | |||
11 | 11 | ||
12 | package Nagios::Plugin; | 12 | package Nagios::Plugin; |
13 | 13 | ||
14 | use Nagios::Plugin::Base; | 14 | use Nagios::Plugin::Functions; |
15 | use Nagios::Plugin::Performance; | 15 | use Nagios::Plugin::Performance; |
16 | use Nagios::Plugin::Threshold; | 16 | use Nagios::Plugin::Threshold; |
17 | 17 | ||
@@ -24,7 +24,7 @@ use Exporter; | |||
24 | our @ISA = qw(Exporter Nagios::__::Plugin); | 24 | our @ISA = qw(Exporter Nagios::__::Plugin); |
25 | our @EXPORT_OK = qw(%ERRORS); | 25 | our @EXPORT_OK = qw(%ERRORS); |
26 | 26 | ||
27 | our $VERSION = $Nagios::Plugin::Base::VERSION; | 27 | our $VERSION = $Nagios::Plugin::Functions::VERSION; |
28 | 28 | ||
29 | sub add_perfdata { | 29 | sub add_perfdata { |
30 | my ($self, %args) = @_; | 30 | my ($self, %args) = @_; |
@@ -41,7 +41,7 @@ sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } | |||
41 | 41 | ||
42 | sub die { | 42 | sub die { |
43 | my $self = shift; | 43 | my $self = shift; |
44 | Nagios::Plugin::Base::die(@_, { plugin => $self }); | 44 | Nagios::Plugin::Functions::die(@_, { plugin => $self }); |
45 | } | 45 | } |
46 | 46 | ||
47 | 1; | 47 | 1; |
diff --git a/lib/Nagios/Plugin/Base.pm b/lib/Nagios/Plugin/Base.pm deleted file mode 100644 index 92651ed..0000000 --- a/lib/Nagios/Plugin/Base.pm +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | # This module holds all exported variables | ||
2 | # and base functions | ||
3 | package Nagios::Plugin::Base; | ||
4 | |||
5 | use strict; | ||
6 | use warnings; | ||
7 | use File::Basename; | ||
8 | |||
9 | our $VERSION = "0.13"; | ||
10 | |||
11 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | ||
12 | |||
13 | require Exporter; | ||
14 | our @ISA = qw(Exporter); | ||
15 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit %ERRORS)); | ||
16 | our @EXPORT_OK = qw(nagios_die %STATUS_TEXT); | ||
17 | our %EXPORT_TAGS = ( | ||
18 | all => [ @EXPORT, @EXPORT_OK ], | ||
19 | codes => [ @STATUS_CODES ], | ||
20 | functions => [ qw(nagios_exit nagios_die) ], | ||
21 | ); | ||
22 | |||
23 | use constant OK => 0; | ||
24 | use constant WARNING => 1; | ||
25 | use constant CRITICAL => 2; | ||
26 | use constant UNKNOWN => 3; | ||
27 | use constant DEPENDENT => 4; | ||
28 | |||
29 | our %ERRORS = ( | ||
30 | 'OK' => OK, | ||
31 | 'WARNING' => WARNING, | ||
32 | 'CRITICAL' => CRITICAL, | ||
33 | 'UNKNOWN' => UNKNOWN, | ||
34 | 'DEPENDENT' => DEPENDENT, | ||
35 | ); | ||
36 | |||
37 | our %STATUS_TEXT = reverse %ERRORS; | ||
38 | |||
39 | # _fake_exit flag and accessor/mutator, for testing | ||
40 | my $_fake_exit = 0; | ||
41 | sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; | ||
42 | |||
43 | sub get_shortname { | ||
44 | my %arg = @_; | ||
45 | |||
46 | return $arg{plugin}->shortname if $arg{plugin}; | ||
47 | |||
48 | my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); | ||
49 | $shortname =~ s/^CHECK_//; | ||
50 | return $shortname; | ||
51 | } | ||
52 | |||
53 | # nagios_exit( $code, $message ) | ||
54 | sub nagios_exit { | ||
55 | my ($code, $message, $arg) = @_; | ||
56 | |||
57 | # Handle named parameters | ||
58 | if (defined $code && ($code eq 'return_code' || $code eq 'message')) { | ||
59 | # Remove last argument if odd no and last is ref | ||
60 | if (int(@_ / 2) != @_ / 2 && ref $_[$#_]) { | ||
61 | $arg = pop @_; | ||
62 | } else { | ||
63 | undef $arg; | ||
64 | } | ||
65 | my %arg = @_; | ||
66 | $code = $arg{return_code}; | ||
67 | $message = $arg{message}; | ||
68 | } | ||
69 | $arg ||= {}; | ||
70 | |||
71 | # Handle string codes | ||
72 | $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; | ||
73 | |||
74 | # Set defaults | ||
75 | $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; | ||
76 | $message = '' unless defined $message; | ||
77 | $message = join(' ', @$message) if ref $message eq 'ARRAY'; | ||
78 | |||
79 | # Setup output | ||
80 | my $output = "$STATUS_TEXT{$code}"; | ||
81 | $output .= " - $message" if defined $message && $message ne ''; | ||
82 | my $shortname = get_shortname(plugin => $arg->{plugin}); | ||
83 | $output = "$shortname $output" if $shortname; | ||
84 | if ($arg->{plugin}) { | ||
85 | my $plugin = $arg->{plugin}; | ||
86 | $output .= " | ". $plugin->all_perfoutput if $plugin->perfdata; | ||
87 | } | ||
88 | $output .= "\n"; | ||
89 | |||
90 | # Don't actually exit if _fake_exit set | ||
91 | if ($_fake_exit) { | ||
92 | require Nagios::Plugin::ExitResult; | ||
93 | return Nagios::Plugin::ExitResult->new($code, $output); | ||
94 | } | ||
95 | |||
96 | # Print output and exit | ||
97 | print $output; | ||
98 | exit $code; | ||
99 | } | ||
100 | |||
101 | # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) | ||
102 | # Default $code: UNKNOWN | ||
103 | sub nagios_die { | ||
104 | my ($arg1, $arg2, $rest) = @_; | ||
105 | |||
106 | # Named parameters | ||
107 | if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) { | ||
108 | return nagios_exit(@_); | ||
109 | } | ||
110 | |||
111 | # ($code, $message) | ||
112 | elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) { | ||
113 | return nagios_exit(@_); | ||
114 | } | ||
115 | |||
116 | # ($message, $code) | ||
117 | elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) { | ||
118 | return nagios_exit($arg2, $arg1, $rest); | ||
119 | } | ||
120 | |||
121 | # Else just assume $arg1 is the message and hope for the best | ||
122 | else { | ||
123 | return nagios_exit( UNKNOWN, $arg1, $rest ); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | # For backwards compatibility | ||
128 | sub die { nagios_die(@_); } | ||
129 | |||
130 | |||
131 | =pod old | ||
132 | |||
133 | my $exit_on_die = 1; | ||
134 | sub exit_on_die { shift; @_ ? $exit_on_die = shift : $exit_on_die }; | ||
135 | my $print_on_die = 1; | ||
136 | sub print_on_die { shift; @_ ? $print_on_die = shift : $print_on_die }; | ||
137 | |||
138 | # Old version - TODO: remove | ||
139 | sub old_die { | ||
140 | my ($class, $args, $plugin) = @_; | ||
141 | my $return_code; | ||
142 | |||
143 | if ( exists $args->{return_code} | ||
144 | && exists $STATUS_TEXT{$args->{return_code}} | ||
145 | ) { | ||
146 | $return_code = $args->{return_code}; | ||
147 | } | ||
148 | else { | ||
149 | $return_code = $ERRORS{UNKNOWN}; | ||
150 | } | ||
151 | my $message = $args->{message} || "Internal error"; | ||
152 | my $output = join(" ", $STATUS_TEXT{$return_code}, $message); | ||
153 | if ($plugin) { | ||
154 | $output = $plugin->shortname." $output" if $plugin->shortname; | ||
155 | $output .= " | ".$plugin->all_perfoutput if $plugin->perfdata; | ||
156 | } | ||
157 | if ($print_on_die) { | ||
158 | print $output, $/; | ||
159 | } | ||
160 | if ($exit_on_die) { | ||
161 | exit $return_code; | ||
162 | } else { | ||
163 | return $output; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | =cut | ||
168 | |||
169 | 1; | ||
170 | |||
171 | # vim:sw=4:sm:et | ||
172 | |||
173 | __END__ | ||
174 | |||
175 | =head1 NAME | ||
176 | |||
177 | Nagios::Plugin::Base - Base functions for Nagios::Plugins | ||
178 | |||
179 | =head1 DESCRIPTION | ||
180 | |||
181 | See Nagios::Plugin for public interfaces. This module is for Nagios::Plugin developers to incorporate | ||
182 | common backend functionality. | ||
183 | |||
184 | =head1 AUTHOR | ||
185 | |||
186 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
187 | |||
188 | =head1 COPYRIGHT AND LICENSE | ||
189 | |||
190 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
191 | |||
192 | This library is free software; you can redistribute it and/or modify | ||
193 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
194 | at your option, any later version of Perl 5 you may have available. | ||
195 | |||
196 | =cut | ||
diff --git a/lib/Nagios/Plugin/ExitResult.pm b/lib/Nagios/Plugin/ExitResult.pm index f059424..191c92a 100644 --- a/lib/Nagios/Plugin/ExitResult.pm +++ b/lib/Nagios/Plugin/ExitResult.pm | |||
@@ -30,10 +30,10 @@ return codes when testing. | |||
30 | =head1 SYNOPSIS | 30 | =head1 SYNOPSIS |
31 | 31 | ||
32 | use Test::More; | 32 | use Test::More; |
33 | use Nagios::Plugin::Base; | 33 | use Nagios::Plugin::Functions; |
34 | 34 | ||
35 | # In a test file somewhere | 35 | # In a test file somewhere |
36 | Nagios::Plugin::Base::_fake_exit(1); | 36 | Nagios::Plugin::Functions::_fake_exit(1); |
37 | 37 | ||
38 | # Later ... | 38 | # Later ... |
39 | $e = nagios_exit( CRITICAL, 'aiiii ...' ); | 39 | $e = nagios_exit( CRITICAL, 'aiiii ...' ); |
@@ -50,7 +50,7 @@ return codes when testing. | |||
50 | Nagios::Plugin::ExitResult is a tiny helper class intended for use | 50 | Nagios::Plugin::ExitResult is a tiny helper class intended for use |
51 | when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult | 51 | when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult |
52 | object is returned by nagios_exit() and friends when | 52 | object is returned by nagios_exit() and friends when |
53 | Nagios::Plugin::Base::_fake_exit has been set, instead of doing a | 53 | Nagios::Plugin::Functions::_fake_exit has been set, instead of doing a |
54 | conventional print + exit. | 54 | conventional print + exit. |
55 | 55 | ||
56 | =head1 AUTHOR | 56 | =head1 AUTHOR |
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm new file mode 100644 index 0000000..9c20288 --- /dev/null +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -0,0 +1,344 @@ | |||
1 | # This module holds all exported variables | ||
2 | # and base functions | ||
3 | package Nagios::Plugin::Functions; | ||
4 | |||
5 | use strict; | ||
6 | use warnings; | ||
7 | use File::Basename; | ||
8 | use Params::Validate qw(validate :types); | ||
9 | |||
10 | our $VERSION = "0.13"; | ||
11 | |||
12 | our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | ||
13 | |||
14 | require Exporter; | ||
15 | our @ISA = qw(Exporter); | ||
16 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); | ||
17 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT); | ||
18 | our %EXPORT_TAGS = ( | ||
19 | all => [ @EXPORT, @EXPORT_OK ], | ||
20 | codes => [ @STATUS_CODES ], | ||
21 | functions => [ qw(nagios_exit nagios_die check_messages) ], | ||
22 | ); | ||
23 | |||
24 | use constant OK => 0; | ||
25 | use constant WARNING => 1; | ||
26 | use constant CRITICAL => 2; | ||
27 | use constant UNKNOWN => 3; | ||
28 | use constant DEPENDENT => 4; | ||
29 | |||
30 | our %ERRORS = ( | ||
31 | 'OK' => OK, | ||
32 | 'WARNING' => WARNING, | ||
33 | 'CRITICAL' => CRITICAL, | ||
34 | 'UNKNOWN' => UNKNOWN, | ||
35 | 'DEPENDENT' => DEPENDENT, | ||
36 | ); | ||
37 | |||
38 | our %STATUS_TEXT = reverse %ERRORS; | ||
39 | |||
40 | # _fake_exit flag and accessor/mutator, for testing | ||
41 | my $_fake_exit = 0; | ||
42 | sub _fake_exit { @_ ? $_fake_exit = shift : $_fake_exit }; | ||
43 | |||
44 | sub get_shortname { | ||
45 | my %arg = @_; | ||
46 | |||
47 | return $arg{plugin}->shortname if $arg{plugin}; | ||
48 | |||
49 | my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); | ||
50 | $shortname =~ s/^CHECK_//; | ||
51 | return $shortname; | ||
52 | } | ||
53 | |||
54 | # nagios_exit( $code, $message ) | ||
55 | sub nagios_exit { | ||
56 | my ($code, $message, $arg) = @_; | ||
57 | |||
58 | # Handle named parameters | ||
59 | if (defined $code && ($code eq 'return_code' || $code eq 'message')) { | ||
60 | # Remove last argument if odd no and last is ref | ||
61 | if (int(@_ / 2) != @_ / 2 && ref $_[$#_]) { | ||
62 | $arg = pop @_; | ||
63 | } else { | ||
64 | undef $arg; | ||
65 | } | ||
66 | my %arg = @_; | ||
67 | $code = $arg{return_code}; | ||
68 | $message = $arg{message}; | ||
69 | } | ||
70 | $arg ||= {}; | ||
71 | |||
72 | # Handle string codes | ||
73 | $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; | ||
74 | |||
75 | # Set defaults | ||
76 | $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; | ||
77 | $message = '' unless defined $message; | ||
78 | $message = join(' ', @$message) if ref $message eq 'ARRAY'; | ||
79 | |||
80 | # Setup output | ||
81 | my $output = "$STATUS_TEXT{$code}"; | ||
82 | $output .= " - $message" if defined $message && $message ne ''; | ||
83 | my $shortname = get_shortname(plugin => $arg->{plugin}); | ||
84 | $output = "$shortname $output" if $shortname; | ||
85 | if ($arg->{plugin}) { | ||
86 | my $plugin = $arg->{plugin}; | ||
87 | $output .= " | ". $plugin->all_perfoutput if $plugin->perfdata; | ||
88 | } | ||
89 | $output .= "\n"; | ||
90 | |||
91 | # Don't actually exit if _fake_exit set | ||
92 | if ($_fake_exit) { | ||
93 | require Nagios::Plugin::ExitResult; | ||
94 | return Nagios::Plugin::ExitResult->new($code, $output); | ||
95 | } | ||
96 | |||
97 | # Print output and exit | ||
98 | print $output; | ||
99 | exit $code; | ||
100 | } | ||
101 | |||
102 | # nagios_die( $message, [ $code ]) OR nagios_die( $code, $message ) | ||
103 | # Default $code: UNKNOWN | ||
104 | sub nagios_die { | ||
105 | my ($arg1, $arg2, $rest) = @_; | ||
106 | |||
107 | # Named parameters | ||
108 | if (defined $arg1 && ($arg1 eq 'return_code' || $arg1 eq 'message')) { | ||
109 | return nagios_exit(@_); | ||
110 | } | ||
111 | |||
112 | # ($code, $message) | ||
113 | elsif (defined $arg1 && (exists $ERRORS{$arg1} || exists $STATUS_TEXT{$arg1})) { | ||
114 | return nagios_exit(@_); | ||
115 | } | ||
116 | |||
117 | # ($message, $code) | ||
118 | elsif (defined $arg2 && (exists $ERRORS{$arg2} || exists $STATUS_TEXT{$arg2})) { | ||
119 | return nagios_exit($arg2, $arg1, $rest); | ||
120 | } | ||
121 | |||
122 | # Else just assume $arg1 is the message and hope for the best | ||
123 | else { | ||
124 | return nagios_exit( UNKNOWN, $arg1, $rest ); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | # For backwards compatibility | ||
129 | sub die { nagios_die(@_); } | ||
130 | |||
131 | |||
132 | # ------------------------------------------------------------------------ | ||
133 | # check_messages - return a status and/or message based on a set of | ||
134 | # message arrays. | ||
135 | # Returns a nagios status code in scalar context. | ||
136 | # Returns a code and a message in list context. | ||
137 | # The message is join($join, @array) for the relevant array for the code, | ||
138 | # or join($join_all, $message) for all arrays if $join_all is set. | ||
139 | sub check_messages { | ||
140 | my %arg = validate( @_, { | ||
141 | critical => { type => ARRAYREF }, | ||
142 | warning => { type => ARRAYREF }, | ||
143 | ok => { type => ARRAYREF | SCALAR, optional => 1 }, | ||
144 | 'join' => { default => ' ' }, | ||
145 | join_all => 0, | ||
146 | }); | ||
147 | $arg{join} = ' ' unless defined $arg{join}; | ||
148 | |||
149 | # Decide $code | ||
150 | my $code = OK; | ||
151 | $code ||= CRITICAL if @{$arg{critical}}; | ||
152 | $code ||= WARNING if @{$arg{warning}}; | ||
153 | return $code unless wantarray; | ||
154 | |||
155 | # Compose message | ||
156 | my $message = ''; | ||
157 | if ($arg{join_all}) { | ||
158 | $message = join( $arg{join_all}, | ||
159 | map { @$_ ? join( $arg{'join'}, @$_) : () } | ||
160 | $arg{critical}, | ||
161 | $arg{warning}, | ||
162 | $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] | ||
163 | ); | ||
164 | } | ||
165 | |||
166 | else { | ||
167 | $message ||= join( $arg{'join'}, @{$arg{critical}} ) | ||
168 | if $code == CRITICAL; | ||
169 | $message ||= join( $arg{'join'}, @{$arg{warning}} ) | ||
170 | if $code == WARNING; | ||
171 | $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} | ||
172 | if $arg{ok}; | ||
173 | } | ||
174 | |||
175 | return ($code, $message); | ||
176 | } | ||
177 | |||
178 | # ------------------------------------------------------------------------ | ||
179 | |||
180 | 1; | ||
181 | |||
182 | # vim:sw=4:sm:et | ||
183 | |||
184 | __END__ | ||
185 | |||
186 | =head1 NAME | ||
187 | |||
188 | Nagios::Plugin::Functions - functions to simplify the creation of | ||
189 | Nagios plugins. | ||
190 | |||
191 | =head1 SYNOPSIS | ||
192 | |||
193 | # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default | ||
194 | use Nagios::Plugin::Functions; | ||
195 | |||
196 | # nagios_exit( ODE, $message ) - exit with error code CODE, | ||
197 | # and message "PLUGIN CODE - $message" | ||
198 | nagios_exit( CRITICAL, $critical_error ) if $critical_error; | ||
199 | nagios_exit( WARNING, $warning_error ) if $warning_error; | ||
200 | nagios_exit( OK, $result ); | ||
201 | |||
202 | # nagios_die( $message, [$CODE] ) - just like nagios_exit(), | ||
203 | # but CODE is optional, defaulting to UNKNOWN | ||
204 | do_something() | ||
205 | or nagios_die("do_something() failed horribly"); | ||
206 | do_something_critical() | ||
207 | or nagios_die("do_something_critical() failed", CRITICAL); | ||
208 | |||
209 | # check_messages - check a set of message arrays, returning a | ||
210 | # CODE and/or a result message | ||
211 | $code = check_messages(critical => \@crit, warning => \@warn); | ||
212 | ($code, $message) = check_messages( | ||
213 | critical => \@crit, warning => \@warn, | ||
214 | ok => \@ok ); | ||
215 | |||
216 | |||
217 | =head1 DESCRIPTION | ||
218 | |||
219 | This module is part of the Nagios::Plugin family, a set of modules | ||
220 | for simplifying the creation of Nagios plugins. This module exports | ||
221 | convenience functions for the class methods provided by | ||
222 | Nagios::Plugin. It is intended for those who prefer a simpler | ||
223 | functional interface, and who do not need the additional | ||
224 | functionality of Nagios::Plugin. | ||
225 | |||
226 | =head2 Exports | ||
227 | |||
228 | Nagios status code constants are exported by default: | ||
229 | |||
230 | OK | ||
231 | WARNING | ||
232 | CRITICAL | ||
233 | UNKNOWN | ||
234 | DEPENDENT | ||
235 | |||
236 | as are the following functions: | ||
237 | |||
238 | nagios_exit | ||
239 | nagios_die | ||
240 | check_messages | ||
241 | |||
242 | The following variables are exported only on request: | ||
243 | |||
244 | %ERRORS | ||
245 | %STATUS_TEXT | ||
246 | |||
247 | |||
248 | =head2 Functions | ||
249 | |||
250 | The following functions are supported: | ||
251 | |||
252 | =over 4 | ||
253 | |||
254 | =item nagios_exit( CODE, $message ) | ||
255 | |||
256 | Exit with return code CODE, and a standard nagios message of the | ||
257 | form "PLUGIN CODE - $message". | ||
258 | |||
259 | =item nagios_die( $message, [CODE] ) | ||
260 | |||
261 | Same as nagios_exit(), except that CODE is optional, defaulting | ||
262 | to UNKNOWN. | ||
263 | |||
264 | =item check_messages( critical => \@crit, warning => \@warn ) | ||
265 | |||
266 | Convenience function to check a set of message arrays and return | ||
267 | an appropriate nagios return code and/or a result message. Returns | ||
268 | only a return code in scalar context; returns a return code and an | ||
269 | error message in list context i.e. | ||
270 | |||
271 | # Scalar context | ||
272 | $code = check_messages(critical => \@crit, warning => \@warn); | ||
273 | # List context | ||
274 | ($code, $msg) = check_messages(critical => \@crit, warning => \@warn); | ||
275 | |||
276 | check_messages() accepts the following named arguments: | ||
277 | |||
278 | =over 4 | ||
279 | |||
280 | =item critical => ARRAYREF | ||
281 | |||
282 | An arrayref of critical error messages - check_messages() returns | ||
283 | CRITICAL if this arrayref is non-empty. Mandatory. | ||
284 | |||
285 | =item warning => ARRAYREF | ||
286 | |||
287 | An arrayref of warning error messages - check_messages() returns | ||
288 | WARNING if this arrayref is non-empty ('critical' is checked | ||
289 | first). Mandatory. | ||
290 | |||
291 | =item ok => ARRAYREF | SCALAR | ||
292 | |||
293 | An arrayref of informational messages (or a single scalar message), | ||
294 | used in list context if both the 'critical' and 'warning' arrayrefs | ||
295 | are empty. Optional. | ||
296 | |||
297 | =item join => SCALAR | ||
298 | |||
299 | A string used to join the relevant array to generate the message | ||
300 | string returned in list context i.e. if the 'critical' array @crit | ||
301 | is non-empty, check_messages would return: | ||
302 | |||
303 | join( $join, @crit ) | ||
304 | |||
305 | as the result message. Optional; default: ' ' (space). | ||
306 | |||
307 | =item join_all => SCALAR | ||
308 | |||
309 | By default, only one set of messages are joined and returned in the | ||
310 | result message i.e. if the result is CRITICAL, only the 'critical' | ||
311 | messages are included in the result; if WARNING, only the 'warning' | ||
312 | messages are included; if OK, the 'ok' messages are included (if | ||
313 | supplied) i.e. the default is to return an 'errors-only' type | ||
314 | message. | ||
315 | |||
316 | If join_all is supplied, however, it will be used as a string to | ||
317 | join the resultant critical, warning, and ok messages together i.e. | ||
318 | all messages are joined and returned. | ||
319 | |||
320 | =back | ||
321 | |||
322 | =back | ||
323 | |||
324 | |||
325 | =head1 SEE ALSO | ||
326 | |||
327 | Nagios::Plugin; the nagios plugin developer guidelines at | ||
328 | http://nagiosplug.sourceforge.net/developer-guidelines.html. | ||
329 | |||
330 | |||
331 | =head1 AUTHORS | ||
332 | |||
333 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
334 | |||
335 | |||
336 | =head1 COPYRIGHT AND LICENSE | ||
337 | |||
338 | Copyright (C) 2006 by Nagios Plugin Development Team | ||
339 | |||
340 | This library is free software; you can redistribute it and/or modify | ||
341 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
342 | at your option, any later version of Perl 5 you may have available. | ||
343 | |||
344 | =cut | ||
diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Nagios/Plugin/Getopt.pm index 7f32c3b..8a9fc1c 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Nagios/Plugin/Getopt.pm | |||
@@ -12,9 +12,9 @@ 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::Base; | 15 | use Nagios::Plugin::Functions; |
16 | use vars qw($VERSION); | 16 | use vars qw($VERSION); |
17 | $VERSION = $Nagios::Plugin::Base::VERSION; | 17 | $VERSION = $Nagios::Plugin::Functions::VERSION; |
18 | 18 | ||
19 | # Standard defaults | 19 | # Standard defaults |
20 | my %DEFAULT = ( | 20 | my %DEFAULT = ( |
@@ -586,7 +586,7 @@ Gavin Carr <gavin@openfusion.com.au> | |||
586 | 586 | ||
587 | =head1 COPYRIGHT AND LICENSE | 587 | =head1 COPYRIGHT AND LICENSE |
588 | 588 | ||
589 | Copyright 2005-2006 Gavin Carr. All Rights Reserved. | 589 | Copyright (C) 2006 by the Nagios Plugin Development Team. |
590 | 590 | ||
591 | This module is free software. It may be used, redistributed | 591 | This module is free software. It may be used, redistributed |
592 | and/or modified under either the terms of the Perl Artistic | 592 | and/or modified under either the terms of the Perl Artistic |
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm index 9e99f54..38803a6 100644 --- a/lib/Nagios/Plugin/Performance.pm +++ b/lib/Nagios/Plugin/Performance.pm | |||
@@ -7,8 +7,8 @@ use warnings; | |||
7 | 7 | ||
8 | use Carp; | 8 | use Carp; |
9 | use Nagios::Plugin::Threshold; | 9 | use Nagios::Plugin::Threshold; |
10 | use Nagios::Plugin::Base; | 10 | use Nagios::Plugin::Functions; |
11 | our ($VERSION) = $Nagios::Plugin::Base::VERSION; | 11 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
12 | 12 | ||
13 | use Class::Struct; | 13 | use Class::Struct; |
14 | struct "Nagios::Plugin::Performance" => { | 14 | struct "Nagios::Plugin::Performance" => { |
diff --git a/lib/Nagios/Plugin/Range.pm b/lib/Nagios/Plugin/Range.pm index b17cc96..f354a54 100644 --- a/lib/Nagios/Plugin/Range.pm +++ b/lib/Nagios/Plugin/Range.pm | |||
@@ -6,8 +6,8 @@ use strict; | |||
6 | use warnings; | 6 | use warnings; |
7 | use Carp; | 7 | use Carp; |
8 | 8 | ||
9 | use Nagios::Plugin::Base; | 9 | use Nagios::Plugin::Functions; |
10 | our ($VERSION) = $Nagios::Plugin::Base::VERSION; | 10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
11 | 11 | ||
12 | use overload | 12 | use overload |
13 | '""' => sub { shift->stringify }; | 13 | '""' => sub { shift->stringify }; |
diff --git a/lib/Nagios/Plugin/Threshold.pm b/lib/Nagios/Plugin/Threshold.pm index d7a8177..3e14d82 100644 --- a/lib/Nagios/Plugin/Threshold.pm +++ b/lib/Nagios/Plugin/Threshold.pm | |||
@@ -6,8 +6,8 @@ use strict; | |||
6 | use warnings; | 6 | use warnings; |
7 | 7 | ||
8 | use Nagios::Plugin::Range; | 8 | use Nagios::Plugin::Range; |
9 | use Nagios::Plugin::Base qw(:codes nagios_die); | 9 | use Nagios::Plugin::Functions qw(:codes nagios_die); |
10 | our ($VERSION) = $Nagios::Plugin::Base::VERSION; | 10 | our ($VERSION) = $Nagios::Plugin::Functions::VERSION; |
11 | 11 | ||
12 | use Class::Struct; | 12 | use Class::Struct; |
13 | struct "Nagios::Plugin::Threshold" => { | 13 | struct "Nagios::Plugin::Threshold" => { |