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

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 2156
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2156&view=rev
Author:   dermoth
Date:     2009-02-24 10:18:27 +0000 (Tue, 24 Feb 2009)

Log Message:
-----------
Die as UNKNOWN instead of CRITICAL when default file is not found

(NB: shall we should die at all?)

From: Thomas Guyot-Sionnest <[email protected]>

Modified Paths:
--------------
    Nagios-Plugin/trunk/lib/Nagios/Plugin/Config.pm
    Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm

Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Config.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Config.pm	2009-02-24 10:18:14 UTC (rev 2155)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Config.pm	2009-02-24 10:18:27 UTC (rev 2156)
@@ -38,7 +38,8 @@
                        }
                 }
 
-                croak "Cannot find '$FILENAME1' or '$FILENAME2' in any standard location." unless $_[0];
+                # Use die instead of croak, so we can pass a clean message downstream
+                die "Cannot find '$FILENAME1' or '$FILENAME2' in any standard location.\n" unless $_[0];
         }
 
         $class->SUPER::read( @_ );

Modified: Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm
===================================================================
--- Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm	2009-02-24 10:18:14 UTC (rev 2155)
+++ Nagios-Plugin/trunk/lib/Nagios/Plugin/Getopt.pm	2009-02-24 10:18:27 UTC (rev 2156)
@@ -242,9 +242,13 @@
   my ($section, $file, $flags) = @_;
   $section ||= $self->{_attr}->{plugin};
 
-  my $Config = Nagios::Plugin::Config->read($file);
+  my $Config;
+  eval { $Config = Nagios::Plugin::Config->read($file); };
+  $self->_die($@) if ($@); #TODO: add test?
 
   # TODO: is this check sane? Does --extra-opts=foo require a [foo] section?
+  ## Nevertheless, if we die as UNKNOWN here we should do the same on default
+  ## file *added eval/_die above*.
   $self->_die("Invalid section '$section' in config file '$file'")
     unless exists $Config->{$section};
 


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

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
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.