Added support for server XML files.

This commit is contained in:
Ramon Novoa 2015-10-14 14:55:55 +02:00
parent 14fab9c05a
commit 86c900b196
3 changed files with 40 additions and 6 deletions

View File

@ -238,7 +238,7 @@ our @EXPORT = qw(
# Some global variables
our @DayNames = qw(sunday monday tuesday wednesday thursday friday saturday);
our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginserver predictionserver wmiserver exportserver inventoryserver webserver eventserver icmpserver snmpserver);
our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginserver predictionserver wmiserver exportserver inventoryserver webserver eventserver icmpserver snmpserver satelliteserver);
our @AlertStatus = ('Execute the alert', 'Do not execute the alert', 'Do not execute the alert, but increment its internal counter', 'Cease the alert', 'Recover the alert', 'Reset internal counter');
# Event storm protection (no alerts or events)
@ -2168,15 +2168,15 @@ Update server status:
=cut
##########################################################################
sub pandora_update_server ($$$$$$;$$) {
sub pandora_update_server ($$$$$$;$$$) {
my ($pa_config, $dbh, $server_name, $server_id, $status,
$server_type, $num_threads, $queue_size) = @_;
$server_type, $num_threads, $queue_size, $version) = @_;
$num_threads = 0 unless defined ($num_threads);
$queue_size = 0 unless defined ($queue_size);
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
my $version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'};
$version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'} unless defined($version);
# First run
if ($server_id == 0) {
@ -2193,8 +2193,10 @@ sub pandora_update_server ($$$$$$;$$) {
logger($pa_config, "Server '" . $pa_config->{'servername'} . "' not found.", 3);
return;
}
} else {
$server_id = $server->{'id_server'};
}
db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?
WHERE id_server = ?',
1, $timestamp, $pa_config->{'pandora_master'}, $timestamp, $version, $num_threads, $queue_size, $server_id);

View File

@ -206,7 +206,11 @@ sub data_consumer ($$) {
}
unlink ($file_name);
process_xml_data ($self->getConfig (), $file_name, $xml_data, $self->getServerID (), $self->getDBH ());
if (defined($xml_data->{'server_name'})) {
process_xml_server ($self->getConfig (), $file_name, $xml_data, $self->getDBH ());
} else {
process_xml_data ($self->getConfig (), $file_name, $xml_data, $self->getServerID (), $self->getDBH ());
}
$AgentSem->down ();
delete ($Agents{$agent_name});
$AgentSem->up ();
@ -764,5 +768,31 @@ sub update_module_configuration ($$$$) {
$module->{'module_interval'} = ($module_conf->{'module_interval'} eq '') ? $module->{'module_interval'} : $module_conf->{'module_interval'};
}
###############################################################################
# Process XML data coming from a server.
###############################################################################
sub process_xml_server ($$$$) {
my ($pa_config, $file_name, $data, $dbh) = @_;
my ($server_name, $server_type, $version, $threads, $modules) = ($data->{'server_name'}, $data->{'server_type'}, $data->{'version'}, $data->{'threads'}, $data->{'modules'});
# Unknown server!
if (! defined ($server_name) || $server_name eq '') {
logger($pa_config, "$file_name has data from an unnamed server", 3);
return;
}
logger($pa_config, "Processing XML from server: $server_name", 10);
# Set some default values
$server_type = SATELLITESERVER unless defined($server_type);
$modules = 0 unless defined($modules);
$threads = 0 unless defined($threads);
$version = '' unless defined($version);
# Update server information
pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version);
}
1;
__END__

View File

@ -56,6 +56,7 @@ our @EXPORT = qw(
EVENTSERVER
ICMPSERVER
SNMPSERVER
SATELLITESERVER
METACONSOLE_LICENSE
$DEVNULL
RECOVERED_ALERT
@ -109,6 +110,7 @@ use constant WEBSERVER => 9;
use constant EVENTSERVER => 10;
use constant ICMPSERVER => 11;
use constant SNMPSERVER => 12;
use constant SATELLITESERVER => 13;
# Value for a metaconsole license type
use constant METACONSOLE_LICENSE => 0x01;