Merge branch 'ent-2967-6662-Error-504-en-vista-de-eventos' into 'develop'
Ent 2967 6662 error 504 en vista de eventos See merge request artica/pandorafms!2167 Former-commit-id: 4096c814248a75bbe5e75858b31ee040379d6486
This commit is contained in:
commit
04e8962cec
|
@ -166,92 +166,30 @@ function events_get_events_grouped(
|
|||
$groupby_extra = '';
|
||||
}
|
||||
|
||||
switch ($config['dbtype']) {
|
||||
case 'mysql':
|
||||
db_process_sql('SET group_concat_max_len = 9999999');
|
||||
$event_lj = events_get_secondary_groups_left_join($table);
|
||||
if ($total) {
|
||||
$sql = "SELECT COUNT(*) FROM (SELECT *
|
||||
FROM $table te $event_lj
|
||||
WHERE 1=1 ".$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(*) 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;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'postgresql':
|
||||
if ($total) {
|
||||
$sql = "SELECT COUNT(*)
|
||||
FROM $table te
|
||||
WHERE 1=1 ".$sql_post.'
|
||||
GROUP BY estado, evento, id_agentmodule, id_evento, id_agente, id_usuario, id_grupo, estado, timestamp, utimestamp, event_type, id_alert_am, criticity, user_comment, tags, source, id_extra'.$groupby_extra;
|
||||
} else {
|
||||
$sql = "SELECT *, MAX(id_evento) AS id_evento, array_to_string(array_agg(DISTINCT user_comment), '<br>') AS user_comment,
|
||||
array_to_string(array_agg(DISTINCT id_evento), ',') AS similar_ids,
|
||||
COUNT(*) 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
|
||||
FROM $table te
|
||||
WHERE 1=1 ".$sql_post.'
|
||||
GROUP BY estado, evento, id_agentmodule, id_evento,
|
||||
id_agente, id_usuario, id_grupo, estado,
|
||||
timestamp, utimestamp, event_type, id_alert_am,
|
||||
criticity, user_comment, tags, source, id_extra,
|
||||
te.critical_instructions,
|
||||
te.warning_instructions,
|
||||
te.unknown_instructions,
|
||||
te.owner_user,
|
||||
te.ack_utimestamp,
|
||||
te.custom_data '.$groupby_extra.'
|
||||
ORDER BY timestamp_rep ASC LIMIT '.$pagination.' OFFSET '.$offset;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
if ($total) {
|
||||
$sql = "SELECT COUNT(*)
|
||||
FROM $table te
|
||||
WHERE 1=1 $sql_post
|
||||
GROUP BY estado, to_char(evento), id_agentmodule".$groupby_extra.') b ';
|
||||
} else {
|
||||
$set = [];
|
||||
$set['limit'] = $pagination;
|
||||
$set['offset'] = $offset;
|
||||
|
||||
$sql = "SELECT ta.*, tb.event_rep, tb.timestamp_rep, tb.timestamp_rep_min, tb.user_comments, tb.similar_ids
|
||||
FROM $table ta
|
||||
INNER JOIN (SELECT MAX(id_evento) AS id_evento, COUNT(id_evento) AS event_rep,
|
||||
MAX(utimestamp) AS timestamp_rep, MIN(utimestamp) AS timestamp_rep_min,
|
||||
TAB_TO_STRING(CAST(COLLECT(TO_CHAR(user_comment) ORDER BY id_evento ASC) AS t_varchar2_tab), '<br>') AS user_comments,
|
||||
TAB_TO_STRING(CAST(COLLECT(CAST(id_evento AS VARCHAR2(4000)) ORDER BY id_evento ASC) AS t_varchar2_tab)) AS similar_ids
|
||||
FROM $table te
|
||||
WHERE 1=1 $sql_post
|
||||
GROUP BY estado, to_char(evento), id_agentmodule$groupby_extra) tb
|
||||
ON ta.id_evento = tb.id_evento
|
||||
ORDER BY tb.timestamp_rep ASC";
|
||||
$sql = oracle_recode_query($sql, $set);
|
||||
}
|
||||
break;
|
||||
db_process_sql('SET group_concat_max_len = 9999999');
|
||||
$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.'
|
||||
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;
|
||||
}
|
||||
|
||||
// Extract the events by filter (or not) from db
|
||||
|
@ -260,16 +198,6 @@ function events_get_events_grouped(
|
|||
if ($total) {
|
||||
return reset($events[0]);
|
||||
} else {
|
||||
// Override the column 'user_comment' with the column 'user_comments' when oracle
|
||||
if (!empty($events) && $config['dbtype'] == 'oracle') {
|
||||
array_walk(
|
||||
$events,
|
||||
function (&$value, $key) {
|
||||
set_if_defined($value['user_comment'], $value['user_comments']);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
|
@ -4871,6 +4799,10 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=
|
|||
*/
|
||||
function events_get_secondary_groups_left_join($table)
|
||||
{
|
||||
if (users_is_admin()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($table == 'tevento') {
|
||||
return 'LEFT JOIN tagent_secondary_group tasg ON te.id_agente = tasg.id_agent';
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ if (check_acl($id_user, 0, 'ER')) {
|
|||
$groups = users_get_groups($id_user, 'EM');
|
||||
}
|
||||
|
||||
|
||||
$propagate = db_get_value('propagate', 'tgrupo', 'id_grupo', $id_group);
|
||||
|
||||
if ($id_group > 0) {
|
||||
|
@ -41,24 +40,67 @@ if ($id_group > 0) {
|
|||
$childrens_ids = array_keys($groups);
|
||||
}
|
||||
|
||||
// Group selection
|
||||
if (!isset($date_from)) {
|
||||
$date_from = '';
|
||||
}
|
||||
|
||||
if (!isset($date_to)) {
|
||||
$date_to = '';
|
||||
}
|
||||
|
||||
if (($date_from === '') && ($date_to === '')) {
|
||||
if ($event_view_hr > 0) {
|
||||
$filter_resume['hours_max'] = $event_view_hr;
|
||||
$unixtime = (get_system_time() - ($event_view_hr * SECONDS_1HOUR));
|
||||
$sql_post .= ' AND (utimestamp > '.$unixtime.')';
|
||||
}
|
||||
} else {
|
||||
// Some of this values will have the user's timezone,
|
||||
// so we need to reverse it to the system's timezone
|
||||
// before using it into the db.
|
||||
$fixed_offset = get_fixed_offset();
|
||||
|
||||
if (!empty($date_from)) {
|
||||
if (empty($time_from)) {
|
||||
$time_from = '00:00:00';
|
||||
}
|
||||
|
||||
$utimestamp_from = (strtotime($date_from.' '.$time_from) - $fixed_offset);
|
||||
$filter_resume['time_from'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_from);
|
||||
$sql_post .= ' AND (utimestamp >= '.$utimestamp_from.')';
|
||||
}
|
||||
|
||||
if (!empty($date_to)) {
|
||||
if (empty($time_to)) {
|
||||
$time_to = '23:59:59';
|
||||
}
|
||||
|
||||
$utimestamp_to = (strtotime($date_to.' '.$time_to) - $fixed_offset);
|
||||
$filter_resume['time_to'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_to);
|
||||
$sql_post .= ' AND (utimestamp <= '.$utimestamp_to.')';
|
||||
}
|
||||
}
|
||||
|
||||
// Group selection.
|
||||
if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
||||
if ($propagate) {
|
||||
$childrens_str = implode(',', $childrens_ids);
|
||||
$sql_post = " AND (id_grupo IN ($childrens_str) OR id_group IN ($childrens_str))";
|
||||
$sql_post .= " AND (id_grupo IN ($childrens_str) OR id_group IN ($childrens_str))";
|
||||
} else {
|
||||
// If a group is selected and it's in the groups allowed
|
||||
$sql_post = " AND (id_grupo = $id_group OR id_group = $id_group)";
|
||||
// If a group is selected and it's in the groups allowed.
|
||||
$sql_post .= " AND (id_grupo = $id_group OR id_group = $id_group)";
|
||||
}
|
||||
} else {
|
||||
$sql_post = sprintf(
|
||||
' AND (id_grupo IN (%s) OR id_group IN (%s)) ',
|
||||
implode(',', array_keys($groups)),
|
||||
implode(',', array_keys($groups))
|
||||
);
|
||||
if (!users_is_admin() && !users_can_manage_group_all('ER')) {
|
||||
$sql_post .= sprintf(
|
||||
' AND (id_grupo IN (%s) OR id_group IN (%s)) ',
|
||||
implode(',', array_keys($groups)),
|
||||
implode(',', array_keys($groups))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip system messages if user is not PM
|
||||
// Skip system messages if user is not PM.
|
||||
if (!check_acl($id_user, 0, 'PM')) {
|
||||
$sql_post .= ' AND id_grupo != 0';
|
||||
}
|
||||
|
@ -164,7 +206,7 @@ if ($source != '') {
|
|||
$sql_post .= " AND source LIKE '%$source%'";
|
||||
}
|
||||
|
||||
// In metaconsole mode the agent search is performed by name
|
||||
// In metaconsole mode the agent search is performed by name.
|
||||
if ($meta) {
|
||||
$text_agent = get_parameter('text_agent', '');
|
||||
$id_agent = get_parameter('id_agent', 0);
|
||||
|
@ -179,7 +221,7 @@ if ($meta) {
|
|||
break;
|
||||
|
||||
case -1:
|
||||
// Agent doesnt exist. No results will returned
|
||||
// Agent doesnt exist. No results will returned.
|
||||
$sql_post .= ' AND 1 = 0';
|
||||
break;
|
||||
|
||||
|
@ -192,9 +234,7 @@ if ($meta) {
|
|||
|
||||
|
||||
|
||||
if ($meta) {
|
||||
// There is another filter.
|
||||
} else {
|
||||
if (!$meta) {
|
||||
if (!empty($text_module)) {
|
||||
$filter_resume['module'] = $text_module;
|
||||
$sql_post .= " AND id_agentmodule IN (
|
||||
|
@ -210,48 +250,7 @@ if ($id_user_ack != '0') {
|
|||
$sql_post .= " AND id_usuario = '".$id_user_ack."'";
|
||||
}
|
||||
|
||||
if (!isset($date_from)) {
|
||||
$date_from = '';
|
||||
}
|
||||
|
||||
if (!isset($date_to)) {
|
||||
$date_to = '';
|
||||
}
|
||||
|
||||
if (($date_from == '') && ($date_to == '')) {
|
||||
if ($event_view_hr > 0) {
|
||||
$filter_resume['hours_max'] = $event_view_hr;
|
||||
$unixtime = (get_system_time() - ($event_view_hr * SECONDS_1HOUR));
|
||||
$sql_post .= ' AND (utimestamp > '.$unixtime.')';
|
||||
}
|
||||
} else {
|
||||
// Some of this values will have the user's timezone,
|
||||
// so we need to reverse it to the system's timezone
|
||||
// before using it into the db
|
||||
$fixed_offset = get_fixed_offset();
|
||||
|
||||
if (!empty($date_from)) {
|
||||
if (empty($time_from)) {
|
||||
$time_from = '00:00:00';
|
||||
}
|
||||
|
||||
$utimestamp_from = (strtotime($date_from.' '.$time_from) - $fixed_offset);
|
||||
$filter_resume['time_from'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_from);
|
||||
$sql_post .= ' AND (utimestamp >= '.$utimestamp_from.')';
|
||||
}
|
||||
|
||||
if (!empty($date_to)) {
|
||||
if (empty($time_to)) {
|
||||
$time_to = '23:59:59';
|
||||
}
|
||||
|
||||
$utimestamp_to = (strtotime($date_to.' '.$time_to) - $fixed_offset);
|
||||
$filter_resume['time_to'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_to);
|
||||
$sql_post .= ' AND (utimestamp <= '.$utimestamp_to.')';
|
||||
}
|
||||
}
|
||||
|
||||
// Search by tag
|
||||
// Search by tag.
|
||||
if (!empty($tag_with)) {
|
||||
if (!users_is_admin()) {
|
||||
$user_tags = array_flip(tags_get_tags_for_module_search());
|
||||
|
@ -305,7 +304,7 @@ if (!empty($tag_without)) {
|
|||
$sql_post .= ' ) ';
|
||||
}
|
||||
|
||||
// Filter/Only alerts
|
||||
// Filter/Only alerts.
|
||||
if (isset($filter_only_alert)) {
|
||||
if ($filter_only_alert == 0) {
|
||||
$filter_resume['alerts'] = $filter_only_alert;
|
||||
|
@ -316,7 +315,7 @@ if (isset($filter_only_alert)) {
|
|||
}
|
||||
}
|
||||
|
||||
// Tags ACLS
|
||||
// Tags ACLS.
|
||||
if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
||||
$group_array = (array) $id_group;
|
||||
} else {
|
||||
|
@ -335,7 +334,7 @@ if (check_acl($id_user, 0, 'ER')) {
|
|||
[],
|
||||
true
|
||||
);
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
|
||||
} else if (check_acl($id_user, 0, 'EW')) {
|
||||
$tags_acls_condition = tags_get_acl_tags(
|
||||
$id_user,
|
||||
|
@ -348,7 +347,7 @@ if (check_acl($id_user, 0, 'ER')) {
|
|||
[],
|
||||
true
|
||||
);
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
|
||||
} else if (check_acl($id_user, 0, 'EM')) {
|
||||
$tags_acls_condition = tags_get_acl_tags(
|
||||
$id_user,
|
||||
|
@ -361,14 +360,14 @@ if (check_acl($id_user, 0, 'ER')) {
|
|||
[],
|
||||
true
|
||||
);
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
||||
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
|
||||
}
|
||||
|
||||
if (($tags_acls_condition != ERR_WRONG_PARAMETERS) && ($tags_acls_condition != ERR_ACL) && ($tags_acls_condition != -110000)) {
|
||||
$sql_post .= $tags_acls_condition;
|
||||
}
|
||||
|
||||
// Metaconsole fitlers
|
||||
// Metaconsole fitlers.
|
||||
if ($meta) {
|
||||
if ($server_id) {
|
||||
$filter_resume['server'] = $server_id;
|
||||
|
|
Loading…
Reference in New Issue