diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index 3b5656323a..9e3979acda 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -353,9 +353,18 @@ if ($delete_action) { if ($enable_alert) { $searchFlag = true; $id_alert = (int) get_parameter('id_alert'); + $id_agente = ($id_agente !== 0) ? $id_agente : alerts_get_agent_by_alert($id_alert); $result = alerts_agent_module_disable($id_alert, false); + if ($id_agente) { + db_process_sql( + 'UPDATE tagente + SET update_alert_count = 1 + WHERE id_agente = '.$id_agente + ); + } + if ($result) { db_pandora_audit( AUDIT_LOG_ALERT_MANAGEMENT, @@ -380,9 +389,18 @@ if ($enable_alert) { if ($disable_alert) { $searchFlag = true; $id_alert = (int) get_parameter('id_alert'); + $id_agente = ($id_agente !== 0) ? $id_agente : alerts_get_agent_by_alert($id_alert); $result = alerts_agent_module_disable($id_alert, true); + if ($id_agente) { + db_process_sql( + 'UPDATE tagente + SET update_alert_count = 1 + WHERE id_agente = '.$id_agente + ); + } + if ($result) { db_pandora_audit( AUDIT_LOG_ALERT_MANAGEMENT, diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 9921419c8b..0bb4216365 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2828,6 +2828,25 @@ function alerts_get_agent_modules( } +/** + * Return the id_agent of the alert + * + * @param integer $id_agent_module + * @return integer id_agent + */ +function alerts_get_agent_by_alert($id_agent_module) +{ + $sql = sprintf( + 'SELECT id_agente FROM talert_template_modules atm INNER JOIN tagente_modulo am ON am.id_agente_modulo = atm.id_agent_module WHERE atm.id = %d + ', + $id_agent_module + ); + $id_agente = db_get_row_sql($sql)['id_agente']; + + return $id_agente; +} + + function alerts_get_actions_names($actions, $reduce=false) { $where = ''; diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 45800de908..ae07174f07 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -401,30 +401,33 @@ sub pandora_server_tasks ($) { # Update forced alerts pandora_exec_forced_alerts ($pa_config, $dbh); + + my @agents = get_db_rows ($dbh, 'SELECT id_agente, update_alert_count FROM tagente WHERE update_alert_count=1'); + foreach my $agent (@agents) { + if ($agent->{'update_alert_count'} == 1) { + pandora_update_agent_alert_count ($pa_config, $dbh, $agent->{'id_agente'}); + } + } } - + # TASKS EXECUTED EVERY 30 SECONDS (Mid latency tasks) # --------------------------------------------------- if (($counter % 30) == 0) { # Update module status and fired alert counts - my @agents = get_db_rows ($dbh, 'SELECT id_agente, nombre, update_module_count, update_alert_count, update_secondary_groups FROM tagente WHERE (update_module_count=1 OR update_alert_count=1 OR update_secondary_groups=1)'); + my @agents = get_db_rows ($dbh, 'SELECT id_agente, nombre, update_module_count, update_secondary_groups FROM tagente WHERE (update_module_count=1 OR update_secondary_groups=1)'); foreach my $agent (@agents) { logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10); - + if ($agent->{'update_module_count'} == 1) { pandora_update_agent_module_count ($pa_config, $dbh, $agent->{'id_agente'}); } - - if ($agent->{'update_alert_count'} == 1) { - pandora_update_agent_alert_count ($pa_config, $dbh, $agent->{'id_agente'}); - } if ($agent->{'update_secondary_groups'} == 1) { pandora_update_secondary_groups_cache ($pa_config, $dbh, $agent->{'id_agente'}); } } - + # Keepalive module control.(very DB intensive, not run frecuently pandora_module_keep_alive_nd ($pa_config, $dbh);