From 7562a9253af43ee731052c254d35b0012ad9de96 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Fri, 3 Mar 2023 13:13:49 +0100 Subject: [PATCH] #10347 refactoring and add link to events in graph --- pandora_console/godmode/groups/tactical.php | 31 ++++++- pandora_console/include/functions_graph.php | 24 +++++- pandora_console/include/functions_groups.php | 86 +++++++++++++------ .../include/javascript/tactical_groups.js | 2 +- pandora_console/include/lib/Group.php | 20 +++++ .../include/styles/tactical_groups.css | 3 + 6 files changed, 138 insertions(+), 28 deletions(-) diff --git a/pandora_console/godmode/groups/tactical.php b/pandora_console/godmode/groups/tactical.php index 74c8158ad2..037af05723 100644 --- a/pandora_console/godmode/groups/tactical.php +++ b/pandora_console/godmode/groups/tactical.php @@ -30,12 +30,32 @@ global $config; check_login(); +if (! check_acl($config['id_user'], 0, 'AR')) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access Tactical View Group' + ); + include 'general/noaccess.php'; + return; +} + + $id_group = get_parameter('id_group', ''); if (empty($id_group) === true) { return; } +$user_groups_acl = users_get_groups(false, 'AR'); +if (in_array(groups_get_name($id_group), $user_groups_acl) === false) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access Tactical View Group' + ); + include 'general/noaccess.php'; + return; +} + if (is_metaconsole() === false) { // Header. ui_print_standard_header( @@ -84,9 +104,9 @@ $table_col1->width = '100%'; $table_col1->data[0][0] = groups_get_heat_map_agents($id_groups, 450, 100); $table_col1->data[1][0] = tactical_groups_get_agents_and_monitoring($id_groups); -$distribution_by_so = '
'; +$distribution_by_so = '
'; $distribution_by_so .= '
'; -$distribution_by_so .= ''.__('Distribution by so').''; +$distribution_by_so .= ''.__('Distribution by os').''; $distribution_by_so .= html_print_image('images/spinner.gif', true, ['id' => 'spinner_distribution_by_so_graph']); $distribution_by_so .= '
'; $distribution_by_so .= '
'; @@ -214,6 +234,13 @@ echo '' success: function(data) { $("#spinner_events_by_agents_group_graph").hide(); $("#events_by_agents_group_graph").append(data); + const canvas = $('#events_by_agents_group_graph canvas')[0]; + canvas.addEventListener('click', function(event) { + var middle_canvas = $('#events_by_agents_group_graph canvas').width() / 2; + if(event.layerX < middle_canvas){ + window.location.replace("index.php?sec=eventos&sec2=operation/events/events&filter[id_group_filter]=") + } + }); } }); diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d1cd1c2083..977076824b 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -5341,6 +5341,16 @@ function get_baseline_data( } +/** + * Draw graph SO agents by group. + * + * @param [type] $id_group + * @param integer $width + * @param integer $height + * @param boolean $recursive + * @param boolean $noWaterMark + * @return string Graph + */ function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true, $noWaterMark=true) { global $config; @@ -5408,6 +5418,17 @@ function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true, } +/** + * Draw graph events by group + * + * @param [type] $id_group + * @param integer $width + * @param integer $height + * @param boolean $noWaterMark + * @param boolean $time_limit + * @param boolean $recursive + * @return string Graph + */ function graph_events_agent_by_group($id_group, $width=300, $height=200, $noWaterMark=true, $time_limit=false, $recursive=true) { global $config; @@ -5443,7 +5464,8 @@ function graph_events_agent_by_group($id_group, $width=300, $height=200, $noWate 'SELECT DISTINCT(id_agente) AS id_agente, COUNT(id_agente) AS count FROM tevento te - WHERE 1=1 %s %s + WHERE 1=1 AND estado = 0 + %s %s GROUP BY id_agente ORDER BY count DESC LIMIT 8', $tags_condition, diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 54d0845a56..1800f09652 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1642,7 +1642,7 @@ function groups_monitor_fired_alerts($group_array) } -function groups_monitor_alerts_total_counters($group_array) +function groups_monitor_alerts_total_counters($group_array, $secondary_group=true) { // If there are not groups to query, we jump to nextone $default_total = [ @@ -1656,26 +1656,32 @@ function groups_monitor_alerts_total_counters($group_array) } $group_clause = implode(',', $group_array); - $group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))"; + if ($secondary_group === true) { + $group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))"; + } else { + $group_clause = "(ta.id_grupo IN ($group_clause))"; + } - $alerts = db_get_row_sql( - "SELECT - COUNT(tatm.id) AS total, - SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired - FROM talert_template_modules tatm - INNER JOIN tagente_modulo tam - ON tatm.id_agent_module = tam.id_agente_modulo - INNER JOIN tagente ta - ON ta.id_agente = tam.id_agente - WHERE ta.id_agente IN ( - SELECT ta.id_agente - FROM tagente ta - LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.disabled = 0 - AND $group_clause - ) AND tam.disabled = 0" - ); + $sql = 'SELECT + COUNT(tatm.id) AS total, + SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired + FROM talert_template_modules tatm + INNER JOIN tagente_modulo tam + ON tatm.id_agent_module = tam.id_agente_modulo + INNER JOIN tagente ta + ON ta.id_agente = tam.id_agente + WHERE ta.id_agente IN ( + SELECT ta.id_agente + FROM tagente ta'; + if ($secondary_group === true) { + $sql .= ' LEFT JOIN tagent_secondary_group tasg ON ta.id_agente = tasg.id_agent'; + } + + $sql .= " WHERE ta.disabled = 0 + AND $group_clause + ) AND tam.disabled = 0"; + + $alerts = db_get_row_sql($sql); return ($alerts === false) ? $default_total : $alerts; } @@ -2453,6 +2459,15 @@ function groups_get_group_deep($id_group) } +/** + * Heat map from agents by group + * + * @param array $id_group + * @param integer $width + * @param integer $height + * + * @return string Html Graph. + */ function groups_get_heat_map_agents(array $id_group, float $width=0, float $height=0) { ui_require_css_file('heatmap'); @@ -2568,14 +2583,14 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig ?>