summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Carr <gonzai@users.sourceforge.net>2006-10-04 10:14:11 (GMT)
committerGavin Carr <gonzai@users.sourceforge.net>2006-10-04 10:14:11 (GMT)
commit579fdad51ca7c1d306ba040954864216b0e07050 (patch)
treebb90e1235e0b27b2c767c67e5c4af1e9b6bd1839
parentf06255753edb3909f83bf279079698808192089d (diff)
downloadmonitoring-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.pm123
-rw-r--r--lib/Nagios/Plugin/Functions.pm7
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
112Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins 112Nagios::Plugin - a family of perl modules to streamline writing Nagios
113plugins
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
177Nagios::Plugin and its associated Nagios::Plugin::* modules are a family of perl modules 186Nagios::Plugin and its associated Nagios::Plugin::* modules are a family of
178to streamline writing Nagios plugins. The main end user modules are Nagios::Plugin, 187perl modules to streamline writing Nagios plugins. The main end user modules
179providing an object-oriented interface to the entire Nagios::Plugin::* collection, and 188are Nagios::Plugin, providing an object-oriented interface to the entire
180Nagios::Plugin::Functions, providing a simpler functional interface to a useful subset of 189Nagios::Plugin::* collection, and Nagios::Plugin::Functions, providing a
181the available functionality. 190simpler functional interface to a useful subset of the available
191functionality.
182 192
183The purpose of the collection is to make it as simple as possible for developers to 193The purpose of the collection is to make it as simple as possible for
184create plugins that conform the Nagios Plugin guidelines 194developers 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
204A hash mapping error strings ("CRITICAL", "UNKNOWN", etc.) to the corresponding 214A hash mapping error strings ("CRITICAL", "UNKNOWN", etc.) to the
205status code. 215corresponding status code.
206 216
207=item %STATUS_TEXT 217=item %STATUS_TEXT
208 218
209A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the 219A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the
210corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the reverse 220corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the
211of %ERRORS. 221reverse 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
222Instantiates a new Nagios::Plugin object. Accepts the following named arguments: 232Instantiates a new Nagios::Plugin object. Accepts the following named
233arguments:
223 234
224=over 4 235=over 4
225 236
226=item shortname 237=item shortname
227 238
228The 'shortname' for this plugin, used as the first token in the plugin output 239The 'shortname' for this plugin, used as the first token in the plugin
229by the various exit methods. Default: uc basename $0. 240output 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.
268EXPERIMENTAL AND SUBJECT TO CHANGE 279EXPERIMENTAL AND SUBJECT TO CHANGE
269 280
270add_messages and check_messages are higher-level convenience methods to add 281add_messages and check_messages are higher-level convenience methods to add
271and then check a set of messages, returning an appropriate return code and/or 282and then check a set of messages, returning an appropriate return code
272result message. 283and/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
278Add a message with CODE status to the object. May be called multiple times. The messages 289Add a message with CODE status to the object. May be called multiple times.
279added are checked by check_messages, following. 290The messages added are checked by check_messages, following.
280 291
281Only CRITICAL, WARNING, and OK are accepted as valid codes. 292Only CRITICAL, WARNING, and OK are accepted as valid codes.
282 293
283 294
284=item check_messages() 295=item check_messages()
285 296
286Check the current set of messages and return an appropriate nagios return code and/or a 297Check the current set of messages and return an appropriate nagios return
287result message. In scalar context, returns only a return code; in list context returns 298code and/or a result message. In scalar context, returns only a return
288both a return code and an output message, suitable for passing directly to nagios_exit() 299code; in list context returns both a return code and an output message,
289e.g. 300suitable 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
294check_messages returns CRITICAL if any critical messages are found, WARNING if any 305check_messages returns CRITICAL if any critical messages are found, WARNING
295warning messages are found, and OK otherwise. The message returned in list context defaults 306if any warning messages are found, and OK otherwise. The message returned
296to the joined set of error messages; this may be customised using the arguments below. 307in list context defaults to the joined set of error messages; this may be
308customised using the arguments below.
297 309
298check_messages accepts the following named arguments (none are required): 310check_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
348Add a set of performance data to the object. May be called multiple times. The performance 360Add a set of performance data to the object. May be called multiple times.
349data is included in the standard plugin output messages by the various exit methods. 361The performance data is included in the standard plugin output messages by
362the various exit methods.
350 363
351See the Nagios::Plugin::Performance documentation for more information on performance data 364See the Nagios::Plugin::Performance documentation for more information on
352and the various field definitions, as well as the relevant section of the Nagios Plugin 365performance data and the various field definitions, as well as the relevant
353guidelines (http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). 366section 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
367See the file 'check_stuff.pl' in the 't' directory for a complete working example of a 381See the file 'check_stuff.pl' in the 't' directory for a complete working
368plugin script. 382example of a plugin script.
369 383
370 384
371=head1 VERSIONING 385=head1 VERSIONING
372 386
373The Nagios::Plugin::* modules are currently experimental and so the interfaces may 387The Nagios::Plugin::* modules are currently experimental and so the
374change up until Nagios::Plugin hits version 1.0, although every attempt will be made to 388interfaces may change up until Nagios::Plugin hits version 1.0, although
375keep them as backwards compatible as possible. 389every attempt will be made to keep them as backwards compatible as
390possible.
376 391
377 392
378=head1 SEE ALSO 393=head1 SEE ALSO
@@ -380,8 +395,9 @@ keep them as backwards compatible as possible.
380See Nagios::Plugin::Functions for a simple functional interface to a subset 395See Nagios::Plugin::Functions for a simple functional interface to a subset
381of the available Nagios::Plugin functionality. 396of the available Nagios::Plugin functionality.
382 397
383See also Nagios::Plugin::Getopt, Nagios::Plugin::Range, Nagios::Plugin::Performance, 398See also Nagios::Plugin::Getopt, Nagios::Plugin::Range,
384Nagios::Plugin::Range, and Nagios::Plugin::Threshold. 399Nagios::Plugin::Performance, Nagios::Plugin::Range, and
400Nagios::Plugin::Threshold.
385 401
386The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. 402The 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
397Maintained by the Nagios Plugin development team - http://nagiosplug.sourceforge.net. 413Maintained by the Nagios Plugin development team -
414http://nagiosplug.sourceforge.net.
398 415
399Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. 416Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>.
400 417
401Nathan Vonnahme added extra tests and subsequent fixes. 418Nathan Vonnahme added extra tests and subsequent fixes.
402 419
403 420
404
405=head1 COPYRIGHT AND LICENSE 421=head1 COPYRIGHT AND LICENSE
406 422
407Copyright (C) 2006 by Nagios Plugin Development Team 423Copyright (C) 2006 by Nagios Plugin Development Team
408 424
409This library is free software; you can redistribute it and/or modify 425This library is free software; you can redistribute it and/or modify it
410it under the same terms as Perl itself, either Perl version 5.8.4 or, 426under the same terms as Perl itself, either Perl version 5.8.4 or, at your
411at your option, any later version of Perl 5 you may have available. 427option, 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}";