From 9692fb72f6f428dbed4e107dd83fa906854babff Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Wed, 7 Feb 2007 17:35:38 +0000 Subject: Added max_state function git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1615 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin/Functions.pm | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 9983456..43f371c 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -18,11 +18,11 @@ our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT); require Exporter; our @ISA = qw(Exporter); our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); -our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname); +our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ], codes => [ @STATUS_CODES ], - functions => [ qw(nagios_exit nagios_die check_messages) ], + functions => [ qw(nagios_exit nagios_die check_messages max_state) ], ); use constant OK => 0; @@ -56,6 +56,15 @@ sub get_shortname { return $shortname; } +sub max_state { + return CRITICAL if grep { $_ == CRITICAL } @_; + return WARNING if grep { $_ == WARNING } @_; + return OK if grep { $_ == OK } @_; + return UNKNOWN if grep { $_ == UNKNOWN } @_; + return DEPENDENT if grep { $_ == DEPENDENT } @_; + return UNKNOWN; +} + # nagios_exit( $code, $message ) sub nagios_exit { my ($code, $message, $arg) = @_; @@ -197,7 +206,7 @@ __END__ =head1 NAME Nagios::Plugin::Functions - functions to simplify the creation of -Nagios plugins. +Nagios plugins =head1 SYNOPSIS @@ -259,6 +268,7 @@ The following variables and functions are exported only on request: %ERRORS %STATUS_TEXT get_shortname + max_state =head2 FUNCTIONS @@ -349,6 +359,12 @@ imported. =back +=item max_state(@a) + +Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN, +DEPENDENT + +=back =head1 SEE ALSO -- cgit v1.2.3-74-g34f1