diff --git a/lib/Resmon/Config.pm b/lib/Resmon/Config.pm index a15f323ae8ff82b03511f6a56cde8fef7a776e18..9798da9b01d9fc5cafc57748acd0fb92b53ea9a2 100755 --- a/lib/Resmon/Config.pm +++ b/lib/Resmon/Config.pm @@ -25,6 +25,19 @@ sub new { grep { $kvs{$1} = $2 if /^\s*(\S+)\s*=>\s*(\S+)\s*$/ } @params; my $object = bless \%kvs, "Resmon::Module::$current"; push(@{$self->{Module}->{$current}}, $object); + + # Test to make sure the module actually works + my $coderef; + eval { $coderef = Resmon::Module::fetch_monitor($current); }; + if (!$coderef) { + # Try to execute the config_as_hash method. If it fails, then + # the module didn't load properly (e.g. syntax error). + eval { $object->config_as_hash; }; + die "Problem loading module $current" if $@; + } else { + print STDERR "moo"; + } + } elsif (/^\s*\}\s*$/) { $current = undef; } else { diff --git a/resmon b/resmon index 4d9b50a6bd91e7073071f6c6c254135e4728cd25..c8f9244423d4f7b269acbe76091afbe938b03558 100755 --- a/resmon +++ b/resmon @@ -36,7 +36,17 @@ sub configure { $config->{interface} = $interface if($interface); } -$SIG{'HUP'} = \&configure; +sub reconfigure { + print STDERR "Reloading...\n"; + eval { configure(); }; + if ($@) { + print STDERR " Failed to reload: "; + print STDERR $@; + print STDERR " Continuing with old configuration\n"; + } +} + +$SIG{'HUP'} = \&reconfigure; configure(); my $sigint = 0; @@ -81,13 +91,14 @@ while(1) { } else { eval { ($check_rv, $check_mess) = $monobj->handler(); }; } + my $checkstat = $@; my $results = { configuration => eval { $monobj->config_as_hash(); }, last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)), }; - if($@) { + if($checkstat) { $results->{state} = 'BAD'; - $results->{message} = $@; + $results->{message} = $checkstat; } else { $results->{state} = $check_rv; $results->{message} = $check_mess;