Merge branch 'ent-6526-Error-SQL-en-la-vista-HTML-del-item-Group-Event-Report-de-templates' into 'develop'
Fixed template events See merge request artica/pandorafms!3535
This commit is contained in:
commit
55517ab53a
|
@ -1552,26 +1552,18 @@ function events_get_event($id, $fields=false, $meta=false, $history=false)
|
|||
/**
|
||||
* Retrieve all events ungrouped.
|
||||
*
|
||||
* @param string $sql_post Sql_post.
|
||||
* @param integer $offset Offset.
|
||||
* @param integer $pagination Pagination.
|
||||
* @param boolean $meta Meta.
|
||||
* @param boolean $history History.
|
||||
* @param boolean $total Total.
|
||||
* @param boolean $history_db History_db.
|
||||
* @param string $order Order.
|
||||
* @param string $sql_post Sql_post.
|
||||
* @param boolean $meta Meta.
|
||||
* @param boolean $history History.
|
||||
* @param boolean $returnSql Only Query.
|
||||
*
|
||||
* @return mixed Array of events or false.
|
||||
*/
|
||||
function events_get_events_no_grouped(
|
||||
$sql_post,
|
||||
$offset=0,
|
||||
$pagination=1,
|
||||
$meta=false,
|
||||
$history=false,
|
||||
$total=false,
|
||||
$history_db=false,
|
||||
$order='ASC'
|
||||
$returnSql=false
|
||||
) {
|
||||
global $config;
|
||||
|
||||
|
@ -1581,7 +1573,11 @@ function events_get_events_no_grouped(
|
|||
$sql .= events_get_secondary_groups_left_join($table);
|
||||
$sql .= $sql_post;
|
||||
|
||||
$events = db_get_all_rows_sql($sql, $history_db);
|
||||
if ($returnSql === true) {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
$events = db_get_all_rows_sql($sql, $history);
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
@ -1634,29 +1630,59 @@ function events_get_events_grouped(
|
|||
$event_lj = events_get_secondary_groups_left_join($table);
|
||||
if ($total) {
|
||||
$sql = "SELECT COUNT(*) FROM (SELECT id_evento
|
||||
FROM $table te $event_lj
|
||||
WHERE 1=1 ".$sql_post.'
|
||||
FROM $table te $event_lj ".$sql_post.'
|
||||
GROUP BY estado, evento, id_agente, id_agentmodule'.$groupby_extra.') AS t';
|
||||
} else {
|
||||
$sql = "SELECT *, MAX(id_evento) AS id_evento,
|
||||
GROUP_CONCAT(DISTINCT user_comment SEPARATOR '<br>') AS user_comment,
|
||||
GROUP_CONCAT(DISTINCT id_evento SEPARATOR ',') AS similar_ids,
|
||||
COUNT(id_evento) AS event_rep, MAX(utimestamp) AS timestamp_rep,
|
||||
MIN(utimestamp) AS timestamp_rep_min,
|
||||
(SELECT owner_user FROM $table WHERE id_evento = MAX(te.id_evento)) owner_user,
|
||||
(SELECT id_usuario FROM $table WHERE id_evento = MAX(te.id_evento)) id_usuario,
|
||||
(SELECT id_agente FROM $table WHERE id_evento = MAX(te.id_evento)) id_agente,
|
||||
(SELECT criticity FROM $table WHERE id_evento = MAX(te.id_evento)) AS criticity,
|
||||
(SELECT ack_utimestamp FROM $table WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp,
|
||||
(SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name
|
||||
FROM $table te $event_lj
|
||||
WHERE 1=1 ".$sql_post.'
|
||||
GROUP BY estado, evento, id_agente, id_agentmodule'.$groupby_extra;
|
||||
$sql .= ' '.events_get_sql_order($sort_field, $order, 2);
|
||||
$sql .= ' LIMIT '.$offset.','.$pagination;
|
||||
$sql = sprintf(
|
||||
'SELECT *,
|
||||
MAX(id_evento) AS id_evento,
|
||||
GROUP_CONCAT(
|
||||
DISTINCT user_comment SEPARATOR "<br>"
|
||||
) AS user_comment,
|
||||
GROUP_CONCAT(
|
||||
DISTINCT id_evento SEPARATOR ","
|
||||
) AS similar_ids,
|
||||
COUNT(id_evento) AS event_rep, MAX(utimestamp) AS timestamp_rep,
|
||||
MIN(utimestamp) AS timestamp_rep_min,
|
||||
(SELECT owner_user
|
||||
FROM %s
|
||||
WHERE id_evento = MAX(te.id_evento)) AS owner_user,
|
||||
(SELECT id_usuario
|
||||
FROM %s
|
||||
WHERE id_evento = MAX(te.id_evento)) AS id_usuario,
|
||||
(SELECT id_agente
|
||||
FROM %s
|
||||
WHERE id_evento = MAX(te.id_evento)) AS id_agente,
|
||||
(SELECT criticity
|
||||
FROM %s
|
||||
WHERE id_evento = MAX(te.id_evento)) AS criticity,
|
||||
(SELECT ack_utimestamp
|
||||
FROM %s
|
||||
WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp,
|
||||
(SELECT nombre
|
||||
FROM tagente_modulo
|
||||
WHERE id_agente_modulo = te.id_agentmodule) AS module_name
|
||||
FROM %s te %s
|
||||
%s
|
||||
GROUP BY estado, evento, id_agente, id_agentmodule %s
|
||||
%s
|
||||
LIMIT %d, %d',
|
||||
$table,
|
||||
$table,
|
||||
$table,
|
||||
$table,
|
||||
$table,
|
||||
$table,
|
||||
$event_lj,
|
||||
$sql_post,
|
||||
$groupby_extra,
|
||||
events_get_sql_order($sort_field, $order, 2),
|
||||
$offset,
|
||||
$pagination
|
||||
);
|
||||
}
|
||||
|
||||
// Extract the events by filter (or not) from db
|
||||
// Extract the events by filter (or not) from db.
|
||||
$events = db_get_all_rows_sql($sql, $history_db);
|
||||
|
||||
if ($total) {
|
||||
|
@ -2971,7 +2997,8 @@ function events_get_agent(
|
|||
$type = [];
|
||||
foreach ($filter_event_type as $event_type) {
|
||||
if ($event_type != '') {
|
||||
// If normal, warning, could be several (going_up_warning, going_down_warning... too complex.
|
||||
// If normal, warning, could be several
|
||||
// (going_up_warning, going_down_warning... too complex.
|
||||
// Shown to user only "warning, critical and normal".
|
||||
if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') {
|
||||
$type[] = " event_type LIKE '%".$event_type."%' ";
|
||||
|
@ -2991,10 +3018,10 @@ function events_get_agent(
|
|||
}
|
||||
|
||||
if ($events_group) {
|
||||
$sql_where .= sprintf(
|
||||
$secondary_groups = sprintf(
|
||||
' INNER JOIN tgrupo tg
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo = %s)
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group = %s)
|
||||
ON (te.id_grupo = tg.id_grupo AND tg.id_grupo IN (%s))
|
||||
OR (tg.id_grupo = tasg.id_group AND tasg.id_group IN (%s))
|
||||
WHERE utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
join(',', $id_group),
|
||||
|
@ -3002,22 +3029,27 @@ function events_get_agent(
|
|||
$datelimit,
|
||||
$date
|
||||
);
|
||||
} else if ($events_module) {
|
||||
$sql_where .= sprintf(
|
||||
' AND id_agentmodule = %d AND utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
$id_agent_module,
|
||||
$datelimit,
|
||||
$date
|
||||
);
|
||||
$sql_where = $secondary_groups.' '.$sql_where;
|
||||
} else {
|
||||
$sql_where .= sprintf(
|
||||
' AND id_agente = %d AND utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
$id_agent,
|
||||
$datelimit,
|
||||
$date
|
||||
);
|
||||
$sql_where = ' WHERE 1=1 '.$sql_where;
|
||||
|
||||
if ($events_module) {
|
||||
$sql_where .= sprintf(
|
||||
' AND id_agentmodule = %d AND utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
$id_agent_module,
|
||||
$datelimit,
|
||||
$date
|
||||
);
|
||||
} else {
|
||||
$sql_where .= sprintf(
|
||||
' AND id_agente = %d AND utimestamp > %d
|
||||
AND utimestamp <= %d ',
|
||||
$id_agent,
|
||||
$datelimit,
|
||||
$date
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_metaconsole() && $id_server) {
|
||||
|
@ -3037,11 +3069,7 @@ function events_get_agent(
|
|||
} else {
|
||||
return events_get_events_no_grouped(
|
||||
$sql_where,
|
||||
0,
|
||||
1000,
|
||||
(is_metaconsole() && $id_server) ? true : false,
|
||||
false,
|
||||
false,
|
||||
$history
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2957,7 +2957,7 @@ function reporting_group_report($report, $content)
|
|||
if (empty($id_group)) {
|
||||
$events = [];
|
||||
} else {
|
||||
$sql_where = sprintf(' AND id_grupo IN (%s) AND estado<>1 ', implode(',', $id_group));
|
||||
$sql_where = sprintf(' WHERE id_grupo IN (%s) AND estado<>1 ', implode(',', $id_group));
|
||||
$events = events_get_events_grouped(
|
||||
$sql_where,
|
||||
0,
|
||||
|
|
|
@ -731,7 +731,7 @@ class Events
|
|||
$system = System::getInstance();
|
||||
|
||||
// --------------Fill the SQL POST-------------------------------
|
||||
$sql_post = '';
|
||||
$sql_post = ' WHERE 1=1 ';
|
||||
|
||||
switch ($this->status) {
|
||||
case 0:
|
||||
|
|
|
@ -311,7 +311,7 @@ if ($user_filter != 0 && empty($id_name) && !$update_from_filter_table) {
|
|||
}
|
||||
|
||||
// Build the condition of the events query.
|
||||
$sql_post = '';
|
||||
$sql_post = ' WHERE 1=1 ';
|
||||
|
||||
$id_user = $config['id_user'];
|
||||
|
||||
|
@ -1214,7 +1214,7 @@ if ($group_rep == 0) {
|
|||
$sql = 'SELECT COUNT(DISTINCT id_evento)
|
||||
FROM $event_table te
|
||||
$event_lj
|
||||
WHERE 1=1 $sql_post';
|
||||
$sql_post';
|
||||
$total_events = (int) db_get_sql($sql);
|
||||
} else if ($group_rep == 1) {
|
||||
$total_events = events_get_events_grouped(
|
||||
|
|
Loading…
Reference in New Issue