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

Added a purge method to status that will remove any status information for

modules that are no longer loaded (due to them being removed from the config
file and resmon being reloaded). This required $status to become global so it
was accessible from the reload_modules command.


git-svn-id: https://labs.omniti.com/resmon/trunk@109 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 7b9e8bc8
No related branches found
No related tags found
No related merge requests found
......@@ -404,6 +404,42 @@ sub store {
print "$name($type) :: $info->{state}($info->{message})\n";
}
}
sub purge {
# This removes status information for modules that are no longer loaded
# Generate list of current modules
my %loaded = ();
my ($self, $config) = @_;
while (my ($type, $mods) = each(%{$config->{Module}}) ) {
$loaded{$type} = ();
foreach (@$mods) {
$loaded{$type}{$_->{'object'}} = 1;
}
}
# Debugging
#while (my ($key, $value) = each(%loaded) ) {
# print STDERR "$key: ";
# while (my ($mod, $dummy) = each (%$value) ) {
# print STDERR "$mod ";
# }
# print "\n";
#}
# Compare $self->{store} with list of loaded modules
while (my ($type, $value) = each (%{$self->{store}})) {
while (my ($name, $value2) = each (%$value)) {
if (!exists($loaded{$type}) || !exists($loaded{$type}{$name})) {
print STDERR "$type $name\n";
delete $self->{store}->{$type}->{$name};
if (scalar(keys %{$self->{store}->{$type}}) == 0) {
print STDERR "$type has no more objects, deleting\n";
delete $self->{store}->{$type};
}
}
}
}
}
sub close {
my $self = shift;
return if($self->{handle_is_stdout});
......
......@@ -11,7 +11,7 @@ use Time::HiRes qw( gettimeofday tv_interval sleep );
use POSIX qw( setsid );
use Getopt::Long;
use Data::Dumper;
use vars qw($config_file $debug $status_file $interface $port $config);
use vars qw($config_file $debug $status_file $interface $port $config $status);
use Resmon::Config;
use Resmon::ExtComm;
......@@ -67,6 +67,7 @@ sub reconfigure {
}
$config->{'modstatus'} = $modstatus;
$status->purge($config);
}
$SIG{'HUP'} = \&reconfigure;
......@@ -96,7 +97,7 @@ unless($debug) {
}
my $list = [];
my $status = Resmon::Status->new($config->{statusfile});
$status = Resmon::Status->new($config->{statusfile});
$status->open();
$status->serve_http_on($config->{interface}, $config->{port})
if($config->{port});
......
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