2012-12-13 Sergio Martin <sergio.martin@artica.es>

* conf/pandora_server.conf
	lib/PandoraFMS/Config.pm
	lib/PandoraFMS/DB.pm
	lib/PandoraFMS/Core.pm
	bin/pandora_server: Added new thread to the
	event replication process (enterprise feature) 
	and control this one and the policy queue patrol 
	process with new two configuration parameters



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7278 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-12-13 17:07:23 +00:00
parent c82191167c
commit 53162b4e9a
6 changed files with 150 additions and 4 deletions

View File

@ -1,3 +1,14 @@
2012-12-13 Sergio Martin <sergio.martin@artica.es>
* conf/pandora_server.conf
lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm
lib/PandoraFMS/Core.pm
bin/pandora_server: Added new thread to the
event replication process (enterprise feature)
and control this one and the policy queue patrol
process with new two configuration parameters
2012-12-10 Sancho Lerena <slerena@artica.es>
* Core.pm: Applied patch 3576115 from Axel: implemented maintance

View File

@ -259,9 +259,16 @@ if ($Config{'daemon'} == 1) {
pandora_daemonize (\%Config);
}
# Start thread to patrol policy queue
if (enterprise_load (\%Config) != 0 && $Config{'pandora_master'} == 1) {
my $thr = threads->create('pandora_process_policy_queue', (\%Config));
if (enterprise_load (\%Config) != 0) {
if($Config{'policy_manager'} == 1) {
# Start thread to patrol policy queue
my $thr_policy_queue = threads->create('pandora_process_policy_queue', (\%Config));
}
if($Config{'event_replication'} == 1) {
# Start thread to process event replication
my $thr_event_replication = threads->create('pandora_process_event_replication', (\%Config));
}
}
# Start the servers

View File

@ -355,3 +355,10 @@ netflow_basedir /tmp
# WARNING: Incremental modules will not work properly if dataserver_lifo is set to 1!!!
dataserver_lifo 0
# If set to 1, the policy manager is enabled and the server is listening the policy queue.
# 0 by default (PANDORA FMS ENTERPRISE ONLY)
policy_manager 1
# If set to 1, the event replicate process is enabled. 0 by default. (PANDORA FMS ENTERPRISE ONLY)
# WARNING: This process doesn't do anything if is not properly configured from the console setup
event_replication 1

View File

@ -281,6 +281,12 @@ sub pandora_load_config {
# Process XML data files as a stack
$pa_config->{"dataserver_lifo"} = 0; # 5.0
# Patrol process of policies queue
$pa_config->{"policy_manager"} = 0; # 5.0
# Event replication process
$pa_config->{"event_replication"} = 0; # 5.0
# -------------------------------------------------------------------------
# This values are not stored in .conf files.
# This values should be stored in database, not in .conf files!
@ -621,6 +627,12 @@ sub pandora_load_config {
elsif ($parametro =~ m/^dataserver_lifo\s+([0-1])/i) {
$pa_config->{'dataserver_lifo'}= clean_blank($1);
}
elsif ($parametro =~ m/^policy_manager\s+([0-1])/i) {
$pa_config->{'policy_manager'}= clean_blank($1);
}
elsif ($parametro =~ m/^event_replication\s+([0-1])/i) {
$pa_config->{'event_replication'}= clean_blank($1);
}
} # end of loop for parameter #
# Set to RDBMS' standard port

View File

@ -154,6 +154,7 @@ our @EXPORT = qw(
pandora_exec_forced_alerts
pandora_generate_alerts
pandora_generate_compound_alerts
pandora_get_config_value
pandora_get_module_tags
pandora_module_keep_alive
pandora_module_keep_alive_nd
@ -172,11 +173,13 @@ our @EXPORT = qw(
pandora_planned_downtime_weekly_start
pandora_planned_downtime_weekly_stop
pandora_process_alert
pandora_process_event_replication
pandora_process_module
pandora_reset_server
pandora_server_keep_alive
pandora_update_agent
pandora_update_agent_address
pandora_update_config_token
pandora_update_module_on_error
pandora_update_module_from_hash
pandora_update_server
@ -774,7 +777,6 @@ sub pandora_execute_alert ($$$$$$$$;$) {
# Generate an event
#If we've spotted an alert recovered, we set the new event's severity to 0, otherwise the original value is maintained.
my $severity;
my ($text, $event, $severity) = ($alert_mode == 0) ? ('recovered', 'alert_recovered', 0) : ('fired', 'alert_fired', $alert->{'priority'});
@ -2257,6 +2259,36 @@ sub pandora_create_group ($$$$$$$$$) {
return $group_id;
}
##########################################################################
## Create or update a token of tconfig table
##########################################################################
sub pandora_update_config_token ($$$) {
my ($dbh, $token, $value) = @_;
my $config_value = pandora_get_config_value($dbh, $token);
my $result = undef;
if($config_value ne '') {
$result = db_update ($dbh, 'UPDATE tconfig SET value = ? WHERE token = ?', $value, $token);
}
else {
$result = db_insert ($dbh, 'id_config', 'INSERT INTO tconfig (token, value) VALUES (?, ?)', $token, $value);
}
return $result;
}
##########################################################################
## Get value of a token of tconfig table
##########################################################################
sub pandora_get_config_value ($$) {
my ($dbh, $token) = @_;
my $config_value = get_db_value($dbh, 'SELECT value FROM tconfig WHERE token = ?',$token);
return (defined ($config_value) ? $config_value : "");
}
##########################################################################
=head2 C<< pandora_create_agent (I<$pa_config>, I<$server_name>, I<$agent_name>, I<$address>, I<$group_id>, I<$parent_id>, I<$os_id>, I<$description>, I<$interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>], [I<$custom_id>], [I<$url_address>]) >>
@ -3317,6 +3349,69 @@ sub pandora_server_statistics ($$) {
Process groups statistics for statistics table
=cut
##########################################################################
sub pandora_process_event_replication ($) {
my $pa_config = shift;
my %pa_config = %{$pa_config};
# Get the console DB connection
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'},
$pa_config{'dbuser'}, $pa_config{'dbpass'});
my $is_event_replication_enabled = enterprise_hook('get_event_replication_flag', [$dbh]);
my $replication_interval = enterprise_hook('get_event_replication_interval', [$dbh]);
# If there are not installed the enterprise version,
# desactivated the event replication or the replication
# interval is wrong: abort
if($is_event_replication_enabled == 0) {
return;
}
if($replication_interval <= 0) {
logger($pa_config, "Replication interval configuration is not a value greater than 0. Event replication thread is will be aborted.", 1);
return;
}
# Get the metaconsole DB connection
my $dbh_metaconsole = enterprise_hook('get_metaconsole_dbh', [$pa_config, $dbh]);
if($dbh_metaconsole eq '') {
logger($pa_config, "Metaconsole DB connection error. Event replication thread is will be aborted.", 1);
return;
}
# Get server id on metaconsole
my $server_name = get_first_server_name($dbh);
my $metaconsole_server_id = -1;
if($server_name ne '') {
$metaconsole_server_id = enterprise_hook('get_metaconsole_setup_server_id', [$dbh_metaconsole,$server_name]);
}
# If the server name is not found in metaconsole setup: abort
if($metaconsole_server_id == -1) {
logger($pa_config, "The server name is not configured in metaconsole. Event replication thread is will be aborted.", 1);
return;
}
my $replication_mode = enterprise_hook('get_event_replication_mode', [$dbh]);
logger($pa_config, "Starting replication events process.", 1);
while(1) {
# Check the queue each N seconds
sleep ($replication_interval);
enterprise_hook('pandora_replicate_events',[$pa_config, $dbh, $dbh_metaconsole, $metaconsole_server_id, $replication_mode]);
}
}
##########################################################################
=head2 C<< pandora_process_policy_queue (I<$pa_config>, I<$dbh>) >>
Process groups statistics for statistics table
=cut
##########################################################################
sub pandora_process_policy_queue ($) {
@ -3327,6 +3422,8 @@ sub pandora_process_policy_queue ($) {
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'},
$pa_config{'dbuser'}, $pa_config{'dbpass'});
logger($pa_config, "Starting policy queue patrol process.", 1);
while(1) {
# Check the queue each 5 seconds
sleep (5);

View File

@ -56,6 +56,7 @@ our @EXPORT = qw(
get_db_rows
get_db_single_row
get_db_value
get_first_server_name
get_group_id
get_group_name
get_module_agent_id
@ -168,6 +169,17 @@ sub get_server_id ($$$) {
return defined ($rc) ? $rc : -1;
}
########################################################################
## Return the first enabled server name found.
########################################################################
sub get_first_server_name ($) {
my ($dbh) = @_;
my $rc = get_db_value ($dbh, "SELECT name FROM tserver");
return defined ($rc) ? $rc : "";
}
########################################################################
## Return group ID given the group name.
########################################################################