#10347 refactoring and add link to events in graph

This commit is contained in:
Daniel Cebrian 2023-03-03 13:13:49 +01:00
parent cdf359481a
commit 7562a9253a
6 changed files with 138 additions and 28 deletions

View File

@ -30,12 +30,32 @@ global $config;
check_login(); 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', ''); $id_group = get_parameter('id_group', '');
if (empty($id_group) === true) { if (empty($id_group) === true) {
return; 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) { if (is_metaconsole() === false) {
// Header. // Header.
ui_print_standard_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[0][0] = groups_get_heat_map_agents($id_groups, 450, 100);
$table_col1->data[1][0] = tactical_groups_get_agents_and_monitoring($id_groups); $table_col1->data[1][0] = tactical_groups_get_agents_and_monitoring($id_groups);
$distribution_by_so = '<table cellpadding=0 cellspacing=0 class="databox pies mrgn_top_15px" width=100%><tr><td style="width:50%;">'; $distribution_by_so = '<table cellpadding=0 cellspacing=0 class="databox pies graph-distribution-so" width=100%><tr><td style="width:50%;">';
$distribution_by_so .= '<fieldset class="padding-0 databox tactical_set" id="distribution_by_so_graph">'; $distribution_by_so .= '<fieldset class="padding-0 databox tactical_set" id="distribution_by_so_graph">';
$distribution_by_so .= '<legend>'.__('Distribution by so').'</legend>'; $distribution_by_so .= '<legend>'.__('Distribution by os').'</legend>';
$distribution_by_so .= html_print_image('images/spinner.gif', true, ['id' => 'spinner_distribution_by_so_graph']); $distribution_by_so .= html_print_image('images/spinner.gif', true, ['id' => 'spinner_distribution_by_so_graph']);
$distribution_by_so .= '</fieldset>'; $distribution_by_so .= '</fieldset>';
$distribution_by_so .= '</td></tr></table>'; $distribution_by_so .= '</td></tr></table>';
@ -214,6 +234,13 @@ echo '<div id="modal-info-agent"></div>'
success: function(data) { success: function(data) {
$("#spinner_events_by_agents_group_graph").hide(); $("#spinner_events_by_agents_group_graph").hide();
$("#events_by_agents_group_graph").append(data); $("#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]=<?php echo $id_group; ?>")
}
});
} }
}); });

View File

@ -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) function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true, $noWaterMark=true)
{ {
global $config; 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) function graph_events_agent_by_group($id_group, $width=300, $height=200, $noWaterMark=true, $time_limit=false, $recursive=true)
{ {
global $config; 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, 'SELECT DISTINCT(id_agente) AS id_agente,
COUNT(id_agente) AS count COUNT(id_agente) AS count
FROM tevento te FROM tevento te
WHERE 1=1 %s %s WHERE 1=1 AND estado = 0
%s %s
GROUP BY id_agente GROUP BY id_agente
ORDER BY count DESC LIMIT 8', ORDER BY count DESC LIMIT 8',
$tags_condition, $tags_condition,

View File

@ -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 // If there are not groups to query, we jump to nextone
$default_total = [ $default_total = [
@ -1656,26 +1656,32 @@ function groups_monitor_alerts_total_counters($group_array)
} }
$group_clause = implode(',', $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( $sql = 'SELECT
"SELECT COUNT(tatm.id) AS total,
COUNT(tatm.id) AS total, SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired
SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired FROM talert_template_modules tatm
FROM talert_template_modules tatm INNER JOIN tagente_modulo tam
INNER JOIN tagente_modulo tam ON tatm.id_agent_module = tam.id_agente_modulo
ON tatm.id_agent_module = tam.id_agente_modulo INNER JOIN tagente ta
INNER JOIN tagente ta ON ta.id_agente = tam.id_agente
ON ta.id_agente = tam.id_agente WHERE ta.id_agente IN (
WHERE ta.id_agente IN ( SELECT ta.id_agente
SELECT ta.id_agente FROM tagente ta';
FROM tagente ta if ($secondary_group === true) {
LEFT JOIN tagent_secondary_group tasg $sql .= ' LEFT JOIN tagent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
ON ta.id_agente = tasg.id_agent }
WHERE ta.disabled = 0
AND $group_clause $sql .= " WHERE ta.disabled = 0
) AND tam.disabled = 0" AND $group_clause
); ) AND tam.disabled = 0";
$alerts = db_get_row_sql($sql);
return ($alerts === false) ? $default_total : $alerts; 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) function groups_get_heat_map_agents(array $id_group, float $width=0, float $height=0)
{ {
ui_require_css_file('heatmap'); ui_require_css_file('heatmap');
@ -2568,14 +2583,14 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
const total_modules = '<?php echo $total_agents; ?>'; const total_agents = '<?php echo $total_agents; ?>';
function getRandomInteger(min, max) { function getRandomInteger(min, max) {
return Math.floor(Math.random() * max) + min; return Math.floor(Math.random() * max) + min;
} }
function oneSquare(solid, time) { function oneSquare(solid, time) {
var randomPoint = getRandomInteger(1, total_modules); var randomPoint = getRandomInteger(1, total_agents);
let target = $(`#rect_${randomPoint}`); let target = $(`#rect_${randomPoint}`);
let class_name = target.attr('class'); let class_name = target.attr('class');
class_name = class_name.split('_')[0]; class_name = class_name.split('_')[0];
@ -2587,7 +2602,7 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig
} }
let cont = 0; let cont = 0;
while (cont < Math.ceil(total_modules / 3)) { while (cont < Math.ceil(total_agents / 3)) {
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900)); oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
cont ++; cont ++;
} }
@ -2601,6 +2616,13 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig
} }
/**
* Return html count from agents and monitoring by group.
*
* @param [type] $id_groups
*
* @return string Html
*/
function tactical_groups_get_agents_and_monitoring($id_groups) function tactical_groups_get_agents_and_monitoring($id_groups)
{ {
global $config; global $config;
@ -2650,11 +2672,17 @@ function tactical_groups_get_agents_and_monitoring($id_groups)
} }
/**
* Return html count from stats alerts by group.
*
* @param [type] $id_groups
* @return string Html.
*/
function tactical_groups_get_stats_alerts($id_groups) function tactical_groups_get_stats_alerts($id_groups)
{ {
global $config; global $config;
$alerts = groups_monitor_alerts_total_counters($id_groups); $alerts = groups_monitor_alerts_total_counters($id_groups, false);
$data = [ $data = [
'monitor_alerts' => $alerts['total'], 'monitor_alerts' => $alerts['total'],
'monitor_alerts_fired' => $alerts['fired'], 'monitor_alerts_fired' => $alerts['fired'],
@ -2717,6 +2745,16 @@ function tactical_groups_get_stats_alerts($id_groups)
} }
/**
* Return html count from stats modules by group.
*
* @param [type] $id_groups
* @param integer $graph_width
* @param integer $graph_height
* @param boolean $links
* @param boolean $data_agents
* @return void
*/
function groups_get_stats_modules_status($id_groups, $graph_width=250, $graph_height=150, $links=false, $data_agents=false) function groups_get_stats_modules_status($id_groups, $graph_width=250, $graph_height=150, $links=false, $data_agents=false)
{ {
global $config; global $config;

View File

@ -1,4 +1,4 @@
/* global $ */ /* global $, load_modal */
function showInfoAgent(id_agent) { function showInfoAgent(id_agent) {
load_modal({ load_modal({
target: $("#modal-info-agent"), target: $("#modal-info-agent"),

View File

@ -479,6 +479,11 @@ class Group extends Entity
} }
/**
* Draw a graph distribution so by group.
*
* @return void
*/
public static function distributionBySoGraph() public static function distributionBySoGraph()
{ {
global $config; global $config;
@ -493,6 +498,11 @@ class Group extends Entity
} }
/**
* Draw a graph events agent by group.
*
* @return void
*/
public static function groupEventsByAgent() public static function groupEventsByAgent()
{ {
global $config; global $config;
@ -507,6 +517,11 @@ class Group extends Entity
} }
/**
* Draw in modal a agent info
*
* @return void
*/
public static function loadInfoAgent() public static function loadInfoAgent()
{ {
$extradata = get_parameter('extradata', ''); $extradata = get_parameter('extradata', '');
@ -577,6 +592,11 @@ class Group extends Entity
} }
/**
* Get agents by group for datatable.
*
* @return void
*/
public static function getAgentsByGroup() public static function getAgentsByGroup()
{ {
global $config; global $config;

View File

@ -26,3 +26,6 @@ rect {
#list_agents_tactical_wrapper { #list_agents_tactical_wrapper {
max-height: 600px; max-height: 600px;
} }
.graph-distribution-so {
margin-top: 55px;
}