diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-11-19 03:58:09 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-11-19 03:58:09 +0000 |
commit | 53d04242544a69e5fe226211bfb0186414941a9f (patch) | |
tree | c5334576ed7564c3db145dd9a7ab03e345da137a /lib/Nagios/Plugin/Functions.pm | |
parent | c47e1a9c28db2890f724ee57e59f3a3c30d7740c (diff) | |
download | monitoring-plugin-perl-53d04242544a69e5fe226211bfb0186414941a9f.tar.gz |
Add max_state_* interface warper to Nagios::Plugin object
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@2082 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin/Functions.pm')
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index a37cdaf..b44157c 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm | |||
@@ -19,11 +19,11 @@ our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); | |||
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(nagios_exit nagios_die check_messages)); |
22 | our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state 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 convert) ], | 26 | functions => [ qw(nagios_exit nagios_die check_messages max_state max_state_alt convert) ], |
27 | ); | 27 | ); |
28 | 28 | ||
29 | use constant OK => 0; | 29 | use constant OK => 0; |
@@ -73,6 +73,15 @@ sub max_state { | |||
73 | return UNKNOWN; | 73 | return UNKNOWN; |
74 | } | 74 | } |
75 | 75 | ||
76 | sub max_state_alt { | ||
77 | return CRITICAL if grep { $_ == CRITICAL } @_; | ||
78 | return WARNING if grep { $_ == WARNING } @_; | ||
79 | return UNKNOWN if grep { $_ == UNKNOWN } @_; | ||
80 | return DEPENDENT if grep { $_ == DEPENDENT } @_; | ||
81 | return OK if grep { $_ == OK } @_; | ||
82 | return UNKNOWN; | ||
83 | } | ||
84 | |||
76 | # nagios_exit( $code, $message ) | 85 | # nagios_exit( $code, $message ) |
77 | sub nagios_exit { | 86 | sub nagios_exit { |
78 | my ($code, $message, $arg) = @_; | 87 | my ($code, $message, $arg) = @_; |
@@ -303,6 +312,7 @@ The following variables and functions are exported only on request: | |||
303 | %STATUS_TEXT | 312 | %STATUS_TEXT |
304 | get_shortname | 313 | get_shortname |
305 | max_state | 314 | max_state |
315 | max_state_alt | ||
306 | 316 | ||
307 | 317 | ||
308 | =head2 FUNCTIONS | 318 | =head2 FUNCTIONS |
@@ -395,6 +405,18 @@ imported. | |||
395 | Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN, | 405 | Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN, |
396 | DEPENDENT | 406 | DEPENDENT |
397 | 407 | ||
408 | The typical usage of max_state is to initialise the state as UNKNOWN and use | ||
409 | it on the result of various test. If no test were performed successfully the | ||
410 | state will still be UNKNOWN. | ||
411 | |||
412 | =item max_state_alt(@a) | ||
413 | |||
414 | Returns the worst state in the array. Order is: CRITICAL, WARNING, UNKNOWN, | ||
415 | DEPENDENT, OK | ||
416 | |||
417 | This is a true definition of a max state (OK last) and should be used if the | ||
418 | internal tests performed can return UNKNOWN. | ||
419 | |||
398 | =back | 420 | =back |
399 | 421 | ||
400 | =head1 SEE ALSO | 422 | =head1 SEE ALSO |