From 21bb51e2ad0d0225c3e00bfc9e843a5f4b4a23f8 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 3 May 2011 16:55:17 +0000 Subject: [PATCH] 2011-05-03 Sergio Martin * util/pandora_manage.pl: Added option to disable all the alerts of one policy. Updated apply_policy option to use disabled flag on the creation and update git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4298 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 ++++ pandora_server/util/pandora_manage.pl | 53 ++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 06fb2c7ba2..2aae96b2ba 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2011-05-03 Sergio Martin + + * util/pandora_manage.pl: Added option to disable all the + alerts of one policy. + Updated apply_policy option to use disabled flag + on the creation and update + 2011-05-03 Ramon Novoa * lib/PandoraFMS/DB.pm, lib/PandoraFMS/DataServer.pm: Check that a group diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 26d9f72cf9..5740b1f962 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -177,15 +177,33 @@ sub pandora_manage_init ($) { ########################################################################## ## Create a template module. ########################################################################## -sub pandora_create_template_module ($$$$;$) { - my ($pa_config, $id_agent_module, $id_alert_template, $dbh, $id_policy_alerts) = @_; +sub pandora_create_template_module ($$$$;$$) { + my ($pa_config, $id_agent_module, $id_alert_template, $dbh, $id_policy_alerts, $disabled) = @_; $id_policy_alerts = 0 unless defined $id_policy_alerts; + $disabled = 0 unless defined $disabled; my $module_name = get_module_name($dbh, $id_agent_module); logger($pa_config, "Creating alert of template '$id_alert_template' on agent module '$module_name'.", 10); - $dbh->do("INSERT INTO talert_template_modules (`id_agent_module`, `id_alert_template`, `id_policy_alerts`) VALUES ($id_agent_module, $id_alert_template, $id_policy_alerts)"); + $dbh->do("INSERT INTO talert_template_modules (`id_agent_module`, `id_alert_template`, `id_policy_alerts`, `disabled`) VALUES ($id_agent_module, $id_alert_template, $id_policy_alerts, $disabled)"); + return $dbh->{'mysql_insertid'}; +} + +########################################################################## +## Update a template module. +########################################################################## + +sub pandora_update_template_module ($$$;$$) { + my ($pa_config, $id_alert, $dbh, $id_policy_alerts, $disabled) = @_; + + $id_policy_alerts = 0 unless defined $id_policy_alerts; + $disabled = 0 unless defined $disabled; + + #my $module_name = get_module_name($dbh, $id_agent_module); + #logger($pa_config, "Update alert of template '$id_alert_template' on agent module '$module_name'.", 10); + + $dbh->do("UPDATE talert_template_modules SET `id_policy_alerts` = '$id_policy_alerts', `disabled` = '$disabled' WHERE id = $id_alert"); return $dbh->{'mysql_insertid'}; } @@ -495,6 +513,7 @@ sub help_screen{ help_screen_line('--delete_data', '-m | -a | -g ', 'Delete historic data of a module, the modules of an agent or the modules of the agents of a group'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--apply_policy', '', 'Force apply a policy'); + help_screen_line('--disable_policy_alerts', '', 'Disable all the alerts of a policy'); help_screen_line('--force_unblock_policies', '', 'Force unblock the policies'); print "\n"; exit; @@ -1345,9 +1364,12 @@ sub pandora_manage_main ($$$) { 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 + # 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'}); + $id_alert_template_module = pandora_create_template_module ($conf, $id_module, $alert->{'id_alert_template'}, $dbh, $alert->{'id'}, $alert->{'disabled'}); + } + else { + pandora_update_template_module ($conf, $id_alert_template_module, $dbh, $alert->{'id'}, $alert->{'disabled'}); } # Get policy alert actions and create it on modules created @@ -1428,6 +1450,27 @@ sub pandora_manage_main ($$$) { elsif ($param eq '--force_unblock_policies') { enterprise_hook('pandora_unblock_policies', [$dbh]); } + elsif ($param eq '--disable_policy_alerts') { + param_check($ltotal, 1); + my $policy_name = @ARGV[2]; + + my $configuration_data = ""; + + 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"; $param = '';