From c4f93de55930896e83d3abb519190704332b4e8f Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Thu, 22 Jan 2009 01:37:10 -0500 Subject: Die as UNKNOWN instead of CRITICAL when default file is not found (NB: shall we should die at all?) diff --git a/lib/Nagios/Plugin/Config.pm b/lib/Nagios/Plugin/Config.pm index d565973..11128dd 100644 --- a/lib/Nagios/Plugin/Config.pm +++ b/lib/Nagios/Plugin/Config.pm @@ -38,7 +38,8 @@ sub read } } - 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( @_ ); diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Nagios/Plugin/Getopt.pm index b21dc6d..0cf8f73 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Nagios/Plugin/Getopt.pm @@ -242,9 +242,13 @@ sub _load_config_section 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}; -- cgit v0.10-9-g596f