diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 4f121cc8c0..ac836d51fd 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -132,40 +132,59 @@ function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $s * * @return mixed Return id if the group have any alert is fired or false is not. */ -function alerts_get_event_status_group($idGroup, $type = "alert_fired", $query = 'AND 1=1') { - global $config; - - $return = false; - - $typeWhere = ''; - - if (!is_array($type)) { - $typeWhere = ' AND event_type = "' . $type . '" '; - } - else { - $temp = array(); - foreach ($type as $item) { - $temp[] = '"' . $item . '"'; - } - - $typeWhere = ' AND event_type IN (' . implode(',', $temp) . ')'; - } - - $agents = agents_get_group_agents($idGroup, false, "lower", false); - - $idAgents = array_keys($agents); - - $result = db_get_all_rows_sql('SELECT id_evento - FROM tevento - WHERE estado = 0 AND id_agente IN (' . implode(',', $idAgents) . ') ' . $typeWhere . $query . ' - ORDER BY id_evento DESC LIMIT 1'); - - if ($result === false) { - return false; - } - - return $result[0]['id_evento']; -} + function alerts_get_event_status_group($idGroup, $type = "alert_fired", $query = 'AND 1=1', $agents = null) { + global $config; + + $return = false; + + $typeWhere = ''; + + if (!is_array($type)) { + $typeWhere = ' AND event_type = "' . $type . '" '; + } + else { + $temp = array(); + foreach ($type as $item) { + array_push ( $temp , $item ); + } + + $typeWhere = ' AND event_type IN ('; + + foreach ($temp as $ele) { + $typeWhere .= "'".$ele."'"; + + if($ele != end($temp)){ + $typeWhere .= ","; + } + + } + + $typeWhere .= ')'; + + } + + if ($agents == null) { + $agents = agents_get_group_agents($idGroup, false, "lower", false); + + $idAgents = array_keys($agents); + + } + else { + $idAgents = array_values($agents); + + } + + $result = db_get_all_rows_sql('SELECT id_evento + FROM tevento + WHERE estado = 0 AND id_agente IN (0,' . implode(',', $idAgents) . ') ' . $typeWhere . $query . ' + ORDER BY id_evento DESC LIMIT 1'); + + if ($result === false) { + return false; + } + + return $result[0]['id_evento']; + } /** * Insert in talert_commands a new command. diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 50efdaa173..c5f0c101ac 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -138,7 +138,7 @@ if (is_ajax ()) { $alert = get_parameter('alert_fired'); if ($alert == 'true') { $resultAlert = alerts_get_event_status_group($idGroup, - 'alert_fired', $query); + array('alert_fired','alert_ceased'), $query); } $critical = get_parameter('critical'); if ($critical == 'true') {