diff options
Diffstat (limited to 'lib/Nagios')
| -rw-r--r-- | lib/Nagios/Plugin.pm | 386 | ||||
| -rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 15 |
2 files changed, 319 insertions, 82 deletions
diff --git a/lib/Nagios/Plugin.pm b/lib/Nagios/Plugin.pm index 5ff6709..025880d 100644 --- a/lib/Nagios/Plugin.pm +++ b/lib/Nagios/Plugin.pm | |||
| @@ -1,17 +1,17 @@ | |||
| 1 | # This is only because Class::Struct doesn't allow subclasses | 1 | # This is only because Class::Struct doesn't allow subclasses |
| 2 | # Trick stolen from Class::DBI | 2 | # Trick stolen from Class::DBI |
| 3 | package Nagios::__::Plugin; | 3 | ###package Nagios::__::Plugin; |
| 4 | 4 | ||
| 5 | use 5.008004; | ||
| 6 | use Class::Struct; | 5 | use Class::Struct; |
| 7 | struct "Nagios::__::Plugin" => { | 6 | struct "Nagios::__::Plugin" => { |
| 8 | perfdata => '@', | 7 | perfdata => '@', |
| 9 | shortname => '$', | 8 | shortname => '$', |
| 10 | }; | 9 | messages => '%', |
| 10 | }; | ||
| 11 | 11 | ||
| 12 | package Nagios::Plugin; | 12 | package Nagios::Plugin; |
| 13 | 13 | ||
| 14 | use Nagios::Plugin::Functions; | 14 | use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); |
| 15 | use Nagios::Plugin::Performance; | 15 | use Nagios::Plugin::Performance; |
| 16 | use Nagios::Plugin::Threshold; | 16 | use Nagios::Plugin::Threshold; |
| 17 | 17 | ||
| @@ -22,149 +22,385 @@ use Carp; | |||
| 22 | 22 | ||
| 23 | use Exporter; | 23 | use Exporter; |
| 24 | our @ISA = qw(Exporter Nagios::__::Plugin); | 24 | our @ISA = qw(Exporter Nagios::__::Plugin); |
| 25 | our @EXPORT = (@STATUS_CODES); | ||
| 25 | our @EXPORT_OK = qw(%ERRORS); | 26 | our @EXPORT_OK = qw(%ERRORS); |
| 26 | 27 | ||
| 27 | our $VERSION = $Nagios::Plugin::Functions::VERSION; | 28 | our $VERSION = $Nagios::Plugin::Functions::VERSION; |
| 28 | 29 | ||
| 29 | sub add_perfdata { | 30 | sub add_perfdata { |
| 30 | my ($self, %args) = @_; | 31 | my ($self, %args) = @_; |
| 31 | my $perf = Nagios::Plugin::Performance->new(%args); | 32 | my $perf = Nagios::Plugin::Performance->new(%args); |
| 32 | push @{$self->perfdata}, $perf; | 33 | push @{$self->perfdata}, $perf; |
| 33 | } | 34 | } |
| 34 | |||
| 35 | sub all_perfoutput { | 35 | sub all_perfoutput { |
| 36 | my $self = shift; | 36 | my $self = shift; |
| 37 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); | 37 | return join(" ", map {$_->perfoutput} (@{$self->perfdata})); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } | 40 | sub set_thresholds { shift; Nagios::Plugin::Threshold->set_thresholds(@_); } |
| 41 | 41 | ||
| 42 | # NP::Functions wrappers | ||
| 43 | sub nagios_exit { | ||
| 44 | my $self = shift; | ||
| 45 | Nagios::Plugin::Functions::nagios_exit(@_, { plugin => $self }); | ||
| 46 | } | ||
| 47 | sub nagios_die { | ||
| 48 | my $self = shift; | ||
| 49 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); | ||
| 50 | } | ||
| 42 | sub die { | 51 | sub die { |
| 43 | my $self = shift; | 52 | my $self = shift; |
| 44 | Nagios::Plugin::Functions::die(@_, { plugin => $self }); | 53 | Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self }); |
| 54 | } | ||
| 55 | |||
| 56 | # ------------------------------------------------------------------------- | ||
| 57 | # NP::Functions::check_messages helpers and wrappers | ||
| 58 | |||
| 59 | sub add_message { | ||
| 60 | my $self = shift; | ||
| 61 | my ($code, @messages) = @_; | ||
| 62 | |||
| 63 | croak "Invalid error code '$code'" | ||
| 64 | unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code}); | ||
| 65 | |||
| 66 | # Store messages using strings rather than numeric codes | ||
| 67 | $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; | ||
| 68 | $code = lc $code; | ||
| 69 | croak "Error code '$code' not supported by add_message" | ||
| 70 | if $code eq 'unknown' || $code eq 'dependent'; | ||
| 71 | |||
| 72 | $self->messages($code, []) unless $self->messages($code); | ||
| 73 | push @{$self->messages($code)}, @messages; | ||
| 45 | } | 74 | } |
| 46 | 75 | ||
| 76 | sub check_messages { | ||
| 77 | my $self = shift; | ||
| 78 | my %args = @_; | ||
| 79 | |||
| 80 | # Add object messages to any passed in as args | ||
| 81 | for my $code (qw(critical warning ok)) { | ||
| 82 | my $messages = $self->messages($code) || []; | ||
| 83 | if ($args{$code}) { | ||
| 84 | unless (ref $args{$code} eq 'ARRAY') { | ||
| 85 | if ($code eq 'ok') { | ||
| 86 | $args{$code} = [ $args{$code} ]; | ||
| 87 | } else { | ||
| 88 | croak "Invalid argument '$code'" | ||
| 89 | } | ||
| 90 | } | ||
| 91 | push @{$args{$code}}, @$messages; | ||
| 92 | } | ||
| 93 | else { | ||
| 94 | $args{$code} = $messages; | ||
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | Nagios::Plugin::Functions::check_messages(%args); | ||
| 99 | } | ||
| 100 | |||
| 101 | # ------------------------------------------------------------------------- | ||
| 102 | |||
| 47 | 1; | 103 | 1; |
| 48 | __END__ | ||
| 49 | 104 | ||
| 50 | =head1 NAME | 105 | #vim:et:sw=4 |
| 106 | |||
| 107 | __END__ | ||
| 51 | 108 | ||
| 52 | Nagios::Plugin - Object oriented helper routines for your Nagios plugin | ||
| 53 | 109 | ||
| 54 | =head1 SYNOPSIS | 110 | =head1 NAME |
| 55 | 111 | ||
| 56 | use Nagios::Plugin qw(%ERRORS); | 112 | Nagios::Plugin - a family of perl modules to streamline writing Nagios plugins |
| 57 | $p = Nagios::Plugin->new( shortname => "PAGESIZE" ); | ||
| 58 | 113 | ||
| 59 | $threshold = $p->set_thresholds( warning => "10:25", critical => "~:25" ); | ||
| 60 | # Critical if outside -INF to 25, ie > 25. Warn if outside 10-25, ie < 10 | ||
| 61 | 114 | ||
| 62 | # ... collect current metric into $value | 115 | =head1 SYNOPSIS |
| 63 | if ($trouble_getting_metric) { | ||
| 64 | $p->die( return_code => $ERRORS{UNKNOWN}, message => "Could not retrieve page"); | ||
| 65 | # Output: PAGESIZE UNKNOWN Could not retrieve page | ||
| 66 | # Return code: 3 | ||
| 67 | } | ||
| 68 | 116 | ||
| 69 | $p->add_perfdata( label => "size", | 117 | # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default |
| 70 | value => $value, | 118 | # See also Nagios::Plugin::Functions for a functional interface |
| 71 | uom => "kB", | 119 | use Nagios::Plugin; |
| 72 | threshold => $threshold, | 120 | |
| 121 | # Constructor | ||
| 122 | $np = Nagios::Plugin->new; # OR | ||
| 123 | $np = Nagios::Plugin->new( shortname => "PAGESIZE" ); | ||
| 124 | |||
| 125 | # Exit methods - nagios_exit( CODE, MESSAGE ), nagios_die( MESSAGE, [CODE]) | ||
| 126 | $page = retrieve_page($page1) | ||
| 127 | or $np->nagios_exit( UNKNOWN, "Could not retrieve page" ); | ||
| 128 | # Return code: 3; output: PAGESIZE UNKNOWN - Could not retrieve page | ||
| 129 | test_page($page) | ||
| 130 | or $np->nagios_exit( CRITICAL, "Bad page found" ); | ||
| 131 | |||
| 132 | # nagios_die() is just like nagios_exit(), but return code defaults to UNKNOWN | ||
| 133 | $page = retrieve_page($page2) | ||
| 134 | or $np->nagios_die( "Could not retrieve page" ); | ||
| 135 | # Return code: 3; output: PAGESIZE UNKNOWN - Could not retrieve page | ||
| 136 | |||
| 137 | # Threshold methods (NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold for now) | ||
| 138 | $code = $np->check_threshold( | ||
| 139 | check => $value, | ||
| 140 | warning => $warning_threshold, | ||
| 141 | critical => $critical_threshold, | ||
| 142 | ); | ||
| 143 | $np->nagios_exit( $code, "Threshold check failed" ) if $code != OK; | ||
| 144 | |||
| 145 | # Message methods (EXPERIMENTAL AND SUBJECT TO CHANGE) - | ||
| 146 | # add_message( CODE, $message ); check_messages() | ||
| 147 | for (@collection) { | ||
| 148 | if (m/Error/) { | ||
| 149 | $np->add_message( CRITICAL, $_ ); | ||
| 150 | } else { | ||
| 151 | $np->add_message( OK, $_ ); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | ($code, $message) = $np->check_message(); | ||
| 155 | nagios_exit( $code, $message ); | ||
| 156 | # If any items in collection matched m/Error/, returns CRITICAL and the joined | ||
| 157 | # set of Error messages; otherwise returns OK and the joined set of ok messages | ||
| 158 | |||
| 159 | # Perfdata methods | ||
| 160 | $np->add_perfdata( | ||
| 161 | label => "size", | ||
| 162 | value => $value, | ||
| 163 | uom => "kB", | ||
| 164 | threshold => $threshold, | ||
| 73 | ); | 165 | ); |
| 74 | $p->add_perfdata( label => "time", ... ); | 166 | $np->add_perfdata( label => "time", ... ); |
| 167 | $np->nagios_exit( OK, "page size at http://... was ${value}kB" ); | ||
| 168 | # Return code: 0; output: | ||
| 169 | # PAGESIZE OK - page size at http://... was 36kB | size=36kB;10:25;25: time=... | ||
| 170 | |||
| 171 | # Option handling methods (NOT YET IMPLEMENTED - use Nagios::Plugin::Getopt for now) | ||
| 172 | |||
| 75 | 173 | ||
| 76 | $p->die( return_code => $threshold->get_status($value), message => "page size at http://... was ${value}kB" ); | ||
| 77 | # Output: PAGESIZE OK: page size at http://... was 36kB | size=36kB;10:25;25: time=... | ||
| 78 | # Return code: 0 | ||
| 79 | 174 | ||
| 80 | =head1 DESCRIPTION | 175 | =head1 DESCRIPTION |
| 81 | 176 | ||
| 82 | This is the place for common routines when writing Nagios plugins. The idea is to make it as | 177 | Nagios::Plugin and its associated Nagios::Plugin::* modules are a family of perl modules |
| 83 | easy as possible for developers to conform to the plugin guidelines | 178 | to streamline writing Nagios plugins. The main end user modules are Nagios::Plugin, |
| 179 | providing an object-oriented interface to the entire Nagios::Plugin::* collection, and | ||
| 180 | Nagios::Plugin::Functions, providing a simpler functional interface to a useful subset of | ||
| 181 | the available functionality. | ||
| 182 | |||
| 183 | The purpose of the collection is to make it as simple as possible for developers to | ||
| 184 | create plugins that conform the Nagios Plugin guidelines | ||
| 84 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). | 185 | (http://nagiosplug.sourceforge.net/developer-guidelines.html). |
| 85 | 186 | ||
| 86 | =head1 EXAMPLE SCRIPT | ||
| 87 | 187 | ||
| 88 | "Enough talk! Show me where to start!" | 188 | =head2 EXPORTS |
| 89 | 189 | ||
| 90 | See the file 'check_stuff.pl' in the 't' directory for a complete working example of a plugin script. | 190 | Nagios status code constants are exported by default: |
| 91 | 191 | ||
| 92 | =head1 DESIGN | 192 | OK |
| 193 | WARNING | ||
| 194 | CRITICAL | ||
| 195 | UNKNOWN | ||
| 196 | DEPENDENT | ||
| 93 | 197 | ||
| 94 | To facilitate object oriented classes, there are multiple perl modules, each reflecting a type of data | 198 | The following variables are also exported on request: |
| 95 | (ie, thresholds, ranges, performance). However, a plugin developer does not need to know about the | ||
| 96 | different types - a "use Nagios::Plugin" should be sufficient. | ||
| 97 | 199 | ||
| 98 | There is a Nagios::Plugin::Export. This holds all internals variables. You can specify these variables | 200 | =over 4 |
| 99 | when use'ing Nagios::Plugin | ||
| 100 | 201 | ||
| 101 | use Nagios::Plugin qw(%ERRORS) | 202 | =item %ERRORS |
| 102 | print $ERRORS{WARNING} # prints 1 | ||
| 103 | 203 | ||
| 104 | =head1 VERSIONING | 204 | A hash mapping error strings ("CRITICAL", "UNKNOWN", etc.) to the corresponding |
| 205 | status code. | ||
| 105 | 206 | ||
| 106 | Only methods listed in the documentation for each module is public. | 207 | =item %STATUS_TEXT |
| 107 | 208 | ||
| 108 | These modules are experimental and so the interfaces may change up until Nagios::Plugin | 209 | A hash mapping status code constants (OK, WARNING, CRITICAL, etc.) to the |
| 109 | hits version 1.0, but every attempt will be made to make backwards compatible. | 210 | corresponding error string ("OK", "WARNING, "CRITICAL", etc.) i.e. the reverse |
| 211 | of %ERRORS. | ||
| 110 | 212 | ||
| 111 | =head1 STARTING | 213 | =back |
| 214 | |||
| 215 | |||
| 216 | =head2 CONSTRUCTOR | ||
| 217 | |||
| 218 | Nagios::Plugin->new; | ||
| 219 | |||
| 220 | Nagios::Plugin->new( shortname => 'PAGESIZE' ); | ||
| 221 | |||
| 222 | Instantiates a new Nagios::Plugin object. Accepts the following named arguments: | ||
| 112 | 223 | ||
| 113 | =over 4 | 224 | =over 4 |
| 114 | 225 | ||
| 115 | =item use Nagios::Plugin qw(%ERRORS) | 226 | =item shortname |
| 116 | 227 | ||
| 117 | Imports the %ERRORS hash. This is currently the only symbol that can be imported. | 228 | The 'shortname' for this plugin, used as the first token in the plugin output |
| 229 | by the various exit methods. Default: uc basename $0. | ||
| 118 | 230 | ||
| 119 | =back | 231 | =back |
| 120 | 232 | ||
| 121 | =head1 CLASS METHODS | 233 | |
| 234 | =head2 EXIT METHODS | ||
| 122 | 235 | ||
| 123 | =over 4 | 236 | =over 4 |
| 124 | 237 | ||
| 125 | =item Nagios::Plugin->new( shortname => $$ ) | 238 | =item nagios_exit( <CODE>, $message ) |
| 239 | |||
| 240 | Exit with return code CODE, and a standard nagios message of the | ||
| 241 | form "SHORTNAME CODE - $message". | ||
| 242 | |||
| 243 | =item nagios_die( $message, [<CODE>] ) | ||
| 244 | |||
| 245 | Same as nagios_exit(), except that CODE is optional, defaulting | ||
| 246 | to UNKNOWN. | ||
| 247 | |||
| 248 | =item die( $message, [<CODE>] ) | ||
| 249 | |||
| 250 | Alias for nagios_die(). Deprecated. | ||
| 126 | 251 | ||
| 127 | Initializes a new Nagios::Plugin object. Can specify the shortname here. | 252 | =back |
| 253 | |||
| 254 | |||
| 255 | =head2 THRESHOLD METHODS | ||
| 256 | |||
| 257 | NOT YET IMPLEMENTED - use Nagios::Plugin::Threshold directly for now. | ||
| 258 | |||
| 259 | =over 4 | ||
| 260 | |||
| 261 | =item check_threshold( check => $value, warning => $warn, critical => $crit ) | ||
| 128 | 262 | ||
| 129 | =back | 263 | =back |
| 130 | 264 | ||
| 131 | =head1 OBJECT METHODS | 265 | |
| 266 | =head2 MESSAGE METHODS | ||
| 267 | |||
| 268 | EXPERIMENTAL AND SUBJECT TO CHANGE | ||
| 269 | |||
| 270 | 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 | ||
| 272 | result message. | ||
| 132 | 273 | ||
| 133 | =over 4 | 274 | =over 4 |
| 134 | 275 | ||
| 135 | =item set_thresholds( warning => "10:25", critical => "~:25" ) | 276 | =item add_message( <CODE>, $message ) |
| 136 | 277 | ||
| 137 | Sets the thresholds, based on the range specification at | 278 | Add a message with CODE status to the object. May be called multiple times. The messages |
| 138 | http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT. | 279 | added are checked by check_messages, following. |
| 139 | Returns a Nagios::Plugin::Threshold object, which can be used to input a value to see which threshold | 280 | |
| 140 | is crossed. | 281 | Only CRITICAL, WARNING, and OK are accepted as valid codes. |
| 141 | 282 | ||
| 142 | =item add_perfdata( label => "size", value => $value, uom => "kB", threshold => $threshold ) | ||
| 143 | 283 | ||
| 144 | Adds to an array a Nagios::Plugin::Performance object with the specified values. | 284 | =item check_messages() |
| 145 | 285 | ||
| 146 | This needs to be done separately to allow multiple perfdata output. | 286 | Check the current set of messages and return an appropriate nagios return code and/or a |
| 287 | result message. In scalar context, returns only a return code; in list context returns | ||
| 288 | both a return code and an output message, suitable for passing directly to nagios_exit() | ||
| 289 | e.g. | ||
| 147 | 290 | ||
| 148 | =item die( return_code => $ERRORS{CRITICAL}, message => "Output" ) | 291 | $code = $np->check_messages; |
| 292 | ($code, $message) = $np->check_messages; | ||
| 149 | 293 | ||
| 150 | Exits the plugin and prints to STDOUT a Nagios plugin compatible output. Exits with the specified | 294 | check_messages returns CRITICAL if any critical messages are found, WARNING if any |
| 151 | return code. Also prints performance data if any have been added in. | 295 | warning messages are found, and OK otherwise. The message returned in list context defaults |
| 296 | to the joined set of error messages; this may be customised using the arguments below. | ||
| 297 | |||
| 298 | check_messages accepts the following named arguments (none are required): | ||
| 299 | |||
| 300 | =over 4 | ||
| 301 | |||
| 302 | =item join => SCALAR | ||
| 303 | |||
| 304 | A string used to join the relevant array to generate the message | ||
| 305 | string returned in list context i.e. if the 'critical' array @crit | ||
| 306 | is non-empty, check_messages would return: | ||
| 307 | |||
| 308 | join( $join, @crit ) | ||
| 309 | |||
| 310 | as the result message. Default: ' ' (space). | ||
| 311 | |||
| 312 | =item join_all => SCALAR | ||
| 313 | |||
| 314 | By default, only one set of messages are joined and returned in the | ||
| 315 | result message i.e. if the result is CRITICAL, only the 'critical' | ||
| 316 | messages are included in the result; if WARNING, only the 'warning' | ||
| 317 | messages are included; if OK, the 'ok' messages are included (if | ||
| 318 | supplied) i.e. the default is to return an 'errors-only' type | ||
| 319 | message. | ||
| 320 | |||
| 321 | If join_all is supplied, however, it will be used as a string to | ||
| 322 | join the resultant critical, warning, and ok messages together i.e. | ||
| 323 | all messages are joined and returned. | ||
| 324 | |||
| 325 | =item critical => ARRAYREF | ||
| 326 | |||
| 327 | Additional critical messages to supplement any passed in via add_message(). | ||
| 328 | |||
| 329 | =item warning => ARRAYREF | ||
| 330 | |||
| 331 | Additional warning messages to supplement any passed in via add_message(). | ||
| 332 | |||
| 333 | =item ok => ARRAYREF | SCALAR | ||
| 334 | |||
| 335 | Additional ok messages to supplement any passed in via add_message(). | ||
| 336 | |||
| 337 | =back | ||
| 152 | 338 | ||
| 153 | =back | 339 | =back |
| 154 | 340 | ||
| 341 | |||
| 342 | =head2 PERFORMANCE DATA METHODS | ||
| 343 | |||
| 344 | =over 4 | ||
| 345 | |||
| 346 | =item add_perfdata( label => "size", value => $value, uom => "kB", threshold => $threshold ) | ||
| 347 | |||
| 348 | Add a set of performance data to the object. May be called multiple times. The performance | ||
| 349 | data is included in the standard plugin output messages by the various exit methods. | ||
| 350 | |||
| 351 | See the Nagios::Plugin::Performance documentation for more information on performance data | ||
| 352 | and the various field definitions, as well as the relevant section of the Nagios Plugin | ||
| 353 | guidelines (http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN202). | ||
| 354 | |||
| 355 | =back | ||
| 356 | |||
| 357 | |||
| 358 | =head2 OPTION HANDLING METHODS | ||
| 359 | |||
| 360 | NOT YET IMPLEMENTED - use Nagios::Plugin::Getopt directly for now. | ||
| 361 | |||
| 362 | |||
| 363 | =head1 EXAMPLES | ||
| 364 | |||
| 365 | "Enough talk! Show me some examples!" | ||
| 366 | |||
| 367 | See the file 'check_stuff.pl' in the 't' directory for a complete working example of a | ||
| 368 | plugin script. | ||
| 369 | |||
| 370 | |||
| 371 | =head1 VERSIONING | ||
| 372 | |||
| 373 | The Nagios::Plugin::* modules are currently experimental and so the interfaces may | ||
| 374 | change up until Nagios::Plugin hits version 1.0, although every attempt will be made to | ||
| 375 | keep them as backwards compatible as possible. | ||
| 376 | |||
| 377 | |||
| 155 | =head1 SEE ALSO | 378 | =head1 SEE ALSO |
| 156 | 379 | ||
| 157 | http://nagiosplug.sourceforge.net | 380 | See Nagios::Plugin::Functions for a simple functional interface to a subset |
| 381 | of the available Nagios::Plugin functionality. | ||
| 382 | |||
| 383 | See also Nagios::Plugin::Getopt, Nagios::Plugin::Range, Nagios::Plugin::Performance, | ||
| 384 | Nagios::Plugin::Range, and Nagios::Plugin::Threshold. | ||
| 385 | |||
| 386 | The Nagios Plugin project page is at http://nagiosplug.sourceforge.net. | ||
| 387 | |||
| 388 | |||
| 389 | =head1 BUGS | ||
| 390 | |||
| 391 | Please report bugs in these modules to the Nagios Plugin development team: | ||
| 392 | nagiosplug-devel@lists.sourceforge.net. | ||
| 393 | |||
| 158 | 394 | ||
| 159 | =head1 AUTHOR | 395 | =head1 AUTHOR |
| 160 | 396 | ||
| 161 | Maintained by the Nagios Plugin development team - http://nagiosplug.sourceforge.net | 397 | Maintained by the Nagios Plugin development team - http://nagiosplug.sourceforge.net. |
| 162 | 398 | ||
| 163 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt> | 399 | Originally by Ton Voon, E<lt>ton.voon@altinity.comE<gt>. |
| 164 | 400 | ||
| 165 | Nathan Vonnahme added extra tests and subsequent fixes. | 401 | Nathan Vonnahme added extra tests and subsequent fixes. |
| 166 | 402 | ||
| 167 | Gavin Carr contributed the Nagios::Plugin::GetOpt module. | 403 | |
| 168 | 404 | ||
| 169 | =head1 COPYRIGHT AND LICENSE | 405 | =head1 COPYRIGHT AND LICENSE |
| 170 | 406 | ||
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 9c20288..e77bc4f 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
| @@ -14,7 +14,7 @@ our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | |||
| 14 | require Exporter; | 14 | require Exporter; |
| 15 | our @ISA = qw(Exporter); | 15 | our @ISA = qw(Exporter); |
| 16 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); | 16 | our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); |
| 17 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT); | 17 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES); |
| 18 | our %EXPORT_TAGS = ( | 18 | our %EXPORT_TAGS = ( |
| 19 | all => [ @EXPORT, @EXPORT_OK ], | 19 | all => [ @EXPORT, @EXPORT_OK ], |
| 20 | codes => [ @STATUS_CODES ], | 20 | codes => [ @STATUS_CODES ], |
| @@ -28,7 +28,7 @@ use constant UNKNOWN => 3; | |||
| 28 | use constant DEPENDENT => 4; | 28 | use constant DEPENDENT => 4; |
| 29 | 29 | ||
| 30 | our %ERRORS = ( | 30 | our %ERRORS = ( |
| 31 | 'OK' => OK, | 31 | 'OK' => OK, |
| 32 | 'WARNING' => WARNING, | 32 | 'WARNING' => WARNING, |
| 33 | 'CRITICAL' => CRITICAL, | 33 | 'CRITICAL' => CRITICAL, |
| 34 | 'UNKNOWN' => UNKNOWN, | 34 | 'UNKNOWN' => UNKNOWN, |
| @@ -84,7 +84,8 @@ sub nagios_exit { | |||
| 84 | $output = "$shortname $output" if $shortname; | 84 | $output = "$shortname $output" if $shortname; |
| 85 | if ($arg->{plugin}) { | 85 | if ($arg->{plugin}) { |
| 86 | my $plugin = $arg->{plugin}; | 86 | my $plugin = $arg->{plugin}; |
| 87 | $output .= " | ". $plugin->all_perfoutput if $plugin->perfdata; | 87 | $output .= " | ". $plugin->all_perfoutput |
| 88 | if $plugin->perfdata && $plugin->all_perfoutput; | ||
| 88 | } | 89 | } |
| 89 | $output .= "\n"; | 90 | $output .= "\n"; |
| 90 | 91 | ||
| @@ -193,7 +194,7 @@ Nagios plugins. | |||
| 193 | # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default | 194 | # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default |
| 194 | use Nagios::Plugin::Functions; | 195 | use Nagios::Plugin::Functions; |
| 195 | 196 | ||
| 196 | # nagios_exit( ODE, $message ) - exit with error code CODE, | 197 | # nagios_exit( CODE, $message ) - exit with error code CODE, |
| 197 | # and message "PLUGIN CODE - $message" | 198 | # and message "PLUGIN CODE - $message" |
| 198 | nagios_exit( CRITICAL, $critical_error ) if $critical_error; | 199 | nagios_exit( CRITICAL, $critical_error ) if $critical_error; |
| 199 | nagios_exit( WARNING, $warning_error ) if $warning_error; | 200 | nagios_exit( WARNING, $warning_error ) if $warning_error; |
| @@ -223,7 +224,7 @@ Nagios::Plugin. It is intended for those who prefer a simpler | |||
| 223 | functional interface, and who do not need the additional | 224 | functional interface, and who do not need the additional |
| 224 | functionality of Nagios::Plugin. | 225 | functionality of Nagios::Plugin. |
| 225 | 226 | ||
| 226 | =head2 Exports | 227 | =head2 EXPORTS |
| 227 | 228 | ||
| 228 | Nagios status code constants are exported by default: | 229 | Nagios status code constants are exported by default: |
| 229 | 230 | ||
| @@ -245,13 +246,13 @@ The following variables are exported only on request: | |||
| 245 | %STATUS_TEXT | 246 | %STATUS_TEXT |
| 246 | 247 | ||
| 247 | 248 | ||
| 248 | =head2 Functions | 249 | =head2 FUNCTIONS |
| 249 | 250 | ||
| 250 | The following functions are supported: | 251 | The following functions are supported: |
| 251 | 252 | ||
| 252 | =over 4 | 253 | =over 4 |
| 253 | 254 | ||
| 254 | =item nagios_exit( CODE, $message ) | 255 | =item nagios_exit( <CODE>, $message ) |
| 255 | 256 | ||
| 256 | Exit with return code CODE, and a standard nagios message of the | 257 | Exit with return code CODE, and a standard nagios message of the |
| 257 | form "PLUGIN CODE - $message". | 258 | form "PLUGIN CODE - $message". |
