2011-05-11 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/Core.pm bin/pandora_server util/pandora_manage.pl: Added thread in main loop of the server with check to the policy queue. Apply and delete agents from policy in the new thread Deleting policies lock system from server git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4335 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
13a7470897
commit
b53259a235
|
@ -1,3 +1,12 @@
|
|||
2011-05-11 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm
|
||||
bin/pandora_server
|
||||
util/pandora_manage.pl: Added thread in main loop of the
|
||||
server with check to the policy queue.
|
||||
Apply and delete agents from policy in the new thread
|
||||
Deleting policies lock system from server
|
||||
|
||||
2011-05-09 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* lib/PandoraFMS/DB.pm
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Pandora FMS Server
|
||||
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
|
||||
##########################################################################
|
||||
# Copyright (c) 2005-2010 Artica Soluciones Tecnologicas S.L
|
||||
# Copyright (c) 2005-2011 Artica Soluciones Tecnologicas S.L
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -189,6 +189,11 @@ if (enterprise_load (\%Config) == 0) {
|
|||
print_message (\%Config, " [*] Pandora FMS Enterprise module loaded.", 1);
|
||||
}
|
||||
|
||||
# Start thread to patrol policy queue
|
||||
if ($Config{'pandora_master'} == 1) {
|
||||
my $thr = threads->create('pandora_process_policy_queue', (\%Config));
|
||||
}
|
||||
|
||||
# Daemonize and put in background
|
||||
if ($Config{'daemon'} == 1) {
|
||||
print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n", 1);
|
||||
|
|
|
@ -163,6 +163,7 @@ our @EXPORT = qw(
|
|||
pandora_group_statistics
|
||||
pandora_server_statistics
|
||||
pandora_self_monitoring
|
||||
pandora_process_policy_queue
|
||||
@ServerTypes
|
||||
);
|
||||
|
||||
|
@ -2081,6 +2082,45 @@ sub pandora_server_statistics ($$) {
|
|||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
=head2 C<< pandora_group_statistics (I<$pa_config>, I<$dbh>) >>
|
||||
|
||||
Process groups statistics for statistics table
|
||||
|
||||
=cut
|
||||
##########################################################################
|
||||
sub pandora_process_policy_queue ($) {
|
||||
my $pa_config = shift;
|
||||
|
||||
my %pa_config = %{$pa_config};
|
||||
|
||||
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, 3306,
|
||||
$pa_config{'dbuser'}, $pa_config{'dbpass'});
|
||||
|
||||
while(1) {
|
||||
my $operation = enterprise_hook('get_first_policy_queue', [$dbh]);
|
||||
$operation = @{$operation}[0];
|
||||
|
||||
if(defined($operation)) {
|
||||
if($operation->{'operation'} eq 'apply') {
|
||||
enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}]);
|
||||
}
|
||||
elsif($operation->{'operation'} eq 'delete') {
|
||||
if($operation->{'id_agent'} == 0) {
|
||||
enterprise_hook('pandora_purge_policy_agents', [$dbh, $pa_config, $operation->{'id_policy'}]);
|
||||
}
|
||||
else {
|
||||
enterprise_hook('pandora_delete_agent_from_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}]);
|
||||
}
|
||||
}
|
||||
|
||||
enterprise_hook('pandora_finish_queue_operation', [$dbh, $operation->{'id'}]);
|
||||
}
|
||||
|
||||
# Check the queue each 5 seconds
|
||||
sleep (5);
|
||||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
=head2 C<< pandora_group_statistics (I<$pa_config>, I<$dbh>) >>
|
||||
|
|
|
@ -449,7 +449,6 @@ sub help_screen{
|
|||
help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file');
|
||||
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
||||
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
|
||||
help_screen_line('--force_unblock_policies', '', 'Force unblock the policies');
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
@ -1229,163 +1228,6 @@ sub pandora_manage_main ($$$) {
|
|||
exist_check($policy_id,'policy',$policy_name);
|
||||
|
||||
enterprise_hook('pandora_apply_policy', [$dbh, $conf, $policy_id]);
|
||||
|
||||
#~ my $blocked_policies = enterprise_hook('pandora_block_policies', [$dbh]);
|
||||
#~
|
||||
#~ if($blocked_policies eq '0E0') {
|
||||
#~ print "[ERROR] The policies are blocked in other terminal.\n\n";
|
||||
#~ exit;
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get the agents
|
||||
#~ my $array_pointer_ag = enterprise_hook('get_policy_agents',[$dbh, $policy_id]);
|
||||
#~
|
||||
#~ if(!defined($array_pointer_ag)) {
|
||||
#~ print "[ERROR] This option is not available in OPEN version.\n\n";
|
||||
#~ exit;
|
||||
#~ }
|
||||
#~
|
||||
#~ print "[INFO] Applying policy '$policy_name'\n\n";
|
||||
#~
|
||||
#~ foreach my $agent (@{$array_pointer_ag}) {
|
||||
#~ my $id_agent = $agent->{'id_agent'};
|
||||
#~ my $agent_name = get_agent_name($dbh, $id_agent);
|
||||
#~
|
||||
#~ # Get the modules
|
||||
#~ my $array_pointer_mod = enterprise_hook('get_policy_modules',[$dbh, $policy_id]);
|
||||
#~
|
||||
#~ if(!defined($array_pointer_mod)) {
|
||||
#~ print "[ERROR] This option is not available in OPEN version.\n\n";
|
||||
#~ exit;
|
||||
#~ }
|
||||
#~
|
||||
#~ foreach my $module (@{$array_pointer_mod}) {
|
||||
#~ # Adapt the fields from tpolicy_modules to tagente_modulos
|
||||
#~ $module->{'id_agente'} = $id_agent;
|
||||
#~
|
||||
#~ $module->{'id_policy_module'} = $module->{'id'};
|
||||
#~ delete $module->{'id'};
|
||||
#~
|
||||
#~ $module->{'descripcion'} = $module->{'description'};
|
||||
#~ delete $module->{'description'};
|
||||
#~
|
||||
#~ $module->{'nombre'} = $module->{'name'};
|
||||
#~ delete $module->{'name'};
|
||||
#~
|
||||
#~ $module->{'id_modulo'} = $module->{'id_module'};
|
||||
#~ delete $module->{'id_module'};
|
||||
#~
|
||||
#~ delete $module->{'id_policy'};
|
||||
#~
|
||||
#~ #Store the conf data
|
||||
#~ $configuration_data .= safe_output("\n\n$module->{'configuration_data'}");
|
||||
#~
|
||||
#~ delete $module->{'configuration_data'};
|
||||
#~
|
||||
#~ my $id_module = get_agent_module_id ($dbh, $module->{'nombre'}, $module->{'id_agente'});
|
||||
#~
|
||||
#~ # If the module doesn't exist we create it, otherwise we update it
|
||||
#~
|
||||
#~ if($id_module == -1) {
|
||||
#~ # Create module
|
||||
#~ $id_module = pandora_create_module_from_hash ($conf, $module, $dbh);
|
||||
#~ }
|
||||
#~ else {
|
||||
#~ # Update module
|
||||
#~ pandora_update_module_from_hash ($conf, $module, 'id_agente_modulo', $id_module, $dbh);
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get policy alerts and create it on created modules
|
||||
#~ my $array_pointer_ale = enterprise_hook('get_policy_module_alerts',[$dbh, $policy_id, $module->{'id_policy_module'}]);
|
||||
#~
|
||||
#~ foreach my $alert (@{$array_pointer_ale}) {
|
||||
#~ my $id_alert_template_module = get_alert_template_module_id($dbh, $id_module, $alert->{'id_alert_template'});
|
||||
#~
|
||||
#~ # Only if the template doesnt exist we create it. If exists we update it
|
||||
#~ if($id_alert_template_module == -1) {
|
||||
#~ $id_alert_template_module = pandora_create_template_module ($conf, $id_module, $alert->{'id_alert_template'}, $dbh, $alert->{'id'}, $alert->{'disabled'}, $alert->{'standby'});
|
||||
#~ }
|
||||
#~ else {
|
||||
#~ pandora_update_template_module ($conf, $id_alert_template_module, $dbh, $alert->{'id'}, $alert->{'disabled'}, $alert->{'standby'});
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get policy alert actions and create it on modules created
|
||||
#~ my $array_pointer_aleact = enterprise_hook('get_policy_alert_actions',[$dbh, $alert->{'id'}]);
|
||||
#~
|
||||
#~ pandora_delete_all_template_module_actions ($dbh, $id_alert_template_module);
|
||||
#~
|
||||
#~ foreach my $alert_action (@{$array_pointer_aleact}) {
|
||||
#~ delete $alert_action->{'id_policy_alert'};
|
||||
#~ delete $alert_action->{'id'};
|
||||
#~ $alert_action->{'id_alert_template_module'} = $id_alert_template_module;
|
||||
#~
|
||||
#~ pandora_create_template_module_action ($conf, $alert_action, $dbh);
|
||||
#~
|
||||
#~ }
|
||||
#~ }
|
||||
#~
|
||||
#~ #Add the conf information to the agent conf file
|
||||
#~ enterprise_hook('pandora_create_policy_conf_info',[$conf, $policy_name, $configuration_data, $agent_name, $dbh]);
|
||||
#~
|
||||
#~ # Flag applyed the agent
|
||||
#~ enterprise_hook('pandora_apply_agent_policy',[$policy_id, $id_agent, $dbh]);
|
||||
#~
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get policy collections and link it on created modules
|
||||
#~ my $array_pointer_col = enterprise_hook('get_policy_collections',[$dbh, $policy_id]);
|
||||
#~
|
||||
#~ my $collection_data = '';
|
||||
#~
|
||||
#~ foreach my $collection (@{$array_pointer_col}) {
|
||||
#~ my $collection_name = enterprise_hook('get_collection_name',[$dbh, $collection->{'id_collection'}]);
|
||||
#~
|
||||
#~ $collection_data = "\n#file_collection $collection_name\n";
|
||||
#~ $collection_data .= "\nfile_collection fc_$collection->{'id_collection'}\n\n";
|
||||
#~ }
|
||||
#~
|
||||
#~ if($collection_data ne '') {
|
||||
#~ enterprise_hook('pandora_delete_collection_agent_from_info',[$conf, $agent_name, $policy_id]);
|
||||
#~ enterprise_hook('pandora_create_collection_conf_info',[$conf, $policy_name, $collection_data,$agent_name,$dbh]);
|
||||
#~ }
|
||||
#~
|
||||
#~ $configuration_data = '';
|
||||
#~ $collection_data = '';
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get extern policy alerts and create it on modules
|
||||
#~ my $array_pointer_ale_ext = enterprise_hook('get_policy_module_alerts',[$dbh, $policy_id, 0]);
|
||||
#~
|
||||
#~ foreach my $alert (@{$array_pointer_ale_ext}) {
|
||||
#~
|
||||
#~ my $array_modules_id = enterprise_hook('get_policy_agents_modules_id',[$dbh, $policy_id, $alert->{'name_extern_module'}]);
|
||||
#~
|
||||
#~ foreach my $module_id (@{$array_modules_id}) {
|
||||
#~ my $id_alert_template_module = get_alert_template_module_id($dbh, $module_id->{'id_agente_modulo'}, $alert->{'id_alert_template'});
|
||||
#~
|
||||
#~ if($id_alert_template_module == -1) {
|
||||
#~ $id_alert_template_module = pandora_create_template_module ($conf, $module_id->{'id_agente_modulo'}, $alert->{'id_alert_template'}, $dbh, $alert->{'id'});
|
||||
#~ }
|
||||
#~
|
||||
#~ # Get policy alert actions and create it on modules created
|
||||
#~ my $array_pointer_aleact = enterprise_hook('get_policy_alert_actions',[$dbh, $alert->{'id'}]);
|
||||
#~
|
||||
#~ pandora_delete_all_template_module_actions ($dbh, $id_alert_template_module);
|
||||
#~
|
||||
#~ foreach my $alert_action (@{$array_pointer_aleact}) {
|
||||
#~ delete $alert_action->{'id_policy_alert'};
|
||||
#~ delete $alert_action->{'id'};
|
||||
#~
|
||||
#~ $alert_action->{'id_alert_template_module'} = $id_alert_template_module;
|
||||
#~
|
||||
#~ pandora_create_template_module_action ($conf, $alert_action, $dbh);
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
#~ enterprise_hook('pandora_unblock_policies', [$dbh]);
|
||||
}
|
||||
elsif ($param eq '--force_unblock_policies') {
|
||||
enterprise_hook('pandora_unblock_policies', [$dbh]);
|
||||
}
|
||||
elsif ($param eq '--disable_policy_alerts') {
|
||||
param_check($ltotal, 1);
|
||||
|
@ -1396,17 +1238,8 @@ sub pandora_manage_main ($$$) {
|
|||
my $policy_id = enterprise_hook('get_policy_id',[$dbh, $policy_name]);
|
||||
exist_check($policy_id,'policy',$policy_name);
|
||||
|
||||
my $blocked_policies = enterprise_hook('pandora_block_policies', [$dbh]);
|
||||
|
||||
if($blocked_policies eq '0E0') {
|
||||
print "[ERROR] The policies are blocked in other terminal.\n\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
# Flag as disabled the policy alerts
|
||||
my $array_pointer_ag = enterprise_hook('pandora_disable_policy_alerts',[$dbh, $policy_id]);
|
||||
|
||||
enterprise_hook('pandora_unblock_policies', [$dbh]);
|
||||
}
|
||||
else {
|
||||
print "[ERROR] Invalid option '$param'.\n\n";
|
||||
|
|
Loading…
Reference in New Issue