diff options
author | Gavin Carr <gonzai@users.sourceforge.net> | 2006-10-04 10:14:11 +0000 |
---|---|---|
committer | Gavin Carr <gonzai@users.sourceforge.net> | 2006-10-04 10:14:11 +0000 |
commit | 579fdad51ca7c1d306ba040954864216b0e07050 (patch) | |
tree | bb90e1235e0b27b2c767c67e5c4af1e9b6bd1839 | |
parent | f06255753edb3909f83bf279079698808192089d (diff) | |
download | monitoring-plugin-perl-579fdad51ca7c1d306ba040954864216b0e07050.tar.gz |
Tweak NP perldoc line widths; add missing chomp to NP::Functions.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1488 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | lib/Nagios/Plugin.pm | 123 | ||||
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 7 |
2 files changed, 75 insertions, 55 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index e6c0c04..5debdbc 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
@@ -109,7 +109,8 @@ __END__ | |||
109 | 109 | ||
110 | =head1 NAME | 110 | =head1 NAME |
111 | 111 | ||
112 | Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins | 112 | Nagios::Plugin - a family of perl modules to streamline writing Nagios |
113 | plugins | ||
113 | 114 | ||
114 | 115 | ||
115 | =head1 SYNOPSIS | 116 | =head1 SYNOPSIS |
@@ -122,19 +123,24 @@ Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins | |||
122 | $np = Nagios::Plugin->new; # OR | 123 | $np = Nagios::Plugin->new; # OR |
123 | $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); | 124 | $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); |
124 | 125 | ||
125 | # Exit methods - nagios_exit( CODE, MESSAGE ), nagios_die( MESSAGE, [CODE]) | 126 | # Exit methods - nagios_exit( CODE, MESSAGE ), |
127 | # nagios_die( MESSAGE, [CODE]) | ||
126 | $page = retrieve_page($page1) | 128 | $page = retrieve_page($page1) |
127 | or $np->nagios_exit( UNKNOWN, "Could not retrieve page" ); | 129 | or $np->nagios_exit( UNKNOWN, "Could not retrieve page" ); |
128 | # Return code: 3; output: PAGESIZE UNKNOWN - Could not retrieve page | 130 | # Return code: 3; |
131 | # output: PAGESIZE UNKNOWN - Could not retrieve page | ||
129 | test_page($page) | 132 | test_page($page) |
130 | or $np->nagios_exit( CRITICAL, "Bad page found" ); | 133 | or $np->nagios_exit( CRITICAL, "Bad page found" ); |
131 | 134 | ||
132 | # nagios_die() is just like nagios_exit(), but return code defaults to UNKNOWN | 135 | # nagios_die() is just like nagios_exit(), but return code defaults |
136 | # to UNKNOWN | ||
133 | $page = retrieve_page($page2) | 137 | $page = retrieve_page($page2) |
134 | or $np->nagios_die( "Could not retrieve page" ); | 138 | or $np->nagios_die( "Could not retrieve page" ); |
135 | # Return code: 3; output: PAGESIZE UNKNOWN - Could not retrieve page | 139 | # Return code: 3; |
140 | # output: PAGESIZE UNKNOWN - Could not retrieve page | ||
136 | 141 | ||
137 | # Threshold methods (NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold for now) | 142 | # Threshold methods (NOT YET IMPLEMENTED - use |
143 | # Nagios::Plugin::Threshold for now) | ||
138 | $code = $np->check_threshold( | 144 | $code = $np->check_threshold( |
139 | check => $value, | 145 | check => $value, |
140 | warning => $warning_threshold, | 146 | warning => $warning_threshold, |
@@ -153,8 +159,9 @@ Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins | |||
153 | } | 159 | } |
154 | ($code, $message) = $np->check_message(); | 160 | ($code, $message) = $np->check_message(); |
155 | nagios_exit( $code, $message ); | 161 | nagios_exit( $code, $message ); |
156 | # If any items in collection matched m/Error/, returns CRITICAL and the joined | 162 | # If any items in collection matched m/Error/, returns CRITICAL and |
157 | # set of Error messages; otherwise returns OK and the joined set of ok messages | 163 | # the joined set of Error messages; otherwise returns OK and the |
164 | # joined set of ok messages | ||
158 | 165 | ||
159 | # Perfdata methods | 166 | # Perfdata methods |
160 | $np->add_perfdata( | 167 | $np->add_perfdata( |
@@ -165,23 +172,26 @@ Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins | |||
165 | ); | 172 | ); |
166 | $np->add_perfdata( label => "time", ... ); | 173 | $np->add_perfdata( label => "time", ... ); |
167 | $np->nagios_exit( OK, "page size at http://... was ${value}kB" ); | 174 | $np->nagios_exit( OK, "page size at http://... was ${value}kB" ); |
168 | # Return code: 0; output: | 175 | # Return code: 0; |
169 | # PAGESIZE OK - page size at http://... was 36kB | size=36kB;10:25;25: time=... | 176 | # output: PAGESIZE OK - page size at http://... was 36kB \ |
177 | # | size=36kB;10:25;25: time=... | ||
170 | 178 | ||
171 | # Option handling methods (NOT YET IMPLEMENTED - use Nagios::Plugin::Getopt for now) | 179 | # Option handling methods (NOT YET IMPLEMENTED - use |
180 | # Nagios::Plugin::Getopt for now) | ||
172 | 181 | ||
173 | 182 | ||
174 | 183 | ||
175 | =head1 DESCRIPTION | 184 | =head1 DESCRIPTION |
176 | 185 | ||
177 | Nagios::Plugin and its associated Nagios::Plugin::* modules are a family of perl modules | 186 | Nagios::Plugin and its associated Nagios::Plugin::* modules are a family of |
178 | to streamline writing Nagios plugins. The main end user modules are Nagios::Plugin, | 187 | perl modules to streamline writing Nagios plugins. The main end user modules |
179 | providing an object-oriented interface to the entire Nagios::Plugin::* collection, and | 188 | are Nagios::Plugin, providing an object-oriented interface to the entire |
180 | Nagios::Plugin::Functions, providing a simpler functional interface to a useful subset of | 189 | Nagios::Plugin::* collection, and Nagios::Plugin::Functions, providing a |
181 | the available functionality. | 190 | simpler functional interface to a useful subset of the available |
191 | functionality. | ||
182 | 192 | ||
183 | The purpose of the collection is to make it as simple as possible for developers to | 193 | The purpose of the collection is to make it as simple as possible for |
184 | create plugins that conform the Nagios Plugin guidelines | 194 | developers to create plugins that conform the Nagios Plugin guidelines |
185 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). | 195 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). |
186 | 196 | ||
187 | 197 | ||
@@ -201,14 +211,14 @@ The following variables are also exported on request: | |||
201 | 211 | ||
202 | =item %ERRORS | 212 | =item %ERRORS |
203 | 213 | ||
204 | A hash mapping error strings ("CRITICAL", "UNKNOWN", etc.) to the corresponding | 214 | A hash mapping error strings ("CRITICAL", "UNKNOWN", etc.) to the |
205 | status code. | 215 | corresponding status code. |
206 | 216 | ||
207 | =item %STATUS_TEXT | 217 | =item %STATUS_TEXT |
208 | 218 | ||
209 | A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the | 219 | A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the |
210 | corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the reverse | 220 | corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the |
211 | of %ERRORS. | 221 | reverse of %ERRORS. |
212 | 222 | ||
213 | =back | 223 | =back |
214 | 224 | ||
@@ -219,14 +229,15 @@ of %ERRORS. | |||
219 | 229 | ||
220 | Nagios::Plugin->new( shortname => 'PAGESIZE' ); | 230 | Nagios::Plugin->new( shortname => 'PAGESIZE' ); |
221 | 231 | ||
222 | Instantiates a new Nagios::Plugin object. Accepts the following named arguments: | 232 | Instantiates a new Nagios::Plugin object. Accepts the following named |
233 | arguments: | ||
223 | 234 | ||
224 | =over 4 | 235 | =over 4 |
225 | 236 | ||
226 | =item shortname | 237 | =item shortname |
227 | 238 | ||
228 | The 'shortname' for this plugin, used as the first token in the plugin output | 239 | The 'shortname' for this plugin, used as the first token in the plugin |
229 | by the various exit methods. Default: uc basename $0. | 240 | output by the various exit methods. Default: uc basename $0. |
230 | 241 | ||
231 | =back | 242 | =back |
232 | 243 | ||
@@ -268,32 +279,33 @@ NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold directly for now. | |||
268 | EXPERIMENTAL AND SUBJECT TO CHANGE | 279 | EXPERIMENTAL AND SUBJECT TO CHANGE |
269 | 280 | ||
270 | add_messages and check_messages are higher-level convenience methods to add | 281 | add_messages and check_messages are higher-level convenience methods to add |
271 | and then check a set of messages, returning an appropriate return code and/or | 282 | and then check a set of messages, returning an appropriate return code |
272 | result message. | 283 | and/or result message. |
273 | 284 | ||
274 | =over 4 | 285 | =over 4 |
275 | 286 | ||
276 | =item add_message( <CODE>, $message ) | 287 | =item add_message( <CODE>, $message ) |
277 | 288 | ||
278 | Add a message with CODE status to the object. May be called multiple times. The messages | 289 | Add a message with CODE status to the object. May be called multiple times. |
279 | added are checked by check_messages, following. | 290 | The messages added are checked by check_messages, following. |
280 | 291 | ||
281 | Only CRITICAL, WARNING, and OK are accepted as valid codes. | 292 | Only CRITICAL, WARNING, and OK are accepted as valid codes. |
282 | 293 | ||
283 | 294 | ||
284 | =item check_messages() | 295 | =item check_messages() |
285 | 296 | ||
286 | Check the current set of messages and return an appropriate nagios return code and/or a | 297 | Check the current set of messages and return an appropriate nagios return |
287 | result message. In scalar context, returns only a return code; in list context returns | 298 | code and/or a result message. In scalar context, returns only a return |
288 | both a return code and an output message, suitable for passing directly to nagios_exit() | 299 | code; in list context returns both a return code and an output message, |
289 | e.g. | 300 | suitable for passing directly to nagios_exit() e.g. |
290 | 301 | ||
291 | $code = $np->check_messages; | 302 | $code = $np->check_messages; |
292 | ($code, $message) = $np->check_messages; | 303 | ($code, $message) = $np->check_messages; |
293 | 304 | ||
294 | check_messages returns CRITICAL if any critical messages are found, WARNING if any | 305 | check_messages returns CRITICAL if any critical messages are found, WARNING |
295 | warning messages are found, and OK otherwise. The message returned in list context defaults | 306 | if any warning messages are found, and OK otherwise. The message returned |
296 | to the joined set of error messages; this may be customised using the arguments below. | 307 | in list context defaults to the joined set of error messages; this may be |
308 | customised using the arguments below. | ||
297 | 309 | ||
298 | check_messages accepts the following named arguments (none are required): | 310 | check_messages accepts the following named arguments (none are required): |
299 | 311 | ||
@@ -345,12 +357,14 @@ Additional ok messages to supplement any passed in via add_message(). | |||
345 | 357 | ||
346 | =item add_perfdata( label => "size", value => $value, uom => "kB", threshold => $threshold ) | 358 | =item add_perfdata( label => "size", value => $value, uom => "kB", threshold => $threshold ) |
347 | 359 | ||
348 | Add a set of performance data to the object. May be called multiple times. The performance | 360 | Add a set of performance data to the object. May be called multiple times. |
349 | data is included in the standard plugin output messages by the various exit methods. | 361 | The performance data is included in the standard plugin output messages by |
362 | the various exit methods. | ||
350 | 363 | ||
351 | See the Nagios::Plugin::Performance documentation for more information on performance data | 364 | See the Nagios::Plugin::Performance documentation for more information on |
352 | and the various field definitions, as well as the relevant section of the Nagios Plugin | 365 | performance data and the various field definitions, as well as the relevant |
353 | guidelines (http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). | 366 | section of the Nagios Plugin guidelines |
367 | (http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). | ||
354 | 368 | ||
355 | =back | 369 | =back |
356 | 370 | ||
@@ -364,15 +378,16 @@ NOT YET IMPLEMENTED - use Nagios::Plugin::Getopt directly for now. | |||
364 | 378 | ||
365 | "Enough talk! Show me some examples!" | 379 | "Enough talk! Show me some examples!" |
366 | 380 | ||
367 | See the file 'check_stuff.pl' in the 't' directory for a complete working example of a | 381 | See the file 'check_stuff.pl' in the 't' directory for a complete working |
368 | plugin script. | 382 | example of a plugin script. |
369 | 383 | ||
370 | 384 | ||
371 | =head1 VERSIONING | 385 | =head1 VERSIONING |
372 | 386 | ||
373 | The Nagios::Plugin::* modules are currently experimental and so the interfaces may | 387 | The Nagios::Plugin::* modules are currently experimental and so the |
374 | change up until Nagios::Plugin hits version 1.0, although every attempt will be made to | 388 | interfaces may change up until Nagios::Plugin hits version 1.0, although |
375 | keep them as backwards compatible as possible. | 389 | every attempt will be made to keep them as backwards compatible as |
390 | possible. | ||
376 | 391 | ||
377 | 392 | ||
378 | =head1 SEE ALSO | 393 | =head1 SEE ALSO |
@@ -380,8 +395,9 @@ keep them as backwards compatible as possible. | |||
380 | See Nagios::Plugin::Functions for a simple functional interface to a subset | 395 | See Nagios::Plugin::Functions for a simple functional interface to a subset |
381 | of the available Nagios::Plugin functionality. | 396 | of the available Nagios::Plugin functionality. |
382 | 397 | ||
383 | See also Nagios::Plugin::Getopt, Nagios::Plugin::Range, Nagios::Plugin::Performance, | 398 | See also Nagios::Plugin::Getopt, Nagios::Plugin::Range, |
384 | Nagios::Plugin::Range, and Nagios::Plugin::Threshold. | 399 | Nagios::Plugin::Performance, Nagios::Plugin::Range, and |
400 | Nagios::Plugin::Threshold. | ||
385 | 401 | ||
386 | The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. | 402 | The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. |
387 | 403 | ||
@@ -394,21 +410,20 @@ nagiosplug-devel@lists.sourceforge.net. | |||
394 | 410 | ||
395 | =head1 AUTHOR | 411 | =head1 AUTHOR |
396 | 412 | ||
397 | Maintained by the Nagios Plugin development team - http://nagiosplug.sourceforge.net. | 413 | Maintained by the Nagios Plugin development team - |
414 | http://nagiosplug.sourceforge.net. | ||
398 | 415 | ||
399 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. | 416 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. |
400 | 417 | ||
401 | Nathan Vonnahme added extra tests and subsequent fixes. | 418 | Nathan Vonnahme added extra tests and subsequent fixes. |
402 | 419 | ||
403 | 420 | ||
404 | |||
405 | =head1 COPYRIGHT AND LICENSE | 421 | =head1 COPYRIGHT AND LICENSE |
406 | 422 | ||
407 | Copyright (C) 2006 by Nagios Plugin Development Team | 423 | Copyright (C) 2006 by Nagios Plugin Development Team |
408 | 424 | ||
409 | This library is free software; you can redistribute it and/or modify | 425 | This library is free software; you can redistribute it and/or modify it |
410 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | 426 | under the same terms as Perl itself, either Perl version 5.8.4 or, at your |
411 | at your option, any later version of Perl 5 you may have available. | 427 | option, any later version of Perl 5 you may have available. |
412 | |||
413 | 428 | ||
414 | =cut | 429 | =cut |
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index e77bc4f..9cb7eb6 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -75,7 +75,12 @@ sub nagios_exit { | |||
75 | # Set defaults | 75 | # Set defaults |
76 | $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; | 76 | $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; |
77 | $message = '' unless defined $message; | 77 | $message = '' unless defined $message; |
78 | $message = join(' ', @$message) if ref $message eq 'ARRAY'; | 78 | if (ref $message && ref $message eq 'ARRAY') { |
79 | $message = join(' ', map { chomp; $_ } @$message); | ||
80 | } | ||
81 | else { | ||
82 | chomp $message; | ||
83 | } | ||
79 | 84 | ||
80 | # Setup output | 85 | # Setup output |
81 | my $output = "$STATUS_TEXT{$code}"; | 86 | my $output = "$STATUS_TEXT{$code}"; |