Skip to content
Snippets Groups Projects
Commit 7b9e8bc8 authored by Mark Harrison's avatar Mark Harrison
Browse files

Several fixes:

    - Broken modules on startup will not cause resmon to quit, but will be
      added to the failed modules list and have a status shown as BAD.
    - Broken modules on startup will no longer break the XML (because there is
      no config_as_hash to generate the configuration from)
    - Reloading modules that were initially broken (either from startup or
      from adding them to the config file and reloading) now works correctly.


git-svn-id: https://labs.omniti.com/resmon/trunk@108 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 40149ad2
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ sub new { ...@@ -7,6 +7,7 @@ sub new {
my $filename = shift; my $filename = shift;
my $self = bless { my $self = bless {
configfile => $filename, configfile => $filename,
modstatus => ''
}, $class; }, $class;
open(CONF, "<$filename") || return undef; open(CONF, "<$filename") || return undef;
...@@ -30,10 +31,16 @@ sub new { ...@@ -30,10 +31,16 @@ sub new {
my $coderef; my $coderef;
eval { $coderef = Resmon::Module::fetch_monitor($current); }; eval { $coderef = Resmon::Module::fetch_monitor($current); };
if (!$coderef) { if (!$coderef) {
# Try to execute the config_as_hash method. If it fails, then # Try to execute the config_as_hash method. If it fails, then
# the module didn't load properly (e.g. syntax error). # the module didn't load properly (e.g. syntax error).
eval { $object->config_as_hash; }; eval { $object->config_as_hash; };
die "Problem loading module $current" if $@; if ($@) {
# Module failed to load, print error and add to failed
# modules list.
print STDERR "Problem loading module $current\n";
print STDERR "This module will not be available\n";
$self->{'modstatus'} .= "$current ";
}
} }
} elsif (/^\s*\}\s*$/) { } elsif (/^\s*\}\s*$/) {
......
...@@ -42,7 +42,10 @@ sub reconfigure { ...@@ -42,7 +42,10 @@ sub reconfigure {
my $modules = $config->{Module}; my $modules = $config->{Module};
while ( my ($key, $value) = each(%$modules) ) { while ( my ($key, $value) = each(%$modules) ) {
my $mod = $value->[0]; # Only need the first of each module my $mod = $value->[0]; # Only need the first of each module
my $errs = $mod->reload_module(); # Called this way rather than $mod->reload_module() in order to deal
# with modules that failed to load on startup and won't have a
# reload_module method.
my $errs = Resmon::Module::reload_module($mod);
if ($errs) { if ($errs) {
my $modname = ref($mod) || $mod; my $modname = ref($mod) || $mod;
$modname =~ s/Resmon::Module:://; $modname =~ s/Resmon::Module:://;
...@@ -112,8 +115,10 @@ while(1) { ...@@ -112,8 +115,10 @@ while(1) {
eval { ($check_rv, $check_mess) = $monobj->handler(); }; eval { ($check_rv, $check_mess) = $monobj->handler(); };
} }
my $checkstat = $@; my $checkstat = $@;
my $confighash = {};
eval { $confighash = $monobj->config_as_hash(); };
my $results = { my $results = {
configuration => eval { $monobj->config_as_hash(); }, configuration => $confighash,
last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)), last_runtime_seconds => sprintf("%.6f", tv_interval($starttime)),
}; };
if($checkstat) { if($checkstat) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment