SF.net SVN: nagiosplug:[2082] Nagios-Plugin/trunk

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 2082
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2082&view=rev
Author:   dermoth
Date:     2008-11-19 03:58:09 +0000 (Wed, 19 Nov 2008)

Log Message:
-----------
Add max_state_* interface warper to Nagios::Plugin object

Modified Paths:
--------------
    Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
    Nagios-Plugin/trunk/lib/Nagios/Plugin.pm

Added Paths:
-----------
    Nagios-Plugin/trunk/t/Nagios-Plugin-Functions-04.t

Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm	2008-11-14 20:38:26 UTC (rev 2081)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Functions.pm	2008-11-19 03:58:09 UTC (rev 2082)
@@ -19,11 +19,11 @@
 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 max_state convert $value_re);
+our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname max_state max_state_alt convert $value_re);
 our %EXPORT_TAGS = (
     all => [ @EXPORT, @EXPORT_OK ],
     codes => [ @STATUS_CODES ],
-    functions => [ qw(nagios_exit nagios_die check_messages max_state convert) ],
+    functions => [ qw(nagios_exit nagios_die check_messages max_state max_state_alt convert) ],
 );
 
 use constant OK         => 0;
@@ -73,6 +73,15 @@
 	return UNKNOWN;
 }
 
+sub max_state_alt {
+        return CRITICAL if grep { $_ == CRITICAL } @_;
+        return WARNING if grep { $_ == WARNING } @_;
+        return UNKNOWN if grep { $_ == UNKNOWN } @_;
+        return DEPENDENT if grep { $_ == DEPENDENT } @_;
+        return OK if grep { $_ == OK } @_;
+        return UNKNOWN;
+}
+
 # nagios_exit( $code, $message )
 sub nagios_exit {
     my ($code, $message, $arg) = @_;
@@ -303,6 +312,7 @@
     %STATUS_TEXT
     get_shortname
     max_state
+    max_state_alt
 
 
 =head2 FUNCTIONS
@@ -395,6 +405,18 @@
 Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN,
 DEPENDENT
 
+The typical usage of max_state is to initialise the state as UNKNOWN and use
+it on the result of various test. If no test were performed successfully the
+state will still be UNKNOWN.
+
+=item max_state_alt(@a)
+
+Returns the worst state in the array. Order is: CRITICAL, WARNING, UNKNOWN,
+DEPENDENT, OK
+
+This is a true definition of a max state (OK last) and should be used if the
+internal tests performed can return UNKNOWN.
+
 =back
 
 =head1 SEE ALSO

Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin.pm	2008-11-14 20:38:26 UTC (rev 2081)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin.pm	2008-11-19 03:58:09 UTC (rev 2082)
@@ -99,6 +99,12 @@
     my $self = shift;
     Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self });
 }
+sub max_state {
+    Nagios::Plugin::Functions::max_state(@_);
+}
+sub max_state_alt {
+    Nagios::Plugin::Functions::max_state_alt(@_);
+}
 
 # Override default shortname accessor to add default
 sub shortname {
@@ -483,6 +489,11 @@
 
 Alias for nagios_die(). Deprecated.
 
+=item max_state, max_state_alt
+
+These are wrapper function for Nagios::Plugin::Functions::max_state and
+Nagios::Plugin::Functions::max_state_alt.
+
 =back
 
 =head2 THRESHOLD METHODS

Added: Nagios-Plugin/trunk/t/Nagios-Plugin-Functions-04.t
===================================================================
--- Nagios-Plugin/trunk/t/Nagios-Plugin-Functions-04.t	                        (rev 0)
+++ Nagios-Plugin/trunk/t/Nagios-Plugin-Functions-04.t	2008-11-19 03:58:09 UTC (rev 2082)
@@ -0,0 +1,21 @@
+# max_state_alt tests
+
+use strict;
+use Test::More tests => 8;
+
+BEGIN { use_ok("Nagios::Plugin::Functions", ":all") }
+
+my $new_state = max_state_alt( OK, WARNING );
+
+is( $new_state, WARNING, "Moved up to WARNING" );
+is( max_state_alt( $new_state, UNKNOWN ), WARNING, "Still at WARNING" );
+
+$new_state = max_state_alt( $new_state, CRITICAL );
+is( $new_state, CRITICAL, "Now at CRITICAL" );
+is( max_state_alt( OK, OK ), OK, "This is OK" );
+
+is( max_state_alt( OK, UNKNOWN ), UNKNOWN, "This is UNKNOWN" );
+
+is( max_state_alt( OK, OK, OK, OK, OK, WARNING ), WARNING, "Use WARNING in this list" );
+
+is( max_state_alt(), UNKNOWN, "Return UNKNOWN if no parameters" );


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.