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

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Tue Feb 24 11:18:27 CET 2009


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 <dermoth at aei.ca>

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.




More information about the Commits mailing list