From 8dbc860f4ab94a08fab21d200c875183968f554b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 8 Jun 2022 17:01:15 +0200 Subject: [PATCH] refactor events meta pandora_enterprise#9086 --- pandora_console/include/ajax/events.php | 48 - pandora_console/include/functions_events.php | 2447 +---------------- pandora_console/include/functions_graph.php | 99 +- .../include/functions_reporting.php | 285 +- .../include/functions_reporting_html.php | 83 +- .../include/javascript/pandora_events.js | 54 - .../Widgets/top_n_events_by_group.php | 8 +- .../Widgets/top_n_events_by_module.php | 8 +- pandora_console/include/lib/Event.php | 2 +- pandora_console/mobile/operation/events.php | 145 +- .../operation/events/events.build_table.php | 1168 +------- pandora_console/operation/events/events.php | 33 +- .../operation/events/events_list.php | 2043 +------------- 13 files changed, 344 insertions(+), 6079 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index d5d7d24c20..bf26205d1d 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -57,7 +57,6 @@ if (! check_acl($config['id_user'], 0, 'ER') } $get_events_details = (bool) get_parameter('get_events_details'); -$get_list_events_agents = (bool) get_parameter('get_list_events_agents'); $get_extended_event = (bool) get_parameter('get_extended_event'); $change_status = (bool) get_parameter('change_status'); $change_owner = (bool) get_parameter('change_owner'); @@ -1892,53 +1891,6 @@ if ($table_events) { } } -if ($get_list_events_agents) { - global $config; - - $id_agent = get_parameter('id_agent'); - $server_id = get_parameter('server_id'); - $event_type = get_parameter('event_type'); - $severity = implode(',', get_parameter('severity', -1)); - $status = get_parameter('status'); - $search = get_parameter('search'); - $id_agent_module = get_parameter('id_agent_module'); - $event_view_hr = get_parameter('event_view_hr'); - $id_user_ack = get_parameter('id_user_ack'); - $tag_with = get_parameter('tag_with'); - $tag_without = get_parameter('tag_without'); - $filter_only_alert = get_parameter('filter_only_alert'); - $date_from = get_parameter('date_from'); - $time_from = get_parameter('time_from', '00:00:00'); - $date_to = get_parameter('date_to'); - $time_to = get_parameter('time_to', '23:59:59'); - $id_user = $config['id_user']; - - $returned_sql = events_sql_events_grouped_agents( - $id_agent, - $server_id, - $event_type, - $severity, - $status, - $search, - $id_agent_module, - $event_view_hr, - $id_user_ack, - $tag_with, - $tag_without, - $filter_only_alert, - $date_from, - $time_from, - $date_to, - $time_to, - $id_user - ); - - $returned_list = events_list_events_grouped_agents($returned_sql); - - echo $returned_list; - return; -} - if ($total_events) { global $config; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index d746352d94..66f096d7bd 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -452,96 +452,6 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal } -/** - * Retrieves all events related to matching one. - * - * @param integer $id_evento Master event (max_id_evento). - * @param array $filter Filters. - * @param boolean $count Count results or get results. - * @param boolean $history Apply on historical table. - * - * @return array Events or false in case of error. - */ -function events_get_related_events( - $id_evento, - $filter=null, - $count=false, - $history=false -) { - global $config; - - if (!isset($id_evento) || $id_evento <= 0) { - return false; - } - - if (!isset($filter) || !is_array($filter)) { - $filter = ['group_rep' => 0]; - } - - $table = 'tevento'; - $select = '*'; - if ($count === true) { - $select = 'count(*) as n'; - }; - - switch ($filter['group_rep']) { - case '0': - case '2': - default: - // No groups option direct update. - $related_sql = sprintf( - 'SELECT %s FROM %s - WHERE id_evento = %d', - $select, - $table, - $id_evento - ); - break; - - case '1': - // Group by events. - $sql = events_get_all( - ['te.*'], - $filter, - // Offset. - null, - // Limit. - null, - // Order. - null, - // Sort_field. - null, - // Historical table. - $history, - // Return_sql. - true - ); - $related_sql = sprintf( - 'SELECT %s FROM %s tu INNER JOIN ( %s ) tf - WHERE tu.estado = tf.estado - AND tu.evento = tf.evento - AND tu.id_agente = tf.id_agente - AND tu.id_agentmodule = tf.id_agentmodule - AND tf.max_id_evento = %d', - $select, - $table, - $sql, - $id_evento - ); - break; - } - - if ($count === true) { - $r = db_get_all_rows_sql($related_sql); - - return $r[0]['n']; - } - - return db_get_all_rows_sql($related_sql); - -} - - /** * Validates all events matching target filter. * @@ -1434,7 +1344,7 @@ function events_get_all( $pagination = ''; if (is_metaconsole() === true) { // TODO: XXX TOTAL 10000 - 10000000. settins meta 300000; TIP. capturra el error. - $pagination = ' LIMIT 10 '; + $pagination = ' LIMIT 100000 '; } else if (isset($limit, $offset) === true && $limit > 0) { $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); } @@ -1602,8 +1512,6 @@ function events_get_all( ('.$sql.') tbase'; } - hd($sql, true); - if ($count !== true) { if (is_metaconsole() === true) { $result_meta = []; @@ -1824,298 +1732,6 @@ function events_get_event($id, $fields=false, $meta=false, $history=false) } -/** - * Retrieve all events ungrouped. - * - * @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, - $meta=false, - $history=false, - $returnSql=false -) { - global $config; - - $table = 'tevento'; - - $sql = 'SELECT * FROM '.$table.' te '; - $sql .= events_get_secondary_groups_left_join($table); - $sql .= $sql_post; - - if ($returnSql === true) { - return $sql; - } - - hd($sql); - - $events = db_get_all_rows_sql($sql, $history); - - return $events; -} - - -/** - * Return all events matching sql_post grouped. - * - * @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 $sort_field Sort_field. - * - * @return mixed Array of events or false. - */ -function events_get_events_grouped( - $sql_post, - $offset=0, - $pagination=1, - $meta=false, - $history=false, - $total=false, - $history_db=false, - $order='down', - $sort_field='utimestamp' -) { - global $config; - - $table = 'tevento'; - - if ($meta) { - $groupby_extra = ', server_id'; - } else { - $groupby_extra = ''; - } - - if (is_metaconsole()) { - $id_source_event = get_parameter('id_source_event'); - if ($id_source_event != '') { - $sql_post .= "AND id_source_event = $id_source_event"; - } - } - - 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 ".$sql_post.' - GROUP BY estado, evento, id_agente, id_agentmodule'.$groupby_extra.') AS t'; - } else { - $sql = sprintf( - 'SELECT *, - MAX(id_evento) AS id_evento, - GROUP_CONCAT( - DISTINCT user_comment SEPARATOR "
" - ) 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. - $events = db_get_all_rows_sql($sql, $history_db); - - if ($total) { - return reset($events[0]); - } else { - return $events; - } -} - - -/** - * Return count of events grouped. - * - * @param string $sql_post Sql_post. - * @param boolean $meta Meta. - * @param boolean $history History. - * - * @return integer Number of events or false if failed. - */ -function events_get_total_events_grouped($sql_post, $meta=false, $history=false) -{ - return events_get_events_grouped($sql_post, 0, 0, $meta, $history, true); -} - - -/** - * Get all the events ids similar to a given event id. - * - * An event is similar then the event text (evento) and the id_agentmodule are - * the same. - * - * @param integer $id Event id to get similar events. - * @param boolean $meta Metaconsole mode flag. - * @param boolean $history History mode flag. - * - * @return array A list of events ids. - */ -function events_get_similar_ids($id, $meta=false, $history=false) -{ - $events_table = 'tevento'; - - $ids = []; - if ($meta) { - $event = events_meta_get_event( - $id, - [ - 'evento', - 'id_agentmodule', - ], - $history - ); - } else { - $event = events_get_event($id, ['evento', 'id_agentmodule']); - } - - if ($event === false) { - return $ids; - } - - $events = db_get_all_rows_filter( - $events_table, - [ - 'evento' => $event['evento'], - 'id_agentmodule' => $event['id_agentmodule'], - ], - ['id_evento'] - ); - if ($events === false) { - return $ids; - } - - foreach ($events as $event) { - $ids[] = $event['id_evento']; - } - - return $ids; -} - - -/** - * Delete events in a transresponse - * - * @param mixed $id_event Event ID or array of events. - * @param boolean $similar Whether to delete similar events too. - * @param boolean $meta Metaconsole mode flag. - * @param boolean $history History mode flag. - * - * @return boolean Whether or not it was successful - */ -function events_delete_event( - $id_event, - $similar=true, - $meta=false, - $history=false -) { - global $config; - - $table_event = 'tevento'; - - // Cleans up the selection for all unwanted values also casts any single values as an array. - $id_event = (array) safe_int($id_event, 1); - - // We must delete all events like the selected. - if ($similar) { - foreach ($id_event as $id) { - $id_event = array_merge( - $id_event, - events_get_similar_ids($id, $meta, $history) - ); - } - - $id_event = array_unique($id_event); - } - - $errors = 0; - - foreach ($id_event as $event) { - if ($meta) { - $event_group = events_meta_get_group($event, $history); - } else { - $event_group = events_get_group($event); - } - - if (check_acl($config['id_user'], $event_group, 'EM') == 0) { - // Check ACL. - db_pandora_audit( - AUDIT_LOG_ACL_VIOLATION, - 'Attempted deleting event #'.$event - ); - $errors++; - } else { - $ret = db_process_sql_delete($table_event, ['id_evento' => $event]); - - if (!$ret) { - $errors++; - } else { - db_pandora_audit( - AUDIT_LOG_ALERT_MANAGEMENT, - 'Deleted event #'.$event - ); - // ACL didn't fail nor did return. - continue; - } - } - - break; - } - - if ($errors > 0) { - return false; - } else { - return true; - } -} - - /** * Change the status of one or multiple events. * @@ -3034,88 +2650,6 @@ function events_print_type_description($type, $return=false) } -/** - * Get all the events happened in a group during a period of time. - * - * The returned events will be in the time interval ($date - $period, $date] - * - * @param mixed $begin Begin. - * @param mixed $result Result. - * @param mixed $id_group Group id to get events for. - * @param integer $period Period in seconds to get events. - * @param integer $date Beginning date to get events. - * @param boolean $filter_event_validated Filter_event_validated. - * @param boolean $filter_event_critical Filter_event_critical. - * @param boolean $filter_event_warning Filter_event_warning. - * @param boolean $filter_event_no_validated Filter_event_no_validated. - * - * @return array An array with all the events happened. - */ -function events_get_group_events_steps( - $begin, - &$result, - $id_group, - $period, - $date, - $filter_event_validated=false, - $filter_event_critical=false, - $filter_event_warning=false, - $filter_event_no_validated=false -) { - global $config; - - $id_group = groups_safe_acl($config['id_user'], $id_group, 'ER'); - - if (empty($id_group)) { - // An empty array means the user doesn't have access. - return false; - } - - $datelimit = ($date - $period); - - $sql_where = ' AND 1 = 1 '; - $criticities = []; - if ($filter_event_critical) { - $criticities[] = 4; - } - - if ($filter_event_warning) { - $criticities[] = 3; - } - - if (!empty($criticities)) { - $sql_where .= ' AND criticity IN ('.implode(', ', $criticities).')'; - } - - if ($filter_event_validated) { - $sql_where .= ' AND estado = 1 '; - } - - if ($filter_event_no_validated) { - $sql_where .= ' AND estado = 0 '; - } - - $sql = sprintf( - 'SELECT *, - (SELECT t2.nombre - FROM tagente t2 - WHERE t2.id_agente = t3.id_agente) AS agent_name, - (SELECT t2.fullname - FROM tusuario t2 - WHERE t2.id_user = t3.id_usuario) AS user_name - FROM tevento t3 - WHERE utimestamp > %d AND utimestamp <= %d - AND id_grupo IN (%s) '.$sql_where.' - ORDER BY utimestamp ASC', - $datelimit, - $date, - implode(',', $id_group) - ); - - return db_get_all_row_by_steps_sql($begin, $result, $sql); -} - - /** * Get all the events happened in an Agent during a period of time. * @@ -3211,7 +2745,6 @@ function events_get_agent( } if (empty($id_agent_module) === false) { - // TODO: XXX por id_agente_modulo. $filters['module_search'] = modules_get_agentmodule_name($id_agent_module); } @@ -3220,35 +2753,25 @@ function events_get_agent( } // Group by agent. - // TODO: XXX constants. - $filters['group_rep'] = 2; - - $max_register = 1000; - - // TODO: XXX - if ($show_summary_group) { - hd('tt'); - return events_get_events_grouped( - $sql_where, - 0, - $max_register, - is_metaconsole(), - false, - false, - $history - ); + if ((bool) $show_summary_group === true) { + $filters['group_rep'] = 1; } else { - $events = Event::search( - ['te.*'], - $filters, - 0, - $max_register, - 'desc', - 'te.utimestamp' - ); - - return $events['data']; + $filters['group_rep'] = 2; } + + $events = Event::search( + [ + 'te.*', + 'ta.alias', + ], + $filters, + 0, + 1000, + 'desc', + 'te.utimestamp' + ); + + return $events['data']; } @@ -4974,12 +4497,6 @@ function events_page_general($event) { global $img_sev; global $config; - - /* - Commented out (old) - // $group_rep = $event['similar_ids'] == -1 ? 1 : count(explode(',',$event['similar_ids'])); - */ - global $group_rep; $secondary_groups = ''; @@ -5428,1913 +4945,59 @@ function events_clean_tags($tags) /** * Get all the events happened in a group during a period of time. * - * The returned events will be in the time interval ($date - $period, $date] - * - * @param mixed $id_group Group id to get events for. - * @param integer $period Period in seconds to get events. - * @param integer $date Beginning date to get events. - * @param boolean $filter_event_severity Filter_event_severity. - * @param boolean $filter_event_type Filter_event_type. - * @param boolean $filter_event_status Filter_event_status. - * @param boolean $filter_event_filter_search Filter_event_filter_search. - * @param boolean $dbmeta Dbmeta. - * @param boolean $filter_event_filter_exclude Filter_event_filter_exclude. + * @param array $data Data. * * @return array An array with all the events happened. */ -function events_get_count_events_by_agent( - $id_group, - $period, - $date, - $filter_event_severity=false, - $filter_event_type=false, - $filter_event_status=false, - $filter_event_filter_search=false, - $dbmeta=false, - $filter_event_filter_exclude=false -) { - global $config; - - // Date. - if (!is_numeric($date)) { - $date = time_w_fixed_tz($date); - } - - if (empty($date)) { - $date = get_system_time(); - } - - // Group. - $id_group = groups_safe_acl($config['id_user'], $id_group, 'AR'); - - if (empty($id_group)) { - // An empty array means the user doesn't have access. - return false; - } - - $datelimit = ($date - $period); - - $sql_where = ''; - $severity_all = 0; - if (!empty($filter_event_severity)) { - foreach ($filter_event_severity as $key => $value) { - switch ($value) { - case -1: - $severity_all = 1; - break; - - case 34: - $filter_event_severity[$key] = '3, 4'; - break; - - case 20: - $filter_event_severity[$key] = '0, 1, 3, 4, 5, 6'; - break; - - case 21: - $filter_event_severity[$key] = '4, 2'; - break; - - default: - // Ignore. - break; - } - } - - if (!$severity_all) { - $sql_where .= ' AND criticity IN ('.implode(', ', $filter_event_severity).')'; - } - } - - $status_all = 0; - if (!empty($filter_event_status)) { - foreach ($filter_event_status as $key => $value) { - switch ($value) { - case -1: - $status_all = 1; - break; - - case 3: - $filter_event_status[$key] = ('0, 2'); - default: - // Ignore. - break; - } - } - - if (!$status_all) { - $sql_where .= ' AND estado IN ('.implode(', ', $filter_event_status).')'; - } - } - - if (!empty($filter_event_type) && $filter_event_type[0] != 'all') { - $sql_where .= ' AND ('; - $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. - // Shown to user only "warning, critical and normal". - if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { - $type[] = " event_type LIKE '%".$event_type."%' "; - } else if ($event_type == 'not_normal') { - $type[] = " (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; - } else if ($event_type != 'all') { - $type[] = " event_type = '".$event_type."'"; - } - } - } - - $sql_where .= implode(' OR ', $type).')'; - } - - if (!empty($filter_event_filter_search)) { - $sql_where .= ' AND (evento LIKE "%'.io_safe_input($filter_event_filter_search).'%" OR id_evento LIKE "%'.io_safe_input($filter_event_filter_search).'%")'; - } - - if (!empty($filter_event_filter_exclude)) { - $sql_where .= ' AND (evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%" AND id_evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%")'; - } - - $tagente = 'tagente'; - $tevento = 'tevento'; - $field_type = 'ta.id_agente'; - if ($dbmeta === true) { - $tagente = 'tmetaconsole_agent'; - $tevento = 'tmetaconsole_event'; - $field_type = 'ta.id_tagente'; - } - - $sql = sprintf( - 'SELECT - ta.id_agente, - ta.alias as agent_name, - count(*) as count - FROM %s te - %s - INNER JOIN %s ta - ON te.id_agente = %s - INNER JOIN tgrupo tg - 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 - GROUP BY ta.id_agente', - $tevento, - events_get_secondary_groups_left_join($tevento), - $tagente, - $field_type, - implode(',', $id_group), - implode(',', $id_group), - $datelimit, - $date, - $sql_where - ); - - $rows = db_get_all_rows_sql($sql); - - if ($rows == false) { - $rows = []; - } - - $return = []; - foreach ($rows as $row) { - $agent_name = $row['agent_name']; - if (empty($row['agent_name'])) { - $agent_name = __('Pandora System'); - } - - $return[$agent_name] = $row['count']; - } - - return $return; -} - - -/** - * Get all the events happened in a group during a period of time. - * - * The returned events will be in the time interval ($date - $period, $date] - * - * @param array $filter Use target filter. - * @param integer $period Period in seconds to get events. - * @param integer $date Beginning date to get events. - * @param boolean $filter_event_severity Filter_event_severity. - * @param boolean $filter_event_type Filter_event_type. - * @param boolean $filter_event_status Filter_event_status. - * @param boolean $filter_event_filter_search Filter_event_filter_search. - * @param boolean $dbmeta Dbmeta. - * @param boolean $filter_event_filter_exclude Filter_event_filter_exclude. - * - * @return array An array with all the events happened. - */ -function events_get_count_events_validated_by_user( - $filter, - $period, - $date, - $filter_event_severity=false, - $filter_event_type=false, - $filter_event_status=false, - $filter_event_filter_search=false, - $dbmeta=false, - $filter_event_filter_exclude=false -) { - global $config; - $tevento = 'tevento'; - if ($dbmeta === true) { - $tevento = 'tmetaconsole_event'; - } - - // Group. - $tgroup_join = ''; - if (isset($filter['id_group'])) { - $id_group = groups_safe_acl($config['id_user'], $filter['id_group'], 'AR'); - - if (empty($id_group)) { - // An empty array means the user doesn't have access. - return false; - } - - $tgroup_join = sprintf( - '%s - INNER JOIN tgrupo tg - 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))', - events_get_secondary_groups_left_join($tevento), - implode(',', $id_group), - implode(',', $id_group) - ); - } - - $sql_filter = ''; - if (!empty($filter['id_agent'])) { - $sql_filter .= sprintf(' AND id_agente = %d ', $filter['id_agent']); - } - - if (!empty($filter['id_agentmodule'])) { - $sql_filter .= sprintf(' AND id_agentmodule = %d ', $filter['id_agentmodule']); - } - - // Date. - if (!is_numeric($date)) { - $date = time_w_fixed_tz($date); - } - - if (empty($date)) { - $date = get_system_time(); - } - - $datelimit = ($date - $period); - - $sql_where = ''; - $severity_all = 0; - if (!empty($filter_event_severity)) { - foreach ($filter_event_severity as $key => $value) { - switch ($value) { - case -1: - $severity_all = 1; - break; - - case 34: - $filter_event_severity[$key] = '3, 4'; - break; - - case 20: - $filter_event_severity[$key] = '0, 1, 3, 4, 5, 6'; - break; - - case 21: - $filter_event_severity[$key] = '4, 2'; - break; - - default: - // Ignore. - break; - } - } - - if (!$severity_all) { - $sql_where .= ' AND criticity IN ('.implode(', ', $filter_event_severity).')'; - } - } - - $status_all = 0; - if (!empty($filter_event_status)) { - foreach ($filter_event_status as $key => $value) { - switch ($value) { - case -1: - $status_all = 1; - break; - - case 3: - $filter_event_status[$key] = ('0, 2'); - default: - // Ignore. - break; - } - } - - if (!$status_all) { - $sql_where .= ' AND estado IN ('.implode(', ', $filter_event_status).')'; - } - } - - if (!empty($filter_event_type) && $filter_event_type[0] != 'all') { - $sql_where .= ' AND ('; - $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. - // Shown to user only "warning, critical and normal". - if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { - $type[] = " event_type LIKE '%".$event_type."%' "; - } else if ($event_type == 'not_normal') { - $type[] = " (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; - } else if ($event_type != 'all') { - $type[] = " event_type = '".$event_type."'"; - } - } - } - - $sql_where .= implode(' OR ', $type).')'; - } - - if (!empty($filter_event_filter_search)) { - $sql_where .= ' AND (evento LIKE "%'.io_safe_input($filter_event_filter_search).'%" OR id_evento LIKE "%'.io_safe_input($filter_event_filter_search).'%")'; - } - - if (!empty($filter_event_filter_exclude)) { - $sql_where .= ' AND (evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%" AND id_evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%")'; - } - - $sql = sprintf( - 'SELECT - te.id_usuario, - tu.fullname as user_name, - count(*) as count - FROM %s te - %s - LEFT JOIN tusuario tu - ON te.owner_user = tu.id_user - WHERE - te.utimestamp > %d AND te.utimestamp <= %d - AND te.estado = %d - %s - GROUP BY te.id_usuario', - $tevento, - $tgroup_join, - $datelimit, - $date, - EVENT_VALIDATE, - $sql_filter, - $sql_where - ); - - $rows = db_get_all_rows_sql($sql); - - if ($rows == false) { - $rows = []; - } - - $return = []; - foreach ($rows as $row) { - $user_name = $row['user_name']; - if (empty($row['user_name'])) { - $user_name = __('Validated but not assigned'); - } - - $return[$user_name] = $row['count']; - } - - return $return; -} - - -/** - * Get all the events happened in a group during a period of time. - * - * The returned events will be in the time interval ($date - $period, $date] - * - * @param mixed $filter Target filter. - * @param integer $period Period in seconds to get events. - * @param integer $date Beginning date to get events. - * @param boolean $filter_event_severity Filter_event_severity. - * @param boolean $filter_event_type Filter_event_type. - * @param boolean $filter_event_status Filter_event_status. - * @param boolean $filter_event_filter_search Filter_event_filter_search. - * @param boolean $dbmeta Dbmeta. - * @param boolean $filter_event_filter_exclude Filter_event_filter_exclude. - * - * @return array An array with all the events happened. - */ -function events_get_count_events_by_criticity( - $filter, - $period, - $date, - $filter_event_severity=false, - $filter_event_type=false, - $filter_event_status=false, - $filter_event_filter_search=false, - $dbmeta=false, - $filter_event_filter_exclude=false -) { - global $config; - - $tevento = 'tevento'; - if ($dbmeta === true) { - $tevento = 'tmetaconsole_event'; - } - - $sql_filter = ''; - $tgroup_join = ''; - if (isset($filter['id_group'])) { - $id_group = groups_safe_acl($config['id_user'], $filter['id_group'], 'AR'); - - if (empty($id_group)) { - // An empty array means the user doesn't have access. - return false; - } - - $tgroup_join = sprintf( - '%s - INNER JOIN tgrupo tg - 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))', - events_get_secondary_groups_left_join($tevento), - implode(',', $id_group), - implode(',', $id_group) - ); - } - - if (!empty($filter['id_agent'])) { - $sql_filter .= sprintf(' AND id_agente = %d ', $filter['id_agent']); - } - - if (!empty($filter['id_agentmodule'])) { - $sql_filter .= sprintf(' AND id_agentmodule = %d ', $filter['id_agentmodule']); - } - - if (!is_numeric($date)) { - $date = time_w_fixed_tz($date); - } - - if (empty($date)) { - $date = get_system_time(); - } - - $datelimit = ($date - $period); - - $sql_where = ''; - $severity_all = 0; - if (!empty($filter_event_severity)) { - foreach ($filter_event_severity as $key => $value) { - switch ($value) { - case -1: - $severity_all = 1; - break; - - case 34: - $filter_event_severity[$key] = '3, 4'; - break; - - case 20: - $filter_event_severity[$key] = '0, 1, 3, 4, 5, 6'; - break; - - case 21: - $filter_event_severity[$key] = '4, 2'; - break; - - default: - // Ignore. - break; - } - } - - if (!$severity_all) { - $sql_where .= ' AND criticity IN ('.implode(', ', $filter_event_severity).')'; - } - } - - $status_all = 0; - if (!empty($filter_event_status)) { - foreach ($filter_event_status as $key => $value) { - switch ($value) { - case -1: - $status_all = 1; - break; - - case 3: - $filter_event_status[$key] = ('0, 2'); - break; - - default: - // Ignored. - break; - } - } - - if (!$status_all) { - $sql_where .= ' AND estado IN ('.implode(', ', $filter_event_status).')'; - } - } - - if (!empty($filter_event_type) && $filter_event_type[0] != 'all') { - $sql_where .= ' AND ('; - $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. - // Shown to user only "warning, critical and normal". - if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { - $type[] = " event_type LIKE '%".$event_type."%' "; - } else if ($event_type == 'not_normal') { - $type[] = " (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; - } else if ($event_type != 'all') { - $type[] = " event_type = '".$event_type."'"; - } - } - } - - $sql_where .= implode(' OR ', $type).')'; - } - - if (!empty($filter_event_filter_search)) { - $sql_where .= ' AND (evento LIKE "%'.io_safe_input($filter_event_filter_search).'%" OR id_evento LIKE "%'.io_safe_input($filter_event_filter_search).'%")'; - } - - if (!empty($filter_event_filter_exclude)) { - $sql_where .= ' AND (evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%" AND id_evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%")'; - } - - $sql = sprintf( - 'SELECT - te.criticity, - count(*) as count - FROM %s te - %s - WHERE - te.utimestamp > %d AND te.utimestamp <= %d - %s - %s - GROUP BY te.id_usuario', - $tevento, - $tgroup_join, - $datelimit, - $date, - $sql_filter, - $sql_where - ); - - $rows = db_get_all_rows_sql($sql); - - if ($rows == false) { - $rows = []; - } - - $return = []; - foreach ($rows as $row) { - $return[get_priority_name($row['criticity'])] = $row['count']; - } - - return $return; -} - - -/** - * Get all the events happened in a group during a period of time. - * - * The returned events will be in the time interval ($date - $period, $date] - * - * @param mixed $filter Target filter. - * @param integer $period Period in seconds to get events. - * @param integer $date Beginning date to get events. - * @param boolean $filter_event_severity Filter_event_severity. - * @param boolean $filter_event_type Filter_event_type. - * @param boolean $filter_event_status Filter_event_status. - * @param boolean $filter_event_filter_search Filter_event_filter_search. - * @param boolean $dbmeta Dbmeta. - * @param boolean $filter_event_filter_exclude Filter_event_filter_exclude. - * - * @return array An array with all the events happened. - */ -function events_get_count_events_validated( - $filter, - $period=null, - $date=null, - $filter_event_severity=false, - $filter_event_type=false, - $filter_event_status=false, - $filter_event_filter_search=false, - $dbmeta=false, - $filter_event_filter_exclude=false -) { - global $config; - $tevento = 'tevento'; - if ($dbmeta === true) { - $tevento = 'tmetaconsole_event'; - } - - // Group. - $sql_filter = ''; - $tgroup_join = ''; - if (isset($filter['id_group'])) { - $id_group = groups_safe_acl($config['id_user'], $filter['id_group'], 'AR'); - - if (empty($id_group)) { - // An empty array means the user doesn't have access. - return false; - } - - $tgroup_join = sprintf( - '%s - INNER JOIN tgrupo tg - 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))', - events_get_secondary_groups_left_join($tevento), - implode(',', $id_group), - implode(',', $id_group) - ); - } - - // Agent. - if (!empty($filter['id_agent'])) { - $sql_filter .= sprintf( - ' AND id_agente = %d ', - $filter['id_agent'] - ); - } - - // Module. - if (!empty($filter['id_agentmodule'])) { - $sql_filter .= sprintf( - ' AND id_agentmodule = %d ', - $filter['id_agentmodule'] - ); - } - - // Date. - if (!is_numeric($date)) { - $date = time_w_fixed_tz($date); - } - - if (empty($date)) { - $date = get_system_time(); - } - - $date_filter = ''; - if (!empty($date) && !empty($period)) { - $datelimit = ($date - $period); - - $date_filter .= sprintf( - ' AND utimestamp > %d AND utimestamp <= %d ', - $datelimit, - $date - ); - } else if (!empty($period)) { - $date = time(); - $datelimit = ($date - $period); - - $date_filter .= sprintf( - ' AND utimestamp > %d AND utimestamp <= %d ', - $datelimit, - $date - ); - } else if (!empty($date)) { - $date_filter .= sprintf(' AND utimestamp <= %d ', $date); - } - - $sql_where = ''; - $severity_all = 0; - if (!empty($filter_event_severity)) { - foreach ($filter_event_severity as $key => $value) { - switch ($value) { - case -1: - $severity_all = 1; - break; - - case 34: - $filter_event_severity[$key] = '3, 4'; - break; - - case 20: - $filter_event_severity[$key] = '0, 1, 3, 4, 5, 6'; - break; - - case 21: - $filter_event_severity[$key] = '4, 2'; - break; - - default: - // Ingore. - break; - } - } - - if (!$severity_all) { - $sql_where .= ' AND criticity IN ('.implode(', ', $filter_event_severity).')'; - } - } - - $status_all = 0; - if (!empty($filter_event_status)) { - foreach ($filter_event_status as $key => $value) { - switch ($value) { - case -1: - $status_all = 1; - break; - - case 3: - $filter_event_status[$key] = ('0, 2'); - break; - - default: - // Ignore. - break; - } - } - - if (!$status_all) { - $sql_where .= ' AND estado IN ('.implode(', ', $filter_event_status).')'; - } - } - - if (!empty($filter_event_type) && $filter_event_type[0] != 'all') { - $sql_where .= ' AND ('; - $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. - // Shown to user only "warning, critical and normal". - if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') { - $type[] = " event_type LIKE '%".$event_type."%' "; - } else if ($event_type == 'not_normal') { - $type[] = " (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; - } else if ($event_type != 'all') { - $type[] = " event_type = '".$event_type."'"; - } - } - } - - $sql_where .= implode(' OR ', $type).')'; - } - - if (!empty($filter_event_filter_search)) { - $sql_where .= ' AND (evento LIKE "%'.io_safe_input($filter_event_filter_search).'%" OR id_evento LIKE "%'.io_safe_input($filter_event_filter_search).'%")'; - } - - if (!empty($filter_event_filter_exclude)) { - $sql_where .= ' AND (evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%" AND id_evento NOT LIKE "%'.io_safe_input($filter_event_filter_exclude).'%")'; - } - - $sql = sprintf( - 'SELECT - te.estado, - count(*) as count - FROM %s te - %s - WHERE - te.utimestamp > %d AND te.utimestamp <= %d - %s - %s - GROUP BY te.id_usuario', - $tevento, - $tgroup_join, - $datelimit, - $date, - $sql_filter, - $sql_where - ); - - $rows = db_get_all_rows_sql($sql); - - if ($rows == false) { - $rows = []; - } - - $return = array_reduce( - $rows, - function ($carry, $item) { - $status = (int) $item['estado']; - $count = (int) $item['count']; - - if ($status === 1) { - $carry[__('Validated')] += $count; - } else if ($status === 0) { - $carry[__('Not validated')] += $count; - } - - return $carry; - }, - [ - __('Validated') => 0, - __('Not validated') => 0, - ] - ); - - return $return; -} - - -/** - * Check event tags. - * - * @param array $event_data Event. - * @param array $acltags Acl tags. - * - * @return boolean True or false. - */ -function events_checks_event_tags($event_data, $acltags) +function events_get_count_events_validated_by_user($data) { - global $config; + $data_graph_by_user = []; + if (empty($data) === false) { + foreach ($data as $value) { + $k = $value['id_usuario']; - if (empty($acltags[$event_data['id_grupo']])) { - return true; - } else { - $tags_arr_acl = explode(',', $acltags[$event_data['id_grupo']]); - $tags_arr_event = explode(',', $event_data['tags']); - - foreach ($tags_arr_acl as $tag) { - $tag_name = tags_get_name($tag); - if (in_array($tag_name, $tags_arr_event)) { - return true; - } else { - $has_tag = false; + if (empty($k) === true + && ($value['estado'] == EVENT_VALIDATE + || $value['status'] == EVENT_VALIDATE) + ) { + if (isset($data_graph_by_user['System']) === true) { + $data_graph_by_user['System']++; + } else { + $data_graph_by_user['System'] = 1; + } + } else if (empty($k) === false) { + if (isset($data_graph_by_user[$k]) === true) { + $data_graph_by_user[$k]++; + } else { + $data_graph_by_user[$k] = 1; + } } } - if (!$has_tag) { - return false; - } - } - - return false; -} - - -/** - * Retrieves events grouped by agent. - * - * @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. - * - * @return array Data. - */ -function events_get_events_grouped_by_agent( - $sql_post, - $offset=0, - $pagination=1, - $meta=false, - $history=false, - $total=false -) { - global $config; - - $table = 'tevento'; - - if ($meta) { - $fields_extra = ', agent_name, server_id'; - $groupby_extra = ', server_id'; - } else { - $groupby_extra = ''; - $fields_extra = ''; - } - - $event_lj = events_get_secondary_groups_left_join($table); - if ($total) { - $sql = 'SELECT COUNT(*) FROM (select id_agente from '.$table.' '.$event_lj.' WHERE 1=1 - '.$sql_post.' GROUP BY id_agente, event_type'.$groupby_extra.' ORDER BY id_agente ) AS t'; - } else { - $sql = 'select id_agente, count(*) as total'.$fields_extra.' from '.$table.' te '.$event_lj.' - WHERE id_agente > 0 '.$sql_post.' GROUP BY id_agente'.$groupby_extra.' ORDER BY id_agente LIMIT '.$offset.','.$pagination; - } - - $result = []; - // Extract the events by filter (or not) from db. - $events = db_get_all_rows_sql($sql); - $result = []; - - if ($events) { - foreach ($events as $event) { - if ($meta) { - $sql = 'SELECT event_type FROM '.$table.' te '.$event_lj." - WHERE agent_name = '".$event['agent_name']."' ".$sql_post.' ORDER BY utimestamp DESC '; - $resultado = db_get_row_sql($sql); - - $id_agente = $event['agent_name']; - $result[] = [ - 'total' => $event['total'], - 'id_server' => $event['server_id'], - 'id_agent' => $id_agente, - 'event_type' => $resultado['event_type'], - ]; - } else { - $sql = 'SELECT event_type FROM '.$table.' te '.$event_lj.' - WHERE id_agente = '.$event['id_agente'].' '.$sql_post.' ORDER BY utimestamp DESC '; - $resultado = db_get_row_sql($sql); - - $id_agente = $event['id_agente']; - $result[] = [ - 'total' => $event['total'], - 'id_agent' => $id_agente, - 'event_type' => $resultado['event_type'], - ]; - } - } - } - - return $result; -} - - -/** - * Return SQL query to group events by agents. - * - * @param mixed $id_agent Id_agent. - * @param integer $server_id Server_id. - * @param string $event_type Event_type. - * @param integer $severity Severity. - * @param integer $status Status. - * @param string $search Search. - * @param integer $id_agent_module Id_agent_module. - * @param integer $event_view_hr Event_view_hr. - * @param boolean $id_user_ack Id_user_ack. - * @param array $tag_with Tag_with. - * @param array $tag_without Tag_without. - * @param boolean $filter_only_alert Filter_only_alert. - * @param string $date_from Date_from. - * @param string $time_from Time_from. - * @param string $date_to Date_to. - * @param string $time_to Time_to. - * @param boolean $id_user Id_user. - * @param boolean $server_id_search Server_id_search. - * - * @return string SQL. - */ -function events_sql_events_grouped_agents( - $id_agent, - $server_id=-1, - $event_type='', - $severity=-1, - $status=3, - $search='', - $id_agent_module=0, - $event_view_hr=8, - $id_user_ack=false, - $tag_with=[], - $tag_without=[], - $filter_only_alert=false, - $date_from='', - $time_from='', - $date_to='', - $time_to='', - $id_user=false, - $server_id_search=false -) { - global $config; - - $sql_post = ' 1 = 1 '; - - $meta = false; - if (is_metaconsole()) { - $meta = true; - } - - switch ($status) { - case 0: - case 1: - case 2: - $sql_post .= ' AND estado = '.$status; - break; - - case 3: - $sql_post .= ' AND (estado = 0 OR estado = 2)'; - break; - - default: - // Ignore. - break; - } - - if ($search != '') { - $sql_post .= " AND (evento LIKE '%".io_safe_input($search)."%' OR id_evento LIKE '%".$search."%')"; - } - - if ($event_type != '') { - // 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') { - $sql_post .= " AND event_type LIKE '%".$event_type."%' "; - } else if ($event_type == 'not_normal') { - $sql_post .= " AND (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; - } else if ($event_type != 'all') { - $sql_post .= " AND event_type = '".$event_type."'"; - } - } - - if ($severity != -1) { - switch ($severity) { - case EVENT_CRIT_WARNING_OR_CRITICAL: - $sql_post .= ' - AND (criticity = '.EVENT_CRIT_WARNING.' OR - criticity = '.EVENT_CRIT_CRITICAL.')'; - break; - - case EVENT_CRIT_OR_NORMAL: - $sql_post .= ' - AND (criticity = '.EVENT_CRIT_NORMAL.' OR - criticity = '.EVENT_CRIT_CRITICAL.')'; - break; - - case EVENT_CRIT_NOT_NORMAL: - $sql_post .= ' AND criticity != '.EVENT_CRIT_NORMAL; - break; - - default: - $sql_post .= ' AND criticity = '.$severity; - break; - } - } - - // In metaconsole mode the agent search is performed by name. - if ($meta) { - if ($id_agent != __('All')) { - $sql_post .= " AND agent_name LIKE '%".$id_agent."%'"; - } - } else { - switch ($id_agent) { - case 0: - // Ignore. - $__invalid_value = 1; - break; - - case -1: - // Agent doesnt exist. No results will returned. - $sql_post .= ' AND 1 = 0'; - break; - - default: - $sql_post .= ' AND id_agente = '.$id_agent; - break; - } - } - - // There is another filter for if ($meta). - if (!$meta) { - if (!empty($text_module)) { - $sql_post .= " AND id_agentmodule IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre = '".$text_module."' - )"; - } - } - - if ($id_user_ack != '0') { - $sql_post .= " AND id_usuario = '".$id_user_ack."'"; - } - - if (isset($date_from) === false) { - $date_from = ''; - } - - if (isset($time_from) === false) { - $time_from = '00:00:00'; - } - - if (isset($date_to) === false) { - $date_to = ''; - } - - if (isset($time_to) === false || empty($time_to) === true) { - $time_to = '23:59:59'; - } - - if (($date_from == '') && ($date_to == '')) { - if ($event_view_hr > 0) { - $unixtime = (get_system_time() - ($event_view_hr * SECONDS_1HOUR)); - $sql_post .= ' AND (utimestamp > '.$unixtime.')'; - } - } else { - if (empty($date_from) === false) { - $udate_from = strtotime($date_from.' '.$time_from); - $sql_post .= ' AND (utimestamp >= '.$udate_from.')'; - } - - if (empty($date_to) === false) { - $udate_to = strtotime($date_to.' '.$time_to); - $sql_post .= ' AND (utimestamp <= '.$udate_to.')'; - } - } - - // Search by tag. - if (!empty($tag_with) && (io_safe_output($tag_with) != '[]') && (io_safe_output($tag_with) != '["0"]')) { - $sql_post .= ' AND ( '; - $first = true; - foreach ($tag_with as $id_tag) { - if ($first) { - $first = false; - } else { - $sql_post .= ' OR '; - } - - $sql_post .= "tags = '".tags_get_name($id_tag)."'"; - } - - $sql_post .= ' ) '; - } - - if (!empty($tag_without) && (io_safe_output($tag_without) != '[]') && (io_safe_output($tag_with) != '["0"]')) { - $sql_post .= ' AND ( '; - $first = true; - foreach ($tag_without as $id_tag) { - if ($first) { - $first = false; - } else { - $sql_post .= ' AND '; - } - - $sql_post .= "tags <> '".tags_get_name($id_tag)."'"; - } - - $sql_post .= ' ) '; - } - - // Filter/Only alerts. - if (isset($filter_only_alert)) { - if ($filter_only_alert == 0) { - $sql_post .= " AND event_type NOT LIKE '%alert%'"; - } else if ($filter_only_alert == 1) { - $sql_post .= " AND event_type LIKE '%alert%'"; - } - } - - // Tags ACLS. - if ($id_group > 0 && in_array($id_group, array_keys($groups))) { - $group_array = (array) $id_group; - } else { - $group_array = array_keys($groups); - } - - $tags_acls_condition = tags_get_acl_tags( - $id_user, - $group_array, - 'ER', - 'event_condition', - 'AND', - '', - $meta, - [], - true - ); - // 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 filters. - if ($meta) { - if ($server_id_search) { - $sql_post .= ' AND server_id = '.$server_id_search; - } else { - $enabled_nodes = db_get_all_rows_sql( - ' - SELECT id - FROM tmetaconsole_setup - WHERE disabled = 0' + if (empty($data_graph_by_user) === false) { + $sql = sprintf( + 'SELECT fullname, id_user + FROM tusuario + WHERE id_user IN ("%s")', + implode('","', array_keys($data_graph_by_user)) ); - if (empty($enabled_nodes)) { - $sql_post .= ' AND 1 = 0'; - } else { - if ($strict_user == 1) { - $enabled_nodes_id = []; - } else { - $enabled_nodes_id = [0]; - } - - foreach ($enabled_nodes as $en) { - $enabled_nodes_id[] = $en['id']; - } - - $sql_post .= ' AND server_id IN ('.implode(',', $enabled_nodes_id).')'; - } - } - } - - return $sql_post; -} - - -/** - * Retrieve list of events grouped by agents. - * - * @param string $sql SQL. - * - * @return string HTML. - */ -function events_list_events_grouped_agents($sql) -{ - global $config; - - $table = 'tevento'; - - $sql = sprintf( - 'SELECT * FROM %s - LEFT JOIN tagent_secondary_group - ON tagent_secondary_group.id_agent = id_agente - WHERE %s', - $table, - $sql - ); - - $result = db_get_all_rows_sql($sql); - $group_rep = 0; - $meta = is_metaconsole(); - - // Fields that the user has selected to show. - if ($meta) { - $show_fields = events_meta_get_custom_fields_user(); - } else { - $show_fields = explode(',', $config['event_fields']); - } - - // Headers. - $i = 0; - $table = new stdClass(); - if (!isset($table->width)) { - $table->width = '100%'; - } - - $table->id = 'eventtable'; - $table->cellpadding = 4; - $table->cellspacing = 4; - if (!isset($table->class)) { - $table->class = 'databox data'; - } - - $table->head = []; - $table->data = []; - - $table->head[$i] = __('ID'); - $table->align[$i] = 'left'; - $i++; - if (in_array('server_name', $show_fields)) { - $table->head[$i] = __('Server'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('estado', $show_fields)) { - $table->head[$i] = __('Status'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('id_evento', $show_fields)) { - $table->head[$i] = __('Event ID'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('evento', $show_fields)) { - $table->head[$i] = __('Event Name'); - $table->align[$i] = 'left'; - $table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;'; - $i++; - } - - if (in_array('id_agente', $show_fields)) { - $table->head[$i] = __('Agent name'); - $table->align[$i] = 'left'; - $table->style[$i] = 'max-width: 350px; word-break: break-all;'; - $i++; - } - - if (in_array('timestamp', $show_fields)) { - $table->head[$i] = __('Timestamp'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('id_usuario', $show_fields)) { - $table->head[$i] = __('User'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('owner_user', $show_fields)) { - $table->head[$i] = __('Owner'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('id_grupo', $show_fields)) { - $table->head[$i] = __('Group'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('event_type', $show_fields)) { - $table->head[$i] = __('Event type'); - $table->align[$i] = 'left'; - $table->style[$i] = 'min-width: 85px;'; - $i++; - } - - if (in_array('id_agentmodule', $show_fields)) { - $table->head[$i] = __('Agent Module'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('id_alert_am', $show_fields)) { - $table->head[$i] = __('Alert'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('criticity', $show_fields)) { - $table->head[$i] = __('Severity'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('user_comment', $show_fields)) { - $table->head[$i] = __('Comment'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('tags', $show_fields)) { - $table->head[$i] = __('Tags'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('source', $show_fields)) { - $table->head[$i] = __('Source'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('id_extra', $show_fields)) { - $table->head[$i] = __('Extra ID'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('ack_utimestamp', $show_fields)) { - $table->head[$i] = __('ACK Timestamp'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('instructions', $show_fields)) { - $table->head[$i] = __('Instructions'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('data', $show_fields)) { - $table->head[$i] = __('Data'); - $table->align[$i] = 'left'; - $i++; - } - - if (in_array('module_status', $show_fields)) { - $table->head[$i] = __('Module status'); - $table->align[$i] = 'left'; - $i++; - } - - if ($i != 0 && $allow_action) { - $table->head[$i] = __('Action'); - $table->align[$i] = 'left'; - $table->size[$i] = '90px'; - $i++; - if (check_acl($config['id_user'], 0, 'EW') == 1 && !$readonly) { - $table->head[$i] = html_print_checkbox('all_validate_box', '1', false, true); - $table->align[$i] = 'left'; - } - } - - if ($meta) { - // Get info of the all servers to use it on hash auth. - $servers_url_hash = metaconsole_get_servers_url_hash(); - $servers = metaconsole_get_servers(); - } - - $show_delete_button = false; - $show_validate_button = false; - - $idx = 0; - // Arrange data. We already did ACL's in the query. - foreach ($result as $event) { - $data = []; - - if ($meta) { - $event['server_url_hash'] = $servers_url_hash[$event['server_id']]; - $event['server_url'] = $servers[$event['server_id']]['server_url']; - $event['server_name'] = $servers[$event['server_id']]['server_name']; - } - - // Clean url from events and store in array. - $event['clean_tags'] = events_clean_tags($event['tags']); - - // First pass along the class of this row. - $myclass = get_priority_class($event['criticity']); - - // Print status. - $estado = $event['estado']; - - // Colored box. - switch ($estado) { - case EVENT_NEW: - $img_st = 'images/star.png'; - $title_st = __('New event'); - break; - - case EVENT_VALIDATE: - $img_st = 'images/tick.png'; - $title_st = __('Event validated'); - break; - - case EVENT_PROCESS: - $img_st = 'images/hourglass.png'; - $title_st = __('Event in process'); - break; - - default: - // Ignore. - break; - } - - $i = 0; - - $data[$i] = '#'.$event['id_evento']; - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3; color: #111 !important;'; - - // Pass grouped values in hidden fields to use it from modal window. - if ($group_rep) { - $similar_ids = $event['similar_ids']; - $timestamp_first = $event['timestamp_rep_min']; - $timestamp_last = $event['timestamp_rep']; - } else { - $similar_ids = $event['id_evento']; - $timestamp_first = $event['utimestamp']; - $timestamp_last = $event['utimestamp']; - } - - // Store group data to show in extended view. - $data[$i] .= html_print_input_hidden('similar_ids_'.$event['id_evento'], $similar_ids, true); - $data[$i] .= html_print_input_hidden('timestamp_first_'.$event['id_evento'], $timestamp_first, true); - $data[$i] .= html_print_input_hidden('timestamp_last_'.$event['id_evento'], $timestamp_last, true); - $data[$i] .= html_print_input_hidden('childrens_ids', json_encode($childrens_ids), true); - - // Store server id if is metaconsole. 0 otherwise. - if ($meta) { - $server_id = $event['server_id']; - - // If meta activated, propagate the id of the event on node (source id). - $data[$i] .= html_print_input_hidden('source_id_'.$event['id_evento'], $event['id_source_event'], true); - $table->cellclass[count($table->data)][$i] = $myclass; - } else { - $server_id = 0; - } - - $data[$i] .= html_print_input_hidden('server_id_'.$event['id_evento'], $server_id, true); - - if (empty($event['event_rep'])) { - $event['event_rep'] = 0; - } - - $data[$i] .= html_print_input_hidden('event_rep_'.$event['id_evento'], $event['event_rep'], true); - // Store concat comments to show in extended view. - $data[$i] .= html_print_input_hidden('user_comment_'.$event['id_evento'], base64_encode($event['user_comment']), true); - - $i++; - - if (in_array('server_name', $show_fields)) { - if ($meta) { - if (can_user_access_node()) { - $data[$i] = "".$event['server_name'].''; - } else { - $data[$i] = $event['server_name']; - } - } else { - $data[$i] = db_get_value('name', 'tserver'); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('estado', $show_fields)) { - $data[$i] = html_print_image( - $img_st, - true, - [ - 'class' => 'image_status', - 'title' => $title_st, - 'id' => 'status_img_'.$event['id_evento'], - ] - ); - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; - $i++; - } - - if (in_array('id_evento', $show_fields)) { - $data[$i] = $event['id_evento']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - switch ($event['criticity']) { - default: - case 0: - $img_sev = 'images/status_sets/default/severity_maintenance.png'; - break; - case 1: - $img_sev = 'images/status_sets/default/severity_informational.png'; - break; - - case 2: - $img_sev = 'images/status_sets/default/severity_normal.png'; - break; - - case 3: - $img_sev = 'images/status_sets/default/severity_warning.png'; - break; - - case 4: - $img_sev = 'images/status_sets/default/severity_critical.png'; - break; - - case 5: - $img_sev = 'images/status_sets/default/severity_minor.png'; - break; - - case 6: - $img_sev = 'images/status_sets/default/severity_major.png'; - break; - } - - if (in_array('evento', $show_fields)) { - // Event description. - $data[$i] = ''; - if ($allow_action) { - $data[$i] .= ''; - } - - $data[$i] .= ''.ui_print_truncate_text(io_safe_output($event['evento']), 160).''; - if ($allow_action) { - $data[$i] .= ''; - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_agente', $show_fields)) { - $data[$i] = ''; - - if ($event['id_agente'] > 0) { - // Agent name. - if ($meta) { - $agent_link = ''; - if (can_user_access_node()) { - $data[$i] = ''.$agent_link.$event['agent_name'].''; - } else { - $data[$i] = $event['agent_name']; - } - } else { - $data[$i] .= ui_print_agent_name($event['id_agente'], true); - } - } else { - $data[$i] .= ''; - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('timestamp', $show_fields)) { - // Time. - $data[$i] = ''; - if ($group_rep == 1) { - $data[$i] .= ui_print_timestamp($event['timestamp_rep'], true); - } else { - $data[$i] .= ui_print_timestamp($event['timestamp'], true); - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_usuario', $show_fields)) { - $user_name = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); - if (empty($user_name)) { - $user_name = $event['id_usuario']; - } - - $data[$i] = $user_name; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('owner_user', $show_fields)) { - $owner_name = db_get_value('fullname', 'tusuario', 'id_user', $event['owner_user']); - if (empty($owner_name)) { - $owner_name = $event['owner_user']; - } - - $data[$i] = $owner_name; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_grupo', $show_fields)) { - if ($meta) { - $data[$i] = $event['group_name']; - } else { - $id_group = $event['id_grupo']; - $group_name = db_get_value('nombre', 'tgrupo', 'id_grupo', $id_group); - if ($id_group == 0) { - $group_name = __('All'); - } - - $data[$i] = $group_name; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('event_type', $show_fields)) { - $data[$i] = events_print_type_description($event['event_type'], true); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_agentmodule', $show_fields)) { - if ($meta) { - $module_link = ''; - if (can_user_access_node()) { - $data[$i] = ''.$module_link.$event['module_name'].''; - } else { - $data[$i] = $event['module_name']; - } - } else { - $module_name = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); - $data[$i] = ''.$module_name.''; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_alert_am', $show_fields)) { - if ($meta) { - $data[$i] = $event['alert_template_name']; - } else { - if ($event['id_alert_am'] != 0) { - $sql = 'SELECT name - FROM talert_templates - WHERE id IN (SELECT id_alert_template - FROM talert_template_modules - WHERE id = '.$event['id_alert_am'].');'; - - $templateName = db_get_sql($sql); - $data[$i] = ''.$templateName.''; - } else { - $data[$i] = ''; - } - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('criticity', $show_fields)) { - $data[$i] = get_priority_name($event['criticity']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('user_comment', $show_fields)) { - $safe_event_user_comment = strip_tags(io_safe_output($event['user_comment'])); - $line_breaks = [ - "\r\n", - "\n", - "\r", - ]; - $safe_event_user_comment = str_replace($line_breaks, '
', $safe_event_user_comment); - $event_user_comments = json_decode($safe_event_user_comment, true); - $event_user_comment_str = ''; - - if (!empty($event_user_comments)) { - $last_key = key(array_slice($event_user_comments, -1, 1, true)); - $date_format = $config['date_format']; - - foreach ($event_user_comments as $key => $event_user_comment) { - $event_user_comment_str .= sprintf( - '%s: %s
%s: %s
%s: %s
', - __('Date'), - date($date_format, $event_user_comment['utimestamp']), - __('User'), - $event_user_comment['id_user'], - __('Comment'), - $event_user_comment['comment'] - ); - if ($key != $last_key) { - $event_user_comment_str .= '
'; + $fullnames = db_get_all_rows_sql($sql); + + if ($fullnames !== false + && empty($fullnames) === false + ) { + foreach ($fullnames as $value) { + if (isset($data_graph_by_user[$value['id_user']]) === true) { + $data_graph_by_user[$value['fullname']] = $data_graph_by_user[$value['id_user']]; + unset($data_graph_by_user[$value['id_user']]); } } } - - $comments_help_tip = ''; - if (!empty($event_user_comment_str)) { - $comments_help_tip = ui_print_help_tip($event_user_comment_str, true); - } - - $data[$i] = ''.$comments_help_tip.''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; } - - if (in_array('tags', $show_fields)) { - $data[$i] = tags_get_tags_formatted($event['tags']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('source', $show_fields)) { - $data[$i] = $event['source']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('id_extra', $show_fields)) { - $data[$i] = $event['id_extra']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('ack_utimestamp', $show_fields)) { - if ($event['ack_utimestamp'] == 0) { - $data[$i] = ''; - } else { - $data[$i] = date($config['date_format'], $event['ack_utimestamp']); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('instructions', $show_fields)) { - switch ($event['event_type']) { - case 'going_unknown': - if (!empty($event['unknown_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['unknown_instructions']))]); - } - break; - - case 'going_up_critical': - case 'going_down_critical': - if (!empty($event['critical_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['critical_instructions']))]); - } - break; - - case 'going_down_warning': - if (!empty($event['warning_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['warning_instructions']))]); - } - break; - - case 'system': - if (!empty($event['critical_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['critical_instructions']))]); - } else if (!empty($event['warning_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['warning_instructions']))]); - } else if (!empty($event['unknown_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['title' => str_replace("\n", '
', io_safe_output($event['unknown_instructions']))]); - } - break; - - default: - // Ignore. - break; - } - - if (!isset($data[$i])) { - $data[$i] = ''; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('data', $show_fields)) { - $data[$i] = $event['data']; - if (($data[$i] % 1) == 0) { - $data[$i] = number_format($data[$i], 0); - } else { - $data[$i] = number_format($data[$i], 2); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if (in_array('module_status', $show_fields)) { - $data[$i] = modules_get_modules_status($event['module_status']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($i != 0 && $allow_action) { - // Actions. - $data[$i] = ''; - - if (!$readonly) { - // Validate event. - if (($event['estado'] != 1) && (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EW', $event['clean_tags'], $childrens_ids))) { - $show_validate_button = true; - $data[$i] .= ''; - $data[$i] .= html_print_image( - 'images/ok.png', - true, - ['title' => __('Validate event')] - ); - $data[$i] .= ''; - } - - // Delete event. - if ((tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EM', $event['clean_tags'], $childrens_ids) == 1)) { - if ($event['estado'] != 2) { - $show_delete_button = true; - $data[$i] .= ''; - $data[$i] .= html_print_image( - 'images/cross.png', - true, - [ - 'title' => __('Delete event'), - 'id' => 'delete_cross_'.$event['id_evento'], - ] - ); - $data[$i] .= ''; - } else { - $data[$i] .= html_print_image( - 'images/cross.disabled.png', - true, - ['title' => __('Is not allowed delete events in process')] - ).' '; - } - } - } - - $data[$i] .= ''; - $data[$i] .= html_print_input_hidden('event_title_'.$event['id_evento'], '#'.$event['id_evento'].' - '.$event['evento'], true); - $data[$i] .= html_print_image( - 'images/eye.png', - true, - ['title' => __('Show more')] - ); - $data[$i] .= ''; - - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; - - $i++; - - if (!$readonly) { - if (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EM', $event['clean_tags'], $childrens_ids) == 1) { - // Checkbox. - // Class 'candeleted' must be the fist class to be parsed from javascript. Dont change. - $data[$i] = html_print_checkbox_extended('validate_ids[]', $event['id_evento'], false, false, false, 'class="candeleted chk_val"', true); - } else if (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EW', $event['clean_tags'], $childrens_ids) == 1) { - // Checkbox. - $data[$i] = html_print_checkbox_extended('validate_ids[]', $event['id_evento'], false, false, false, 'class="chk_val"', true); - } else if (isset($table->header[$i]) || true) { - $data[$i] = ''; - } - } - - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; - } - - array_push($table->data, $data); - - $idx++; } - return html_print_table($table, true); + return $data_graph_by_user; } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d9493a99b2..99dd0cad88 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -3286,73 +3286,6 @@ function series_suffix_leyend($series_name, $series_suffix, $id_agent, $data_mod } -function graph_events_validated($width=300, $height=200, $extra_filters=[], $meta=false, $history=false) -{ - global $config; - global $graphic_type; - - $event_type = false; - if (array_key_exists('event_type', $extra_filters)) { - $event_type = $extra_filters['event_type']; - } - - $event_severity = false; - if (array_key_exists('event_severity', $extra_filters)) { - $event_severity = $extra_filters['event_severity']; - } - - $event_status = false; - if (array_key_exists('event_status', $extra_filters)) { - $event_status = $extra_filters['event_status']; - } - - $event_filter_search = false; - if (array_key_exists('event_filter_search', $extra_filters)) { - $event_filter_search = $extra_filters['event_filter_search']; - } - - $data_graph = events_get_count_events_validated( - ['id_group' => array_keys(users_get_groups())], - null, - null, - $event_severity, - $event_type, - $event_status, - $event_filter_search - ); - - $colors = []; - foreach ($data_graph as $k => $v) { - if ($k == __('Validated')) { - $colors[$k] = COL_NORMAL; - } else { - $colors[$k] = COL_CRITICAL; - } - } - - if ($config['fixed_graph'] == false) { - $water_mark = [ - 'file' => $config['homedir'].'/images/logo_vertical_water.png', - 'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false), - ]; - } - - echo pie_graph( - $data_graph, - $width, - $height, - __('other'), - '', - $water_mark, - $config['fontpath'], - $config['font_size'], - 1, - 'bottom', - $colors - ); -} - - /** * Print a pie graph with events data of group * @@ -3365,13 +3298,13 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr global $config; global $graphic_type; - // It was urlencoded, so we urldecode it + // It was urlencoded, so we urldecode it. $url = html_entity_decode(rawurldecode($url), ENT_QUOTES); $data = []; $loop = 0; define('NUM_PIECES_PIE', 6); - // Hotfix for the id_agente_modulo + // Hotfix for the id_agente_modulo. $url = str_replace( 'SELECT id_agente_modulo', 'SELECT_id_agente_modulo', @@ -3386,22 +3319,24 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr 'INSERT ', 'EXEC', ]; - // remove bad strings from the query so queries like ; DELETE FROM don't pass + // remove bad strings from the query so queries like ; DELETE FROM don't pass. $url = str_ireplace($badstrings, '', $url); - // Hotfix for the id_agente_modulo + // Hotfix for the id_agente_modulo. $url = str_replace( 'SELECT_id_agente_modulo', 'SELECT id_agente_modulo', $url ); - $event_table = 'tevento'; - $field_extra = ''; - $groupby_extra = ''; - - // Add tags condition to filter - $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); + // Add tags condition to filter. + $tags_condition = tags_get_acl_tags( + $config['id_user'], + 0, + 'ER', + 'event_condition', + 'AND' + ); if ($time_limit && $config['event_view_hr']) { $tags_condition .= ' AND utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')'; @@ -3409,14 +3344,14 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr // This will give the distinct id_agente, give the id_grupo that goes // with it and then the number of times it occured. GROUP BY statement - // is required if both DISTINCT() and COUNT() are in the statement + // is required if both DISTINCT() and COUNT() are in the statement. $sql = sprintf( 'SELECT DISTINCT(id_agente) AS id_agente, - COUNT(id_agente) AS count'.$field_extra.' - FROM '.$event_table.' te LEFT JOIN tagent_secondary_group tasg + COUNT(id_agente) AS count + FROM tevento te LEFT JOIN tagent_secondary_group tasg ON te.id_grupo = tasg.id_group WHERE 1=1 %s %s - GROUP BY id_agente'.$groupby_extra.' + GROUP BY id_agente ORDER BY count DESC LIMIT 8', $url, $tags_condition @@ -3456,7 +3391,7 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr $data[$name] = $system_events; } - // Sort the data + // Sort the data. arsort($data); if ($noWaterMark) { $water_mark = [ diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index edc47dc02b..157cbf7b7b 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -67,6 +67,7 @@ define('REPORT_STATUS_DOWNTIME', 4); define('REPORT_STATUS_IGNORED', 5); // Clases. +use PandoraFMS\Event; use PandoraFMS\Module; @@ -1959,7 +1960,10 @@ function reporting_event_report_group( $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated']; - if (isset($content['recursion']) && $content['recursion'] == 1 && $content['id_group'] != 0) { + if (isset($content['recursion']) + && $content['recursion'] == 1 + && $content['id_group'] != 0 + ) { $propagate = db_get_value( 'propagate', 'tgrupo', @@ -2029,27 +2033,26 @@ function reporting_event_report_group( $return['chart']['by_user_validator'] = null; $return['chart']['by_criticity'] = null; $return['chart']['validated_vs_unvalidated'] = null; - $server_name = $content['server_name']; - $metaconsole_dbtable = false; - if (is_metaconsole() === true && empty($server_name) === true) { - $metaconsole_dbtable = true; - } if ($event_graph_by_agent) { - $data_graph = events_get_count_events_by_agent( - $content['id_group'], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_agent = []; + if (empty($data) === false) { + foreach ($data as $value) { + $k = $value['alias']; + if (is_metaconsole() === true) { + $k = '('.$value['server_name'].') '.$value['alias']; + } + + if (isset($data_graph_by_agent[$k]) === true) { + $data_graph_by_agent[$k]++; + } else { + $data_graph_by_agent[$k] = 1; + } + } + } $return['chart']['by_agent'] = pie_graph( - $data_graph, + $data_graph_by_agent, 500, 150, __('other'), @@ -2062,20 +2065,9 @@ function reporting_event_report_group( } if ($event_graph_by_user_validator) { - $data_graph = events_get_count_events_validated_by_user( - ['id_group' => $content['id_group']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); - + $data_graph_by_user = events_get_count_events_validated_by_user($data); $return['chart']['by_user_validator'] = pie_graph( - $data_graph, + $data_graph_by_user, 500, 150, __('other'), @@ -2088,21 +2080,22 @@ function reporting_event_report_group( } if ($event_graph_by_criticity) { - $data_graph = events_get_count_events_by_criticity( - ['id_group' => $content['id_group']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable - ); + $data_graph_by_criticity = []; + if (empty($data) === false) { + foreach ($data as $value) { + $k = get_priority_name($value['criticity']); + if (isset($data_graph_by_criticity[$k]) === true) { + $data_graph_by_criticity[$k]++; + } else { + $data_graph_by_criticity[$k] = 1; + } + } + } - $colors = get_criticity_pie_colors($data_graph); + $colors = get_criticity_pie_colors($data_graph_by_criticity); $return['chart']['by_criticity'] = pie_graph( - $data_graph, + $data_graph_by_criticity, 500, 150, __('other'), @@ -2117,20 +2110,24 @@ function reporting_event_report_group( } if ($event_graph_validated_vs_unvalidated) { - $data_graph = events_get_count_events_validated( - ['id_group' => $content['id_group']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_status = []; + if (empty($data) === false) { + $status = [ + 1 => __('Validated'), + 0 => __('Not validated'), + ]; + foreach ($data as $value) { + $k = $status[$value['estado']]; + if (isset($data_graph_by_status[$k]) === true) { + $data_graph_by_status[$k]++; + } else { + $data_graph_by_status[$k] = 1; + } + } + } $return['chart']['validated_vs_unvalidated'] = pie_graph( - $data_graph, + $data_graph_by_status, 500, 150, __('other'), @@ -2142,10 +2139,6 @@ function reporting_event_report_group( ); } - if (is_metaconsole() === true) { - metaconsole_restore_db(); - } - // Total events. if ($return['data'] != '') { $return['total_events'] = count($return['data']); @@ -3670,15 +3663,29 @@ function reporting_groups_nodes($content) if (empty($id_group)) { $events = []; } else { - $sql_where = sprintf( - ' WHERE id_grupo IN (%s) AND estado<>1 ', - implode(',', $id_group) - ); - $events = events_get_events_grouped( - $sql_where, + // ID group. + if (empty($id_group) === false) { + $filters['id_group_filter'] = $id_group; + } + + // Status. + if (empty($filter_event_status) === false) { + $filters['status'] = EVENT_NO_VALIDATED; + } + + // Grouped. + $filters['group_rep'] = 1; + + $events = Event::search( + [ + 'te.*', + 'ta.alias', + ], + $filters, 0, 1000, - false + 'desc', + 'te.utimestamp' ); } @@ -3835,28 +3842,10 @@ function reporting_event_report_agent( $return['chart']['by_criticity'] = null; $return['chart']['validated_vs_unvalidated'] = null; - $server_name = $content['server_name']; - if (is_metaconsole() && $server_name != '') { - $metaconsole_dbtable = true; - } else { - $metaconsole_dbtable = false; - } - if ($event_graph_by_user_validator) { - $data_graph = events_get_count_events_validated_by_user( - ['id_agent' => $content['id_agent']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); - + $data_graph_by_user = events_get_count_events_validated_by_user($return['data']); $return['chart']['by_user_validator'] = pie_graph( - $data_graph, + $data_graph_by_user, 500, 150, __('other'), @@ -3869,22 +3858,22 @@ function reporting_event_report_agent( } if ($event_graph_by_criticity) { - $data_graph = events_get_count_events_by_criticity( - ['id_agent' => $content['id_agent']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_criticity = []; + if (empty($return['data']) === false) { + foreach ($return['data'] as $value) { + $k = get_priority_name($value['criticity']); + if (isset($data_graph_by_criticity[$k]) === true) { + $data_graph_by_criticity[$k]++; + } else { + $data_graph_by_criticity[$k] = 1; + } + } + } - $colors = get_criticity_pie_colors($data_graph); + $colors = get_criticity_pie_colors($data_graph_by_criticity); $return['chart']['by_criticity'] = pie_graph( - $data_graph, + $data_graph_by_criticity, 500, 150, __('other'), @@ -3899,20 +3888,24 @@ function reporting_event_report_agent( } if ($event_graph_validated_vs_unvalidated) { - $data_graph = events_get_count_events_validated( - ['id_agent' => $content['id_agent']], - $content['period'], - $report['datetime'], - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_status = []; + if (empty($return['data']) === false) { + $status = [ + 1 => __('Validated'), + 0 => __('Not validated'), + ]; + foreach ($return['data'] as $value) { + $k = $status[$value['estado']]; + if (isset($data_graph_by_status[$k]) === true) { + $data_graph_by_status[$k]++; + } else { + $data_graph_by_status[$k] = 1; + } + } + } $return['chart']['validated_vs_unvalidated'] = pie_graph( - $data_graph, + $data_graph_by_status, 500, 150, __('other'), @@ -10478,20 +10471,9 @@ function reporting_get_module_detailed_event( } if ($event_graph_by_user_validator) { - $data_graph = events_get_count_events_validated_by_user( - ['id_agentmodule' => $id_module], - $period, - $date, - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); - + $data_graph_by_user = events_get_count_events_validated_by_user($event['data']); $event['chart']['by_user_validator'] = pie_graph( - $data_graph, + $data_graph_by_user, 500, 150, __('other'), @@ -10504,22 +10486,22 @@ function reporting_get_module_detailed_event( } if ($event_graph_by_criticity) { - $data_graph = events_get_count_events_by_criticity( - ['id_agentmodule' => $id_module], - $period, - $date, - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_criticity = []; + if (empty($event['data']) === false) { + foreach ($event['data'] as $value) { + $k = get_priority_name($value['criticity']); + if (isset($data_graph_by_criticity[$k]) === true) { + $data_graph_by_criticity[$k]++; + } else { + $data_graph_by_criticity[$k] = 1; + } + } + } - $colors = get_criticity_pie_colors($data_graph); + $colors = get_criticity_pie_colors($data_graph_by_criticity); $event['chart']['by_criticity'] = pie_graph( - $data_graph, + $data_graph_by_criticity, 500, 150, __('other'), @@ -10534,20 +10516,24 @@ function reporting_get_module_detailed_event( } if ($event_graph_validated_vs_unvalidated) { - $data_graph = events_get_count_events_validated( - ['id_agentmodule' => $id_module], - $period, - $date, - $filter_event_severity, - $filter_event_type, - $filter_event_status, - $filter_event_filter_search, - $metaconsole_dbtable, - $filter_event_filter_exclude - ); + $data_graph_by_status = []; + if (empty($event['data']) === false) { + $status = [ + 1 => __('Validated'), + 0 => __('Not validated'), + ]; + foreach ($event['data'] as $value) { + $k = $status[$value['estado']]; + if (isset($data_graph_by_status[$k]) === true) { + $data_graph_by_status[$k]++; + } else { + $data_graph_by_status[$k] = 1; + } + } + } $event['chart']['validated_vs_unvalidated'] = pie_graph( - $data_graph, + $data_graph_by_status, 500, 150, __('other'), @@ -10664,6 +10650,7 @@ function reporting_get_agents_detailed_event( 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp'], 'id_evento' => $e['id_evento'], + 'id_usuario' => $e['id_usuario'], 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', ]; } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index e8502376c1..6f3fe071a7 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1068,20 +1068,26 @@ function reporting_html_event_report_group($table, $item, $pdf=0) foreach ($item['data'] as $k => $event) { // First pass along the class of this row. if ($item['show_summary_group']) { - $table1->cellclass[$k][1] = $table1->cellclass[$k][2] = $table1->cellclass[$k][4] = $table1->cellclass[$k][5] = $table1->cellclass[$k][6] = $table1->cellclass[$k][7] = get_priority_class($event['criticity']); + $table1->cellclass[$k][1] = get_priority_class($event['criticity']); + $table1->cellclass[$k][2] = get_priority_class($event['criticity']); + $table1->cellclass[$k][4] = get_priority_class($event['criticity']); + $table1->cellclass[$k][5] = get_priority_class($event['criticity']); + $table1->cellclass[$k][6] = get_priority_class($event['criticity']); + $table1->cellclass[$k][7] = get_priority_class($event['criticity']); + $table1->cellclass[$k][8] = get_priority_class($event['criticity']); } else { - $table1->cellclass[$k][1] = $table1->cellclass[$k][3] = $table1->cellclass[$k][4] = $table1->cellclass[$k][5] = $table1->cellclass[$k][6] = get_priority_class($event['criticity']); + $table1->cellclass[$k][1] = get_priority_class($event['criticity']); + $table1->cellclass[$k][3] = get_priority_class($event['criticity']); + $table1->cellclass[$k][4] = get_priority_class($event['criticity']); + $table1->cellclass[$k][5] = get_priority_class($event['criticity']); + $table1->cellclass[$k][6] = get_priority_class($event['criticity']); + $table1->cellclass[$k][7] = get_priority_class($event['criticity']); } $data = []; // Colored box. switch ($event['estado']) { - case 0: - $img_st = 'images/star.png'; - $title_st = __('New event'); - break; - case 1: $img_st = 'images/tick.png'; $title_st = __('Event validated'); @@ -1091,6 +1097,12 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $img_st = 'images/hourglass.png'; $title_st = __('Event in process'); break; + + default: + case 0: + $img_st = 'images/star.png'; + $title_st = __('New event'); + break; } $data[] = html_print_image( @@ -1117,17 +1129,29 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $data[] = events_print_type_img($event['event_type'], true); - if (!empty($event['id_agente'])) { - $data[] = agents_get_alias($event['id_agente']); + if (empty($event['alias']) === false) { + $alias = $event['alias']; + if (is_metaconsole() === true) { + $alias = '('.$event['server_name'].') '.$event['alias']; + } + + $data[] = $alias; } else { $data[] = __('%s System', get_product_name()); } $data[] = get_priority_name($event['criticity']); - if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + if (empty($event['id_usuario']) === true + && $event['estado'] == EVENT_VALIDATE + ) { $data[] = ''.__('System').''; } else { - $user_name = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $user_name = db_get_value( + 'fullname', + 'tusuario', + 'id_user', + $event['id_usuario'] + ); $data[] = io_safe_output($user_name); } @@ -1138,10 +1162,14 @@ function reporting_html_event_report_group($table, $item, $pdf=0) } if ($show_custom_data === true) { - $custom_data = json_decode($event['custom_data'], true); $custom_data_text = ''; - foreach ($custom_data as $key => $value) { - $custom_data_text .= $key.' = '.$value.'
'; + if (empty($event['custom_data']) === false) { + $custom_data = json_decode($event['custom_data'], true); + if (empty($custom_data) === false) { + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + } } $data[] = $custom_data_text; @@ -1306,9 +1334,17 @@ function reporting_html_event_report_module($table, $item, $pdf=0) foreach ($item_data as $i => $event) { $data = []; if ($show_summary_group) { - $table1->cellclass[$i][1] = $table1->cellclass[$i][2] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = $table1->cellclass[$i][5] = get_priority_class($event['criticity']); + $table1->cellclass[$i][1] = get_priority_class($event['criticity']); + $table1->cellclass[$i][2] = get_priority_class($event['criticity']); + $table1->cellclass[$i][3] = get_priority_class($event['criticity']); + $table1->cellclass[$i][4] = get_priority_class($event['criticity']); + $table1->cellclass[$i][5] = get_priority_class($event['criticity']); + $table1->cellclass[$i][6] = get_priority_class($event['criticity']); } else { - $table1->cellclass[$i][1] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = get_priority_class($event['criticity']); + $table1->cellclass[$i][1] = get_priority_class($event['criticity']); + $table1->cellclass[$i][3] = get_priority_class($event['criticity']); + $table1->cellclass[$i][4] = get_priority_class($event['criticity']); + $table1->cellclass[$i][6] = get_priority_class($event['criticity']); } // Colored box. @@ -2397,9 +2433,18 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) foreach ($item['data'] as $i => $event) { if ($item['show_summary_group']) { - $table1->cellclass[$i][1] = $table1->cellclass[$i][2] = $table1->cellclass[$i][4] = $table1->cellclass[$i][5] = $table1->cellclass[$i][6] = get_priority_class($event['criticity']); + $table1->cellclass[$i][1] = get_priority_class($event['criticity']); + $table1->cellclass[$i][2] = get_priority_class($event['criticity']); + $table1->cellclass[$i][4] = get_priority_class($event['criticity']); + $table1->cellclass[$i][5] = get_priority_class($event['criticity']); + $table1->cellclass[$i][6] = get_priority_class($event['criticity']); + $table1->cellclass[$i][7] = get_priority_class($event['criticity']); } else { - $table1->cellclass[$i][1] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = $table1->cellclass[$i][5] = get_priority_class($event['criticity']); + $table1->cellclass[$i][1] = get_priority_class($event['criticity']); + $table1->cellclass[$i][3] = get_priority_class($event['criticity']); + $table1->cellclass[$i][4] = get_priority_class($event['criticity']); + $table1->cellclass[$i][5] = get_priority_class($event['criticity']); + $table1->cellclass[$i][6] = get_priority_class($event['criticity']); } $data = []; @@ -2454,7 +2499,7 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) } if ($item['show_summary_group']) { - $data[] = ''.date($config['date_format'], $event['timestamp']).''; + $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } else { $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index eda55136f5..d005316cca 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -653,60 +653,6 @@ function event_comment(current_event) { return false; } -//Show event list when fielter repetead is Group agents -function show_events_group_agent(id_insert, id_agent, server_id) { - var parameter = []; - parameter.push({ name: "id_agent", value: id_agent }); - parameter.push({ name: "server_id", value: server_id }); - parameter.push({ name: "event_type", value: $("#event_type").val() }); - parameter.push({ name: "severity", value: $("#severity").val() }); - parameter.push({ name: "status", value: $("#status").val() }); - parameter.push({ name: "search", value: $("#text-search").val() }); - parameter.push({ - name: "id_agent_module", - value: $("input:hidden[name=module_search_hidden]").val() - }); - parameter.push({ - name: "event_view_hr", - value: $("#text-event_view_hr").val() - }); - parameter.push({ name: "id_user_ack", value: $("#id_user_ack").val() }); - parameter.push({ - name: "tag_with", - value: Base64.decode($("#hidden-tag_with").val()) - }); - parameter.push({ - name: "tag_without", - value: Base64.decode($("#hidden-tag_without").val()) - }); - parameter.push({ - name: "filter_only_alert", - value: $("#filter_only_alert").val() - }); - parameter.push({ name: "date_from", value: $("#text-date_from").val() }); - parameter.push({ name: "date_to", value: $("#text-date_to").val() }); - parameter.push({ name: "server_id_search", value: $("#server_id").val() }); - parameter.push({ - name: "page", - value: "include/ajax/events" - }); - parameter.push({ - name: "get_list_events_agents", - value: 1 - }); - - jQuery.ajax({ - type: "POST", - url: $("#hidden-ajax_file").val(), - data: parameter, - dataType: "html", - success: function(data) { - $("#" + id_insert).html(data); - $("#" + id_insert).toggle(); - } - }); -} - function show_event_response_command_dialog(id, response, total_checked) { var params = []; params.push("page=include/ajax/events"); diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php index 42cd059dc5..9329fb749a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_group.php @@ -367,8 +367,6 @@ class TopNEventByGroupWidget extends Widget $this->values['groupId'] = explode(',', $this->values['groupId'][0]); - $event_table = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; - if (empty($this->values['groupId']) === true) { $output .= '
'; $output .= \ui_print_info_message( @@ -390,13 +388,12 @@ class TopNEventByGroupWidget extends Widget if ($all_group === false) { $sql = sprintf( 'SELECT id_agente, COUNT(*) AS count - FROM %s + FROM tevento WHERE utimestamp >= %d AND id_grupo IN (%s) GROUP BY id_agente ORDER BY count DESC LIMIT %d', - $event_table, $timestamp, implode(',', $this->values['groupId']), $this->values['amountShow'] @@ -404,12 +401,11 @@ class TopNEventByGroupWidget extends Widget } else { $sql = sprintf( 'SELECT id_agente, COUNT(*) AS count - FROM %s + FROM tevento WHERE utimestamp >= %d GROUP BY id_agente ORDER BY count DESC LIMIT %d', - $event_table, $timestamp, $this->values['amountShow'] ); diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php index 0d413d219c..f110c4ea52 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n_events_by_module.php @@ -365,8 +365,6 @@ class TopNEventByModuleWidget extends Widget $this->values['groupId'] = explode(',', $this->values['groupId'][0]); - $event_table = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; - if (empty($this->values['groupId']) === true) { $output = '
'; $output .= \ui_print_info_message( @@ -391,13 +389,12 @@ class TopNEventByModuleWidget extends Widget id_agentmodule, event_type, COUNT(*) AS count - FROM %s + FROM tevento WHERE utimestamp >= %d AND id_grupo IN (%s) GROUP BY id_agentmodule, event_type ORDER BY count DESC LIMIT %d', - $event_table, $timestamp, implode(',', $this->values['groupId']), $this->values['amountShow'] @@ -408,12 +405,11 @@ class TopNEventByModuleWidget extends Widget id_agentmodule, event_type, COUNT(*) AS count - FROM %s + FROM tevento WHERE utimestamp >= %d GROUP BY id_agentmodule, event_type ORDER BY count DESC LIMIT %d', - $event_table, $timestamp, $this->values['amountShow'] ); diff --git a/pandora_console/include/lib/Event.php b/pandora_console/include/lib/Event.php index e09b4ace20..57584469d7 100644 --- a/pandora_console/include/lib/Event.php +++ b/pandora_console/include/lib/Event.php @@ -60,7 +60,7 @@ class Event extends Entity */ public function __construct(?int $event_id=null) { - $this->table = ((bool) \is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; + $this->table = 'tevento'; if ($event_id === 0) { parent::__construct($this->table); diff --git a/pandora_console/mobile/operation/events.php b/pandora_console/mobile/operation/events.php index d893cb6e51..466ce20673 100644 --- a/pandora_console/mobile/operation/events.php +++ b/pandora_console/mobile/operation/events.php @@ -731,95 +731,51 @@ class Events { $system = System::getInstance(); - // --------------Fill the SQL POST------------------------------- - $sql_post = ' WHERE 1=1 '; + $filters = []; - if ($this->status != null) { - switch ($this->status) { - case 0: - case 1: - case 2: - $sql_post .= ' AND estado = '.$this->status; - break; - - case 3: - $sql_post .= ' AND (estado = 0 OR estado = 2)'; - break; - - default: - // Not posible. - break; - } + // Status. + if (empty($this->status) === false) { + $filters['status'] = $this->status; } - if ($this->free_search != '') { - $sql_post .= " AND evento LIKE '%".io_safe_input($this->free_search)."%'"; + // Filter search. + if (empty($this->free_search) === false) { + $filters['search'] = $this->free_search; } - if ($this->severity != null && $this->severity != -1) { - switch ($this->severity) { - case EVENT_CRIT_WARNING_OR_CRITICAL: - $sql_post .= ' AND (criticity = '.EVENT_CRIT_WARNING.' OR - criticity = '.EVENT_CRIT_CRITICAL.')'; - break; - - case EVENT_CRIT_NOT_NORMAL: - $sql_post .= ' AND criticity != '.EVENT_CRIT_NORMAL; - break; - - default: - $sql_post .= ' AND criticity = '.$this->severity; - break; - } + // Severity. + if (empty($this->severity) === false) { + $filters['severity'] = $this->severity; } - if ($this->hours_old > 0) { - $unixtime = (get_system_time() - ($this->hours_old * SECONDS_1HOUR)); - $sql_post .= ' AND (utimestamp > '.$unixtime.')'; - } - - if ($this->type != '') { - // If normal, warning, could be several (going_up_warning, going_down_warning... too complex - // for the user so for him is presented only "warning, critical and normal" - if ($this->type == 'warning' || $this->type == 'critical' - || $this->type == 'normal' - ) { - $sql_post .= " AND event_type LIKE '%".$this->type."%' "; - } else if ($this->type == 'not_normal') { - $sql_post .= " AND event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' "; - } else if ($this->type != 'all') { - $sql_post .= " AND event_type = '".$this->type."'"; - } - } - - $system = System::getInstance(); - $groups = users_get_groups($system->getConfig('id_user'), 'ER'); - - // Group selection - if ($this->group > 0 && in_array($this->group, array_keys($groups))) { - // If a group is selected and it's in the groups allowed - $sql_post .= ' AND id_grupo = '.$this->group; + // Hours. + if (empty($this->hours_old) === false) { + $filters['event_view_hr'] = $this->hours_old; } else { - if (is_user_admin($system->getConfig('id_user'))) { - // Do nothing if you're admin, you get full access - $sql_post .= ''; - } else { - // Otherwise select all groups the user has rights to. - $sql_post .= ' AND id_grupo IN ('.implode(',', array_keys($groups)).')'; - } + $filters['event_view_hr'] = 8; } - if ($this->id_agent > 0) { - $sql_post .= ' AND id_agente = '.$this->id_agent; + // Type. + if (empty($this->type) === false) { + $filters['event_type'] = $this->type; } - // Skip system messages if user is not PM - if (!check_acl($system->getConfig('id_user'), 0, 'PM')) { - $sql_post .= ' AND id_grupo != 0'; + // ID group. + if (empty($this->group) === false) { + $filters['id_group_filter'] = $this->group; } + // Id Agent. + if ($this->id_agent !== false && empty($this->id_agent) === false) { + $filters['id_agent'] = $this->id_agent; + } + + $filters['group_rep'] = 1; + // -------------------------------------------------------------- - if (isset($this->limit) && $this->limit != -1) { + if (isset($this->limit) === true + && $this->limit !== -1 + ) { $offset = 0; $pagination = $this->limit; } else { @@ -827,24 +783,41 @@ class Events $pagination = $system->getPageSize(); } - $meta = false; - if ($system->getConfig('metaconsole')) { - $meta = true; - } - - $events_db = events_get_events_grouped( - $sql_post, + $events_db = events_get_all( + // Fields. + [ + 'te.*', + 'ta.alias', + ], + // Filter. + $filters, + // Offset. $offset, + // Limit. $pagination, - $meta, - false + // Order. + 'desc', + // Sort field. + 'timestamp' ); - if (empty($events_db)) { - $events_db = []; + if (is_metaconsole() === false) { + $count = events_get_all( + 'count', + $filters, + ); + + if ($count !== false) { + $total_events = $count['0']['nitems']; + } + } else { + $total_events = $events_db['total']; + $events_db = $events_db['data']; } - $total_events = events_get_total_events_grouped($sql_post, $meta); + if (empty($events_db) === true) { + $events_db = []; + } return [ 'events' => $events_db, diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 1653f7ab7a..1ddfaa02a3 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -1,1168 +1,2 @@ width)) { - $table->width = '100%'; -} - -$table->id = 'eventtable'; -$table->cellpadding = 4; -$table->cellspacing = 4; -if (!isset($table->class)) { - $table->class = 'info_table'; -} - -$table->head = []; -$table->data = []; - -$params = [ - // Pandora sections - 'sec' => 'eventos', - 'sec2' => 'operation/events/events', - - // Events query params - 'search' => io_safe_input($search), - 'event_type' => $event_type, - 'severity' => $severity, - 'status' => $status, - 'id_group' => $id_group, - 'recursion' => $recursion, - 'refr' => (int) get_parameter('refr', 0), - 'id_agent' => $id_agent, - 'id_agent_module' => $id_agent_module, - 'pagination' => $pagination, - 'group_rep' => $group_rep, - 'event_view_hr' => $event_view_hr, - 'id_user_ack' => $id_user_ack, - 'tag_with' => $tag_with_base64, - 'tag_without' => $tag_without_base64, - 'filter_only_alert' => $filter_only_alert, - 'offset' => $offset, - 'toogle_filter' => 'no', - 'filter_id' => $filter_id, - 'id_name' => $id_name, - 'history' => (int) $history, - 'section' => $section, - 'open_filter' => $open_filter, - 'date_from' => $date_from, - 'date_to' => $date_to, - 'pure' => $config['pure'], - - // Display params - 'offset' => $offset, - 'disabled' => $disabled, - 'sort' => $sort, - 'sort_field' => $sort_field, -]; - -if ($group_rep == 2) { - $table->class = 'databox filters data'; - $table->head[1] = __('Agent'); - $table->head[5] = __('More detail'); - - // $url = html_print_sort_arrows( - // array_merge($params, array('sort_field' => 'status')), - // 'sort' - // ); - $params_sort_field_status = array_merge($params, ['sort_field' => 'status']); - $url = 'index.php?'.http_build_query($params_sort_field_status, '', '&'); - - foreach ($result as $key => $res) { - if ($res['event_type'] == 'alert_fired') { - $table->rowstyle[$key] = 'background: #FFA631;'; - } else if ($res['event_type'] == 'going_up_critical' || $res['event_type'] == 'going_down_critical') { - $table->rowstyle[$key] = 'background: #e63c52;'; - } else if ($res['event_type'] == 'going_up_warning' || $res['event_type'] == 'going_down_warning') { - $table->rowstyle[$key] = 'background: #f3b200;'; - } else if ($res['event_type'] == 'going_up_normal' || $res['event_type'] == 'going_down_normal') { - $table->rowstyle[$key] = 'background: #82b92e;'; - } else if ($res['event_type'] == 'going_unknown') { - $table->rowstyle[$key] = 'background: #B2B2B2;'; - } - - - if ($meta) { - $table->data[$key][1] = __('The Agent: ').'"'.$res['id_agent'].'", '.__(' has ').$res['total'].__(' events.'); - } else { - $table->data[$key][1] = __('The Agent: ').'"'.agents_get_alias($res['id_agent']).'", '.__(' has ').$res['total'].__(' events.'); - } - - $uniq = uniqid(); - if ($meta) { - $table->data[$key][2] = 'id.'-'.$uniq.'-0","'.$res['id_agent'].'",'.$res['id_server'].');\' />'; - } else { - $table->data[$key][2] = 'id.'-'.$uniq.'-0",'.$res['id_agent'].',false);\'/>'; - } - - $table->cellstyle[$uniq][0] = 'display:none;'; - $table->data[$uniq][0] = false; - } - - if ($result) { - if ($allow_pagination) { - ui_pagination($total_events, $url, $offset, $pagination); - } - - html_print_table($table); - - if ($allow_pagination) { - ui_pagination($total_events, $url, $offset, $pagination); - } - } else { - echo '
'.__('No events').'
'; - } -} else { - // Fields that the user has selected to show. - if ($meta) { - $show_fields = events_meta_get_custom_fields_user(); - } else { - $show_fields = explode(',', $config['event_fields']); - } - - // headers - $i = 0; - $table->head[$i] = __('ID').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'event_id']), - 'sort' - ); - - $table->align[$i] = 'left'; - - $i++; - foreach ($show_fields as $k_s => $fields) { - if ($fields == 'server_name') { - $table->head[$i] = __('Server'); - $table->align[$i] = 'left'; - $i++; - } - - if ($fields == 'id_evento') { - $table->head[$i] = __('Event ID').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'event_id']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'evento') { - $table->head[$i] = __('Event Name').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'event_name']), - 'sort' - ); - $table->align[$i] = 'left'; - $table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;'; - $i++; - } - - if ($fields == 'id_agente') { - $table->head[$i] = __('Agent name').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'agent_id']), - 'sort' - ); - $table->align[$i] = 'left'; - $table->style[$i] = 'max-width: 350px; word-break: break-all;'; - $i++; - } - - if ($fields == 'timestamp') { - $table->head[$i] = __('Timestamp').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'timestamp']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'id_usuario') { - $table->head[$i] = __('User').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'user_id']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'owner_user') { - $table->head[$i] = __('Owner').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'owner']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'id_grupo') { - $table->head[$i] = __('Group').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'group_id']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'event_type') { - $table->head[$i] = __('Event Type').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'event_type']), - 'sort' - ); - $table->align[$i] = 'left'; - - $table->style[$i] = 'min-width: 85px;'; - $i++; - } - - if ($fields == 'id_agentmodule') { - $table->head[$i] = __('Module Name').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'module_name']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'id_alert_am') { - $table->head[$i] = __('Alert').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'alert_id']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'criticity') { - $table->head[$i] = __('Severity').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'criticity']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'user_comment') { - $table->head[$i] = __('Comment').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'comment']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'tags') { - $table->head[$i] = __('Tags').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'tags']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'source') { - $table->head[$i] = __('Source').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'source']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'id_extra') { - $table->head[$i] = __('Extra ID').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'extra_id']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'ack_utimestamp') { - $table->head[$i] = __('ACK Timestamp').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'ack_utimestamp']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'instructions') { - $table->head[$i] = __('Instructions'); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'data') { - $table->head[$i] = __('Data').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'data']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields == 'module_status') { - $table->head[$i] = __('Module Status').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'module_status']), - 'sort' - ); - $table->align[$i] = 'left'; - - $i++; - } - - if ($fields === 'custom_data') { - $table->head[$i] = __('Custom data'); - $table->align[$i] = 'left'; - - $i++; - } - } - - if (in_array('estado', $show_fields)) { - $table->head[$i] = ''.__('Status').html_print_sort_arrows( - array_merge($params, ['sort_field' => 'status']), - 'sort' - ).''; - $table->align[$i] = 'left'; - $table->style[$i] = 'white-space: nowrap !important; width: 1px !important;'; - $i++; - } - - - if ($i != 0 && $allow_action) { - $table->head[$i] = __('Action'); - $table->align[$i] = 'left'; - - $table->size[$i] = '90px'; - $i++; - if (check_acl($config['id_user'], 0, 'EW') == 1 && !$readonly) { - $table->head[$i] = html_print_checkbox('all_validate_box', '1', false, true); - $table->align[$i] = 'left'; - } else { - $table->head[$i] = ''; - } - } - - if ($meta) { - // Get info of the all servers to use it on hash auth - $servers_url_hash = metaconsole_get_servers_url_hash(); - $servers = metaconsole_get_servers(); - } - - $show_delete_button = false; - $show_validate_button = false; - - $idx = 0; - - if ($meta) { - $alias_array = []; - } - - // Arrange data. We already did ACL's in the query - foreach ($result as $event) { - $data = []; - - if ($meta) { - $event['server_url_hash'] = $servers_url_hash[$event['server_id']]; - $event['server_url'] = $servers[$event['server_id']]['server_url']; - $event['server_name'] = $servers[$event['server_id']]['server_name']; - } - - // Clean url from events and store in array - $event['clean_tags'] = events_clean_tags($event['tags']); - - // First pass along the class of this row - $myclass = get_priority_class($event['criticity']); - - // print status - $estado = $event['estado']; - - // Colored box - switch ($estado) { - case EVENT_NEW: - $img_st = 'images/star.png'; - $title_st = __('New event'); - break; - - case EVENT_VALIDATE: - $img_st = 'images/tick.png'; - $title_st = __('Event validated'); - break; - - case EVENT_PROCESS: - $img_st = 'images/hourglass.png'; - $title_st = __('Event in process'); - break; - } - - $i = 0; - - $data[$i] = '#'.$event['id_evento']; - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3; color: #111 !important;'; - - // Pass grouped values in hidden fields to use it from modal window - if ($group_rep) { - $similar_ids = $event['similar_ids']; - $timestamp_first = $event['timestamp_rep_min']; - $timestamp_last = $event['timestamp_rep']; - } else { - $similar_ids = $event['id_evento']; - $timestamp_first = $event['utimestamp']; - $timestamp_last = $event['utimestamp']; - } - - // Store group data to show in extended view - $data[$i] .= html_print_input_hidden('similar_ids_'.$event['id_evento'], $similar_ids, true); - $data[$i] .= html_print_input_hidden('timestamp_first_'.$event['id_evento'], $timestamp_first, true); - $data[$i] .= html_print_input_hidden('timestamp_last_'.$event['id_evento'], $timestamp_last, true); - $data[$i] .= html_print_input_hidden('childrens_ids', json_encode($childrens_ids), true); - - // Store server id if is metaconsole. 0 otherwise - if ($meta) { - $server_id = $event['server_id']; - - // If meta activated, propagate the id of the event on node (source id) - $data[$i] .= html_print_input_hidden('source_id_'.$event['id_evento'], $event['id_source_event'], true); - $table->cellclass[count($table->data)][$i] = $myclass; - } else { - $server_id = 0; - } - - $data[$i] .= html_print_input_hidden('server_id_'.$event['id_evento'], $server_id, true); - - if (empty($event['event_rep'])) { - $event['event_rep'] = 0; - } - - $data[$i] .= html_print_input_hidden('event_rep_'.$event['id_evento'], $event['event_rep'], true); - // Store concat comments to show in extended view - $data[$i] .= html_print_input_hidden('user_comment_'.$event['id_evento'], base64_encode($event['user_comment']), true); - - $i++; - - switch ($event['criticity']) { - default: - case 0: - $img_sev = 'images/status_sets/default/severity_maintenance.png'; - break; - case 1: - $img_sev = 'images/status_sets/default/severity_informational.png'; - break; - - case 2: - $img_sev = 'images/status_sets/default/severity_normal.png'; - break; - - case 3: - $img_sev = 'images/status_sets/default/severity_warning.png'; - break; - - case 4: - $img_sev = 'images/status_sets/default/severity_critical.png'; - break; - - case 5: - $img_sev = 'images/status_sets/default/severity_minor.png'; - break; - - case 6: - $img_sev = 'images/status_sets/default/severity_major.png'; - break; - } - - foreach ($show_fields as $k_s => $fields) { - if ($fields == 'server_name') { - if ($meta) { - if (can_user_access_node()) { - $data[$i] = "".$event['server_name'].''; - } else { - $data[$i] = $event['server_name']; - } - } else { - $data[$i] = db_get_value('name', 'tserver'); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_evento') { - $data[$i] = $event['id_evento']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'evento') { - // Event description - $data[$i] = ''; - if ($allow_action) { - $data[$i] .= ''; - } - - $data[$i] .= ''.ui_print_truncate_text( - strip_tags(io_safe_output($event['evento'])), - 160 - ).''; - if ($allow_action) { - $data[$i] .= ''; - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_agente') { - $data[$i] = ''; - - if ($event['id_agente'] > 0) { - // Agent name - if ($meta) { - if (!empty($event['agent_name'])) { - if (!array_key_exists($event['agent_name'], $alias_array)) { - $alias_array[$event['agent_name']] = db_get_value('alias', 'tmetaconsole_agent', 'nombre', $event['agent_name']); - } - } - - $agent_link = ''; - if (can_user_access_node()) { - $data[$i] = ''.$agent_link.$alias_array[$event['agent_name']].''; - } else { - $data[$i] = $alias_array[$event['agent_name']]; - } - } else { - $agent = db_get_row('tagente', 'id_agente', $event['id_agente']); - $data[$i] .= ''; - $data[$i] .= ''.$agent['alias'].''; - } - } else { - $data[$i] .= ''; - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'timestamp') { - // Time - $data[$i] = ''; - if ($group_rep == 1) { - $data[$i] .= ui_print_timestamp($event['timestamp_rep'], true); - } else { - $data[$i] .= ui_print_timestamp($event['timestamp'], true); - } - - $data[$i] .= ''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_usuario') { - $user_name = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); - if (empty($user_name)) { - $user_name = $event['id_usuario']; - } - - $data[$i] = $user_name; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'owner_user') { - $owner_name = db_get_value('fullname', 'tusuario', 'id_user', $event['owner_user']); - if (empty($owner_name)) { - $owner_name = $event['owner_user']; - } - - $data[$i] = $owner_name; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_grupo') { - if ($meta) { - $data[$i] = $event['group_name']; - } else { - $id_group = $event['id_grupo']; - $group_name = db_get_value('nombre', 'tgrupo', 'id_grupo', $id_group); - if ($id_group == 0) { - $group_name = __('All'); - } - - $data[$i] = $group_name; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'event_type') { - $data[$i] = events_print_type_description($event['event_type'], true); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_agentmodule') { - if ($meta) { - $module_link = ''; - if (can_user_access_node()) { - $data[$i] = ''.$module_link.$event['module_name'].''; - } else { - $data[$i] = $event['module_name']; - } - } else { - $module_name = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); - $data[$i] = ''.$module_name.''; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_alert_am') { - if ($meta) { - $data[$i] = $event['alert_template_name']; - } else { - if ($event['id_alert_am'] != 0) { - $sql = 'SELECT name - FROM talert_templates - WHERE id IN (SELECT id_alert_template - FROM talert_template_modules - WHERE id = '.$event['id_alert_am'].');'; - - $templateName = db_get_sql($sql); - $data[$i] = ''.$templateName.''; - } else { - $data[$i] = ''; - } - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'criticity') { - $data[$i] = get_priority_name($event['criticity']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'user_comment') { - $safe_event_user_comment = strip_tags(io_safe_output($event['user_comment'])); - $line_breaks = [ - "\r\n", - "\n", - "\r", - ]; - $safe_event_user_comment = str_replace($line_breaks, '
', $safe_event_user_comment); - $event_user_comments = json_decode($safe_event_user_comment, true); - $event_user_comment_str = ''; - - if (!empty($event_user_comments)) { - $last_key = key(array_slice($event_user_comments, -1, 1, true)); - $date_format = $config['date_format']; - - foreach ($event_user_comments as $key => $event_user_comment) { - $event_user_comment_str .= sprintf( - '%s: %s
%s: %s
%s: %s
', - __('Date'), - date($date_format, $event_user_comment['utimestamp']), - __('User'), - $event_user_comment['id_user'], - __('Comment'), - $event_user_comment['comment'] - ); - if ($key != $last_key) { - $event_user_comment_str .= '
'; - } - } - } - - $comments_help_tip = ''; - if (!empty($event_user_comment_str)) { - if ($myclass == 'datos_yellow') { - $comments_help_tip = ui_print_help_tip_border($event_user_comment_str, true); - } else { - $comments_help_tip = ui_print_help_tip($event_user_comment_str, true); - } - } - - $data[$i] = ''.$comments_help_tip.''; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'tags') { - $data[$i] = tags_get_tags_formatted($event['tags']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'source') { - $data[$i] = $event['source']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'id_extra') { - $data[$i] = $event['id_extra']; - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'ack_utimestamp') { - if ($event['ack_utimestamp'] == 0) { - $data[$i] = ''; - } else { - $data[$i] = date($config['date_format'], $event['ack_utimestamp']); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'instructions') { - switch ($event['event_type']) { - case 'going_unknown': - if (!empty($event['unknown_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['unknown_instructions']))]); - } - break; - - case 'going_up_critical': - case 'going_down_critical': - if (!empty($event['critical_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['critical_instructions']))]); - } - break; - - case 'going_down_warning': - if (!empty($event['warning_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['warning_instructions']))]); - } - break; - - case 'system': - if (!empty($event['critical_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['critical_instructions']))]); - } else if (!empty($event['warning_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['warning_instructions']))]); - } else if (!empty($event['unknown_instructions'])) { - $data[$i] = html_print_image('images/page_white_text.png', true, ['class' => 'invert_filter', 'title' => str_replace("\n", '
', io_safe_output($event['unknown_instructions']))]); - } - break; - } - - if (!isset($data[$i])) { - $data[$i] = ''; - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'data') { - $data[$i] = $event['data']; - if (($data[$i] % 1) == 0) { - $data[$i] = number_format($data[$i], 0); - } else { - $data[$i] = number_format($data[$i], 2); - } - - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - - if ($fields == 'module_status') { - $data[$i] = modules_get_modules_status($event['module_status']); - $table->cellclass[count($table->data)][$i] = $myclass; - $i++; - } - } - - if (in_array('estado', $show_fields)) { - $data[$i] = html_print_image( - $img_st, - true, - [ - 'class' => 'image_status', - 'title' => $title_st, - 'id' => 'status_img_'.$event['id_evento'], - ] - ); - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3; white-space: nowrap; width: 1px;'; - $i++; - } - - if ($i != 0 && $allow_action) { - // Actions - $data[$i] = ''; - $data[$i] .= html_print_input_hidden('event_title_'.$event['id_evento'], '#'.$event['id_evento'].' - '.strip_tags(io_safe_output($event['evento'])), true); - $data[$i] .= html_print_image( - 'images/eye.png', - true, - [ - 'class' => 'invert_filter', - 'title' => __('Show more'), - ] - ); - $data[$i] .= ''; - - if (!$readonly) { - // Validate event - if (($event['estado'] != 1) && (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EW', $event['clean_tags'], $childrens_ids))) { - $show_validate_button = true; - $data[$i] .= ''; - $data[$i] .= html_print_image( - 'images/ok.png', - true, - ['title' => __('Validate event')] - ); - $data[$i] .= ''; - // Display the go to in progress status button - if ($event['estado'] != 2) { - $data[$i] .= ''; - $data[$i] .= html_print_image( - 'images/hourglass.png', - true, - [ - 'class' => 'invert_filter', - 'title' => __('Change to in progress status'), - ] - ); - $data[$i] .= ''; - } - } - - // Delete event - if ((tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EM', $event['clean_tags'], $childrens_ids) == 1)) { - if ($event['estado'] != 2) { - $show_delete_button = true; - $data[$i] .= ''; - $data[$i] .= html_print_image( - 'images/cross.png', - true, - [ - 'class' => 'invert_filter', - 'title' => __('Delete event'), - 'id' => 'delete_cross_'.$event['id_evento'], - ] - ); - $data[$i] .= ''; - } else { - $data[$i] .= html_print_image( - 'images/cross.disabled.png', - true, - [ - 'title' => __('Is not allowed delete events in process'), - 'id' => 'delete-'.$event['id_evento'], - ] - ); - $data[$i] .= ' '; - } - } - } - - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; - - $i++; - - if (!$readonly) { - if (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EM', $event['clean_tags'], $childrens_ids) == 1) { - // Checkbox - // Class 'candeleted' must be the fist class to be parsed from javascript. Dont change - $data[$i] = html_print_checkbox_extended('validate_ids[]', $event['id_evento'], false, false, false, 'class="candeleted chk_val"', true); - } else if (tags_checks_event_acl($config['id_user'], $event['id_grupo'], 'EW', $event['clean_tags'], $childrens_ids) == 1) { - // Checkbox - $data[$i] = html_print_checkbox_extended('validate_ids[]', $event['id_evento'], false, false, false, 'class="chk_val"', true); - } else if (isset($table->header[$i]) || true) { - $data[$i] = html_print_checkbox_extended('validate_ids[]', $event['id_evento'], false, false, false, 'class="chk_val"', true); - } - } - - $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; - } - - array_push($table->data, $data); - - $idx++; - } - - echo '
'; - if (!empty($table->data)) { - if ($allow_pagination) { - $params_to_paginate = $params; - unset($params_to_paginate['offset']); - $url_paginate = 'index.php?'.http_build_query($params_to_paginate, '', '&'); - ui_pagination($total_events, $url_paginate, $offset, $pagination); - } - - if ($allow_action) { - echo '
'; - echo ""; - } - - if (defined('METACONSOLE')) { - echo '
'; - } else { - echo '
'; - } - - html_print_table($table); - if ($allow_pagination) { - $params_to_paginate = $params; - unset($params_to_paginate['offset']); - $url_paginate = 'index.php?'.http_build_query($params_to_paginate, '', '&'); - ui_pagination($total_events, $url_paginate, $offset, $pagination, false, 'offset', true, 'pagination-bottom'); - } - - echo '
'; - - if ($allow_action) { - echo '
'; - if (!$readonly && $show_validate_button) { - $array_events_actions['in_progress_selected'] = 'In progress selected'; - $array_events_actions['validate_selected'] = 'Validate selected'; - // Fix: validated_selected JS function has to be included with the proper user ACLs - ?> - - - - '; - echo ''; - - $sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'"; - $event_responses = db_get_all_rows_sql($sql_event_resp); - - foreach ($event_responses as $val) { - $array_events_actions[$val['id']] = $val['name']; - } - - if (check_acl($config['id_user'], 0, 'EW')) { - if ($config['event_replication'] != 1) { - echo '
'; - echo '
'; - html_print_select($array_events_actions, 'response_id', '', '', '', 0, false, false, false); - echo '  '; - html_print_button(__('Execute event response'), 'submit_event_response', false, 'execute_event_response(true);', 'class="sub next"'); - echo "'; - echo '
'; - echo ''; - echo ''; - echo '
'; - } - } - } - - ?> - - '.__('No events').'
'; - } - - echo '
'; -} +// Deprecated. diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index c3312a0db3..3dd916da45 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -424,8 +424,12 @@ if (is_ajax() === true) { ) ); - $tmp->timestamp = $max_event['timestamp']; - $tmp->criticity = $max_event['criticity']; + if ($max_event !== false + && empty($max_event) === false + ) { + $tmp->timestamp = $max_event['timestamp']; + $tmp->criticity = $max_event['criticity']; + } } $tmp->agent_name = io_safe_output($tmp->agent_name); @@ -1588,34 +1592,9 @@ try { 'class' => 'no-padding', ], 'id_evento', - // 'id_agente', - // 'id_usuario', - // 'id_grupo', - // 'estado', 'agent_name', 'timestamp', - // 'utimestamp', - // 'event_type', - // 'id_agentmodule', - // 'id_alert_am', 'event_type', - // 'user_comment', - // 'tags', - // 'source', - // 'id_extra', - // 'critical_instructions', - // 'warning_instructions', - // 'unknown_instructions', - // 'owner_user', - // 'ack_utimestamp', - // 'custom_data', - // 'data', - // 'module_status', - // 'similar_ids', - // 'event_rep', - // 'timestamp_rep', - // 'timestamp_rep_min', - // 'module_name', [ 'text' => 'options', 'class' => 'action_buttons w120px', diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 1ea6dfe190..1ddfaa02a3 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -1,2043 +1,2 @@ $id] - ); - - if ($result === false) { - echo 'error'; - } else { - echo 'ok'; - } - } - - if ($get_event_filters) { - $event_filter = events_get_event_filter_select(); - - echo io_json_mb_encode($event_filter); - } - - return; -} - -// Get the tags where the user have permissions in Events reading tasks. -$tags = tags_get_user_tags($config['id_user'], $access); - - -if ($id_agent == 0 && !empty($text_agent)) { - $id_agent = -1; -} - -$id_name = get_parameter('id_name', ''); - -// -------------------------------------------------------------------------- -// ------------------------ DEFAULT USER FILTER ----------------------------- -$user = $config['id_user']; -$user_filter = db_get_value_filter( - 'default_event_filter', - 'tusuario', - ['id_user' => $user] -); -$update_from_filter_table = (bool) get_parameter( - 'update_from_filter_table', - false -); - -if ($user_filter != 0 && empty($id_name) && !$update_from_filter_table) { - $user_default_filter = db_get_all_rows_filter( - 'tevent_filter', - ['id_filter' => $user_filter] - ); - $user_default_filter = $user_default_filter[0]; - - if (!empty($user_default_filter)) { - // FORM. - $id_name = $user_default_filter['id_name']; - $id_group = $user_default_filter['id_group']; - if ($user_default_filter['event_type'] != '') { - $event_type = $user_default_filter['event_type']; - } - - $severity = $user_default_filter['severity']; - $status = $user_default_filter['status']; - $event_view_hr = $user_default_filter['event_view_hr']; - $group_rep = $user_default_filter['group_rep']; - $id_extra = $user_default_filter['id_extra']; - $user_comment = $user_default_filter['user_comment']; - $source = $user_default_filter['source']; - - if ($user_default_filter['search'] != '') { - $search = $user_default_filter['search']; - } - - if ($user_default_filter['id_user_ack'] != 0) { - $id_user_ack = $user_default_filter['id_user_ack']; - } - - if ($user_default_filter['id_agent_module'] != 0) { - $id_agent_module = $user_default_filter['id_agent_module']; - } - - if ($user_default_filter['id_agent'] != 0) { - $id_agent = $user_default_filter['id_agent']; - $text_agent = agents_get_alias($id_agent); - } - - if ($user_default_filter['filter_only_alert'] != -1) { - $filter_only_alert = $user_default_filter['filter_only_alert']; - } - - if ($user_default_filter['pagination'] != 20) { - $pagination = $user_default_filter['pagination']; - } - - if ($user_default_filter['date_from'] != '0000-00-00') { - $date_from = $user_default_filter['date_from']; - } - - if ($user_default_filter['date_to'] != '0000-00-00') { - $date_to = $user_default_filter['date_to']; - } - - if (io_safe_output($user_default_filter['tag_with']) != '[]' - && io_safe_output($user_default_filter['tag_with']) != '["0"]' - ) { - $tag_with = $user_default_filter['tag_with']; - $tag_with_clean = io_safe_output($tag_with); - $tag_with = json_decode($tag_with_clean, true); - } - - if (io_safe_output($user_default_filter['tag_without']) != '[]' - && io_safe_output($user_default_filter['tag_without']) != '["0"]' - ) { - $tag_without = $user_default_filter['tag_without']; - $tag_without_clear = io_safe_output($tag_without); - $tag_without = json_decode($tag_without_clear, true); - } - } -} - -// Build the condition of the events query. -$sql_post = ' WHERE 1=1 '; - -$id_user = $config['id_user']; - -$filter_resume = []; - -require 'events.build_query.php'; -// Now $sql_post have all the where condition. -// Trick to catch if any filter button has been pushed (don't collapse filter) -// or the filter was open before click -// or autorefresh is in use (collapse filter). -$update_pressed = get_parameter_post('update', ''); -$update_pressed = (int) !empty($update_pressed); - -if ($update_pressed || $open_filter) { - $open_filter = true; -} - -unset($table); - -$filters = events_get_event_filter_select(); -$user_groups_array = users_get_groups_for_select( - $config['id_user'], - $access, - true, - true, - false -); - -// Some translated words to be used from javascript. -html_print_div( - [ - 'hidden' => true, - 'id' => 'not_filter_loaded_text', - 'content' => __('No filter loaded'), - ] -); - -html_print_div( - [ - 'hidden' => true, - 'id' => 'filter_loaded_text', - 'content' => __('Filter loaded'), - ] -); - -html_print_div( - [ - 'hidden' => true, - 'id' => 'save_filter_text', - 'content' => __('Save filter'), - ] -); - -html_print_div( - [ - 'hidden' => true, - 'id' => 'load_filter_text', - 'content' => __('Load filter'), - ] -); - -if (check_acl($config['id_user'], 0, 'EW') - || check_acl($config['id_user'], 0, 'EM') -) { - // Save filter div for dialog. - echo ''; -} - -// Load filter div for dialog. -echo ''; - -// TAGS. -$tags_select_with = []; -$tags_select_without = []; -$tag_with_temp = []; -$tag_without_temp = []; -foreach ($tags as $id_tag => $tag) { - if ((array_search($id_tag, $tag_with) === false) - || (array_search($id_tag, $tag_with) === null) - ) { - $tags_select_with[$id_tag] = ui_print_truncate_text($tag, 50, true); - } else { - $tag_with_temp[$id_tag] = ui_print_truncate_text($tag, 50, true); - } - - if ((array_search($id_tag, $tag_without) === false) - || (array_search($id_tag, $tag_without) === null) - ) { - $tags_select_without[$id_tag] = ui_print_truncate_text($tag, 50, true); - } else { - $tag_without_temp[$id_tag] = ui_print_truncate_text($tag, 50, true); - } -} - -$add_with_tag_disabled = empty($tags_select_with); -$remove_with_tag_disabled = empty($tag_with_temp); -$add_without_tag_disabled = empty($tags_select_without); -$remove_without_tag_disabled = empty($tag_without_temp); - -$tabletags_with = html_get_predefined_table('transparent', 2); -$tabletags_with->id = 'filter_events_tags_with'; -$tabletags_with->width = '100%'; -$tabletags_with->cellspacing = 4; -$tabletags_with->cellpadding = 4; -$tabletags_with->class = 'noshadow'; -$tabletags_with->styleTable = 'border: 0px;'; -if (defined('METACONSOLE')) { - $tabletags_with->class = 'nobady'; - $tabletags_with->cellspacing = 0; - $tabletags_with->cellpadding = 0; -} - - -$data = []; - -$data[0] = html_print_select( - $tags_select_with, - 'select_with', - '', - '', - '', - 0, - true, - true, - true, - '', - false, - 'width: 200px;' -); - -$data[1] = html_print_image( - 'images/darrowright.png', - true, - [ - 'id' => 'button-add_with', - 'style' => 'cursor: pointer;', - 'title' => __('Add'), - 'class' => 'invert_filter', - ] -); - -$data[1] .= html_print_input_hidden( - 'tag_with', - $tag_with_base64, - true -); - -$data[1] .= '

'.html_print_image( - 'images/darrowleft.png', - true, - [ - 'id' => 'button-remove_with', - 'style' => 'cursor: pointer;', - 'title' => __('Remove'), - 'class' => 'invert_filter', - ] -); - -$data[2] = html_print_select( - $tag_with_temp, - 'tag_with_temp', - [], - '', - '', - 0, - true, - true, - true, - '', - false, - 'width: 200px;' -); - -$tabletags_with->data[] = $data; -$tabletags_with->rowclass[] = ''; - - -$tabletags_without = html_get_predefined_table('transparent', 2); -$tabletags_without->id = 'filter_events_tags_without'; -$tabletags_without->width = '100%'; -$tabletags_without->cellspacing = 4; -$tabletags_without->cellpadding = 4; -$tabletags_without->class = 'noshadow'; -if (defined('METACONSOLE')) { - $tabletags_without->class = 'nobady'; - $tabletags_without->cellspacing = 0; - $tabletags_without->cellpadding = 0; -} - -$tabletags_without->styleTable = 'border: 0px;'; - -$data = []; -$data[0] = html_print_select( - $tags_select_without, - 'select_without', - '', - '', - '', - 0, - true, - true, - true, - '', - false, - 'width: 200px;' -); -$data[1] = html_print_image( - 'images/darrowright.png', - true, - [ - 'id' => 'button-add_without', - 'style' => 'cursor: pointer;', - 'title' => __('Add'), - ] -); -$data[1] .= html_print_input_hidden( - 'tag_without', - $tag_without_base64, - true -); -$data[1] .= '

'.html_print_image( - 'images/darrowleft.png', - true, - [ - 'id' => 'button-remove_without', - 'style' => 'cursor: pointer;', - 'title' => __('Remove'), - ] -); -$data[2] = html_print_select( - $tag_without_temp, - 'tag_without_temp', - [], - '', - '', - 0, - true, - true, - true, - '', - false, - 'width: 200px;' -); -$tabletags_without->data[] = $data; -$tabletags_without->rowclass[] = ''; - - -// END OF TAGS. -// EVENTS FILTER. -// Table for filter controls. -if (is_metaconsole()) { - $events_filter = '
'; -} else { - $events_filter = ''; -} - -// Hidden field with the loaded filter name. -$events_filter .= html_print_input_hidden('id_name', $id_name, true); - -// Hidden field that signals filter has been applied. -$events_filter .= html_print_input_hidden('is_filtered', 'true', true); - -// Hidden open filter flag -// If autoupdate is in use collapse filter. -if ($open_filter) { - $events_filter .= html_print_input_hidden( - 'open_filter', - 'true', - true - ); -} else { - $events_filter .= html_print_input_hidden( - 'open_filter', - 'false', - true - ); -} - -// ---------------------------------------------------------------------- -// - INI ADVANCE FILTER ------------------------------------------------- -$table_advanced = new stdClass(); -$table_advanced->id = 'events_filter_form_advanced'; -$table_advanced->width = '100%'; -$table_advanced->cellspacing = 4; -$table_advanced->cellpadding = 4; -$table_advanced->class = 'transparent'; -$table_advanced->styleTable = 'font-weight: bold; color: #555;'; -$table_advanced->data = []; - -$data = []; -$data[0] = __('Free search').$jump; -$data[0] .= html_print_input_text('search', $search, '', 25, 255, true); -$data[1] = __('Agent search').$jump; -$params = []; -$params['show_helptip'] = true; -$params['input_name'] = 'text_agent'; -$params['value'] = $text_agent; -$params['return'] = true; - -if ($meta) { - $params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax'; -} - -$params['print_hidden_input_idagent'] = true; -$params['hidden_input_idagent_name'] = 'id_agent'; -$params['hidden_input_idagent_value'] = $id_agent; - -$data[1] .= ui_print_agent_autocomplete_input($params); -$table_advanced->data[] = $data; -$table_advanced->rowclass[] = ''; - - -$data = []; -$data[0] = __('User ack.').$jump; - -$user_users = users_get_user_users( - $config['id_user'], - $access, - users_can_manage_group_all($access) -); - -$data[0] .= html_print_select( - $user_users, - 'id_user_ack', - $id_user_ack, - '', - __('Any'), - 0, - true -); - -if (!$meta) { - $data[1] = __('Module search').$jump; - $data[1] .= html_print_autocomplete_modules( - 'module_search', - $text_module, - false, - true, - '', - [], - true, - $id_agent_module - ); -} else { - $data[1] = __('Server').$jump; - $data[1] .= html_print_select_from_sql( - 'SELECT id, server_name FROM tmetaconsole_setup', - 'server_id', - $server_id, - 'script', - __('All'), - '0', - true - ); -} - -$table_advanced->data[] = $data; -$table_advanced->rowclass[] = ''; - -$data = []; -$data[0] = __('Alert events').$jump; -$alert_events_titles = [ - '-1' => __('All'), - '0' => __('Filter alert events'), - '1' => __('Only alert events'), -]; -$data[0] .= html_print_select( - $alert_events_titles, - 'filter_only_alert', - $filter_only_alert, - '', - '', - '', - true -); -$data[1] = __('Block size for pagination').$jump; -$lpagination[25] = 25; -$lpagination[50] = 50; -$lpagination[100] = 100; -$lpagination[200] = 200; -$lpagination[500] = 500; -$data[1] .= html_print_select( - $lpagination, - 'pagination', - $pagination, - '', - __('Default'), - $config['block_size'], - true -); -$table_advanced->data[] = $data; -$table_advanced->rowclass[] = ''; - -$data = []; -$data[0] = __('Date from').$jump; - -$data[0] .= html_print_input_text('date_from', $date_from, '', 15, 10, true); - -$data[1] = __('Date to').$jump; -$data[1] .= html_print_input_text('date_to', $date_to, '', 15, 10, true); - -$table_advanced->data[] = $data; -$table_advanced->rowclass[] = ''; - -$data[0] = __('Timestamp from:').$jump; -$data[0] .= html_print_input_text('time_from', $time_from, '', 9, 7, true); - -$data[1] = __('Timestamp to:').$jump; -$data[1] .= html_print_input_text('time_to', $time_to, '', 9, 7, true); - -$table_advanced->data[] = $data; -$table_advanced->rowclass[] = ''; - -$data = []; -if (defined('METACONSOLE')) { - $data[0] = '
'.__('Events with following tags').''.html_print_table($tabletags_with, true).'
'; - $data2[1] = '
'.__('Events without following tags').''.html_print_table($tabletags_without, true).'
'; -} else { - $data[0] = '
'.__('Events with following tags').''.html_print_table($tabletags_with, true).'
'; - $data[1] = '
'.__('Events without following tags').''.html_print_table($tabletags_without, true).'
'; -} - -$table_advanced->data[] = $data; -if (defined('METACONSOLE')) { - $table_advanced->data[] = $data2; -} - -$table_advanced->rowclass[] = ''; -// END ADVANCE FILTER -------------------------------------------------. -$table = new stdClass(); -$table->id = 'events_filter_form'; -$table->width = '100%'; -$table->cellspacing = 4; -$table->cellpadding = 4; -$table->class = 'databox filters'; - -$table->styleTable = 'font-weight: bold; color: #555;'; -$table->data = []; - -$data = []; -$data[0] = __('Group').$jump; -$data[0] .= html_print_select( - $user_groups_array, - 'id_group', - $id_group, - '', - '', - 0, - true, - false, - false -).$jump; -// ********************************************************************** -// TODO -// This code is disabled for to enabled in Pandora 5.1 -// but it needs a field in tevent_filter. -// -// $data[0] .= __('Group recursion') . ' '; -// $data[0] .= html_print_checkbox ("recursion", 1, $recursion, true, false); -// ********************************************************************** -$data[1] = __('Event type').$jump; -$types = get_event_types(); - -// Expand standard array to add not_normal -// (not exist in the array, used only for searches). -$types['not_normal'] = __('Not normal'); -$data[1] .= html_print_select( - $types, - 'event_type', - $event_type, - '', - __('All'), - '', - true -); - -$data[2] = __('Severity').$jump; -$severities = get_priorities(); -$data[2] .= html_print_select( - $severities, - 'severity', - $severity, - '', - __('All'), - '-1', - true, - false, - false -); -$table->data[] = $data; -$table->rowclass[] = ''; - -$data = []; -$data[0] = __('Event status').$jump; -$fields = events_get_all_status(); -$data[0] .= html_print_select($fields, 'status', $status, '', '', '', true); -$data[1] = __('Max. hours old').$jump; -$data[1] .= html_print_input_text( - 'event_view_hr', - $event_view_hr, - '', - 5, - 255, - true -); -$data[2] = __('Repeated').$jump; -$repeated_sel[0] = __('All events'); -$repeated_sel[1] = __('Group events'); -$repeated_sel[2] = __('Group agents'); -$data[2] .= html_print_select( - $repeated_sel, - 'group_rep', - $group_rep, - '', - '', - 0, - true -); -$table->data[] = $data; -$table->rowclass[] = ''; - -$data = []; -$data[0] = __('Source').$jump; -$data[0] .= html_print_input_text('source', $source, '', 35, 255, true); -$data[1] = __('Extra ID').$jump; -$data[1] .= html_print_input_text('id_extra', $id_extra, '', 11, 255, true); -$data[2] = __('Comment').$jump; -$data[2] .= html_print_input_text( - 'user_comment', - $user_comment, - '', - 35, - 255, - true -); -if (is_metaconsole()) { - $data[3] = __('Id source event').$jump; - $data[3] .= html_print_input_text( - 'id_source_event', - $id_source_event, - '', - 5, - 255, - true - ); -} - -$table->data[] = $data; -$table->rowclass[] = ''; - -$data = []; -$data[0] = ui_toggle( - html_print_table($table_advanced, true), - __('Advanced options'), - '', - '', - true, - true -); -$table->colspan[count($table->data)][0] = 3; -$table->cellstyle[count($table->data)][0] = 'padding: 10px;'; -$table->data[] = $data; -$table->rowclass[] = ''; - - -$data = []; -$table->data[] = $data; -$table->rowclass[] = ''; - -// The buttons. -$data = []; -$data[0] = ''; - - -$table->colspan[count($table->data)][1] = 4; -$table->rowstyle[count($table->data)] = 'text-align:right;'; -$table->data[] = $data; -$table->rowclass[] = ''; - -$data = []; -$data[0] = html_print_input_hidden('update_from_filter_table', 1, true); -$table->data[] = $data; -$table->rowclass[] = ''; - -$events_filter .= html_print_table($table, true); - -unset($table); - -$botom_update = "
"; -$botom_update .= html_print_submit_button( - __('Update'), - 'update', - false, - 'class="sub upd float-right"', - true -); -$botom_update .= '
'; - -$events_filter .= $botom_update; - -$events_filter .= '
'; -// This is the filter div. -$user_filter = db_get_value( - 'default_event_filter', - 'tusuario', - 'id_user', - $config['id_user'] -); -$user_default_filter = db_get_all_rows_filter( - 'tevent_filter', - ['id_filter' => $user_filter] -); -$user_default_filter = $user_default_filter[0]; - -$id_name = $user_default_filter['id_name']; - -$filter_resume['title'] = empty($id_name) ? __('No filter loaded') : __('Filter loaded').': '.$id_name; - -if (is_metaconsole()) { - ui_toggle($events_filter, __('Show Options')); -} else { - if ($config['pure']) { - ui_toggle($events_filter, __('Event control filter').'. '.$filter_resume['title']); - } else { - ui_toggle($events_filter, __('Event control filter')); - } -} - - -// Error div for ajax messages. -echo "'; -?> - - $fields, - 'event_type' => $types, - 'severity' => $severities, - 'duplicate' => $repeated_sel, - 'alerts' => $alert_events_titles, - 'groups' => $user_groups_array, - 'id_source_event' => $id_source_event, - - ], - ] -); - -if (!empty($result)) { - // Checking the event tags exactly. - // The event query filters approximated tags to keep events - // with several tags. - $acltags = tags_get_user_groups_and_tags($config['id_user'], $access, true); - - foreach ($result as $key => $event_data) { - $has_tags = events_checks_event_tags($event_data, $acltags); - if (!$has_tags) { - unset($result[$key]); - } - } -} - - - -// Delete rnum field generated by oracle_recode_query() function. -if (($config['dbtype'] == 'oracle') && ($result !== false)) { - for ($i = 0; $i < count($result); $i++) { - unset($result[$i]['rnum']); - } -} - -if ($group_rep == 0) { - $sql = 'SELECT COUNT(DISTINCT id_evento) - FROM $event_table te - $event_lj - $sql_post'; - $total_events = (int) db_get_sql($sql); -} else if ($group_rep == 1) { - $total_events = events_get_events_grouped( - $sql_post, - false, - false, - $meta, - $history, - true, - false - ); -} else if ($group_rep == 2) { - $sql = 'SELECT COUNT(*) FROM (select id_agente as total from $event_table te - $event_lj - WHERE id_agente > 0 - $sql_post GROUP BY id_agente ORDER BY id_agente ) AS t'; - $total_events = (int) db_get_sql($sql); -} - -if (empty($result)) { - $result = []; -} - -$allow_action = true; -$allow_pagination = true; -$id_group_filter = $id_group; -require 'events.build_table.php'; - -enterprise_hook('close_meta_frame'); - -unset($table); - -// Values to be used from javascript library. -html_print_input_hidden( - 'ajax_file', - ui_get_full_url('ajax.php', false, false, false) -); -html_print_input_hidden('meta', (int) $meta); -html_print_input_hidden('history', (int) $history); - -ui_require_jquery_file('json'); -ui_include_time_picker(); -?> - +// Deprecated.