From a02482ac5d26de3637e8b06314b5b6c7d499e2dd Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Tue, 10 Oct 2023 15:15:43 +0200 Subject: [PATCH] #10194 added links --- .../javascript/general_tactical_view.js | 2 +- .../TacticalView/elements/Configurations.php | 4 +- .../lib/TacticalView/elements/Events.php | 82 +++++++++++++ .../lib/TacticalView/elements/LogStorage.php | 4 +- .../lib/TacticalView/elements/Overview.php | 109 ++++++++++++------ .../include/styles/general_tactical_view.css | 49 ++++++-- pandora_console/operation/events/events.php | 16 ++- pandora_console/views/tacticalView/view.php | 80 ++++++------- 8 files changed, 251 insertions(+), 95 deletions(-) diff --git a/pandora_console/include/javascript/general_tactical_view.js b/pandora_console/include/javascript/general_tactical_view.js index 817315db50..25e5c5af7f 100644 --- a/pandora_console/include/javascript/general_tactical_view.js +++ b/pandora_console/include/javascript/general_tactical_view.js @@ -30,7 +30,7 @@ $(document).ready(function() { url: "ajax.php", data: { page: "include/ajax/general_tactical_view.ajax", - method: "getEventsStatusValidateGraph", + method: "getEventsStatusGraph", class: "Events" }, type: "POST", diff --git a/pandora_console/include/lib/TacticalView/elements/Configurations.php b/pandora_console/include/lib/TacticalView/elements/Configurations.php index 51b9dcd6b5..614d5bbadd 100644 --- a/pandora_console/include/lib/TacticalView/elements/Configurations.php +++ b/pandora_console/include/lib/TacticalView/elements/Configurations.php @@ -208,8 +208,8 @@ class Configurations extends Element */ public function getTotalUnknowAgents():string { - $value = $this->valueMonitoring('total_notinit'); - $total = round($value[0]['total_unknown']); + $value = $this->valueMonitoring('total_unknown'); + $total = round($value[0]['datos']); $image = html_print_image('images/Tactical_Unknown_agent.svg', true); $text = ''.__('Unknown agents').''; $number = html_print_div( diff --git a/pandora_console/include/lib/TacticalView/elements/Events.php b/pandora_console/include/lib/TacticalView/elements/Events.php index b304e59300..b83e56f8fd 100644 --- a/pandora_console/include/lib/TacticalView/elements/Events.php +++ b/pandora_console/include/lib/TacticalView/elements/Events.php @@ -40,6 +40,7 @@ class Events extends Element 'getEventsGraph', 'getEventsCriticalityGraph', 'getEventsStatusValidateGraph', + 'getEventsStatusGraph', ]; } @@ -333,6 +334,86 @@ class Events extends Element } + /** + * Return the html graph of events in last 8h grouped by status. + * + * @return string + */ + public function getEventsStatusGraph():string + { + global $config; + $id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false)); + if (in_array(0, $id_groups) === false) { + foreach ($id_groups as $key => $id_group) { + if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) { + unset($id_groups[$key]); + } + } + } + + if (users_can_manage_group_all() === true) { + $id_groups[] = 0; + } + + $id_groups = implode(',', $id_groups); + $interval8h = (time() - 86400); + $sql = 'SELECT criticity, count(*) AS total + FROM tevento + WHERE utimestamp >= '.$interval8h.' AND id_grupo IN ('.$id_groups.') + group by criticity'; + + $rows = db_process_sql($sql); + + $labels = []; + $data = []; + $colors = []; + foreach ($rows as $key => $row) { + switch ($row['criticity']) { + case EVENT_CRIT_CRITICAL: + $label = __('CRITICAL'); + $colors[] = COL_CRITICAL; + break; + + case EVENT_CRIT_NORMAL: + $label = __('NORMAL'); + $colors[] = COL_NORMAL; + break; + + case EVENT_CRIT_WARNING: + $label = __('WARNING'); + $colors[] = COL_WARNING; + break; + + default: + $colors[] = COL_UNKNOWN; + $label = __('UNKNOWN'); + break; + } + + $labels[] = $this->controlSizeText($label); + $data[] = $row['total']; + } + + $options = [ + 'labels' => $labels, + 'legend' => ['display' => false], + 'cutout' => 80, + 'nodata_image' => ['width' => '100%'], + 'colors' => $colors, + ]; + $pie = ring_graph($data, $options); + $output = html_print_div( + [ + 'content' => $pie, + 'style' => 'margin: 0 auto; max-width: 80%; max-height: 220px;', + ], + true + ); + + return $output; + } + + /** * Return the datatable events in last 8 hours. * @@ -360,6 +441,7 @@ class Events extends Element 'ajax_data' => [ 'get_events' => 1, 'compact_date' => 1, + 'external_url' => 1, ], 'order' => [ 'field' => 'timestamp', diff --git a/pandora_console/include/lib/TacticalView/elements/LogStorage.php b/pandora_console/include/lib/TacticalView/elements/LogStorage.php index 27e8b61fbb..fbf950024f 100644 --- a/pandora_console/include/lib/TacticalView/elements/LogStorage.php +++ b/pandora_console/include/lib/TacticalView/elements/LogStorage.php @@ -197,11 +197,11 @@ class LogStorage extends Element { $data = $this->valueMonitoring('Longest data archived'); $date = $data[0]['datos']; - if ($date > 0) { + if ($date > 0 && $this->isEnabled() === true) { $interval = (time() - strtotime($date)); $days = round($interval / 86400); } else { - $days = '-'; + $days = 'N/A'; } return html_print_div( diff --git a/pandora_console/include/lib/TacticalView/elements/Overview.php b/pandora_console/include/lib/TacticalView/elements/Overview.php index 01e4a67a49..af1a7ab2ae 100644 --- a/pandora_console/include/lib/TacticalView/elements/Overview.php +++ b/pandora_console/include/lib/TacticalView/elements/Overview.php @@ -44,6 +44,7 @@ class Overview extends Element $this->ajaxMethods = [ 'getLogSizeStatus', 'getServerStatus', + 'getCPULoadGraph', ]; $this->interval = 300000; $this->refreshConfig = [ @@ -55,6 +56,10 @@ class Overview extends Element 'id' => 'status-servers', 'method' => 'getServerStatus', ], + 'cpuStatus' => [ + 'id' => 'status-cpu', + 'method' => 'getCPULoadGraph', + ], ]; } @@ -153,19 +158,65 @@ class Overview extends Element */ public function getLicenseUsageGraph():string { - // TODO: show real data. - $data = [ - 'free_agents' => [ - 'label' => __('Free agents'), - 'perc' => 40, - 'color' => '#5C63A2', - ], - 'agents_used' => [ - 'label' => __('Agents used'), - 'perc' => 60, - 'color' => '#1C4E6B', - ], - ]; + if (enterprise_installed() === true) { + $info = license_get_info(); + if ($info['limit'] > $info['count']) { + $used = round(($info['count'] / $info['limit']) * 100); + $free = (100 - $used); + } else { + $free = 100; + $used = 0; + } + + $data = [ + 'agents_used' => [ + 'label' => __('% Agents used'), + 'perc' => $used, + 'color' => '#1C4E6B', + ], + 'free_agents' => [ + 'label' => __('% Free agents'), + 'perc' => $free, + 'color' => '#5C63A2', + ], + ]; + } else { + $agents = agents_get_agents(); + $enabled_agents = agents_get_agents( + false, + false, + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 1 + ); + if (is_array($agents) === true) { + $total = count($agents); + } else { + $total = 0; + } + + if ($total > 0 && is_array($enabled_agents) === true) { + $total_disabled_agents = round((($total - count($enabled_agents)) * 100) / $total); + $total_enabled_agents = round((count($enabled_agents) * 100) / $total); + } + + $data = [ + 'agents_enabled' => [ + 'label' => __('% Agents enabled'), + 'perc' => $total_enabled_agents, + 'color' => '#1C4E6B', + ], + 'agents_disabled' => [ + 'label' => __('% Agents disabled'), + 'perc' => $total_disabled_agents, + 'color' => '#5C63A2', + ], + ]; + } $bar = $this->printHorizontalBar($data); $output = html_print_div( @@ -216,12 +267,12 @@ class Overview extends Element $output .= ''; $output .= '
-
0 %
-
20 %
-
40 %
-
60 %
-
80 %
-
100 %
+
0 %
+
20 %
+
40 %
+
60 %
+
80 %
+
100 %
'; $output .= ''; @@ -236,20 +287,9 @@ class Overview extends Element */ public function getCPULoadGraph():string { - $sql = 'SELECT - utimestamp, - DATE_FORMAT(FROM_UNIXTIME(utimestamp), "%Y-%m-%d %H:00:00") AS hour, - COUNT(*) AS xml_proccessed - FROM tagent_access - WHERE FROM_UNIXTIME(utimestamp) >= NOW() - INTERVAL 24 HOUR - GROUP BY hour - ORDER BY hour;'; - - $rows = db_process_sql($sql); $data_last24h = $this->valueMonitoring('CPU Load', (time() - 86400), time()); $dates = []; $cpu_load = []; - $total = 0; foreach ($data_last24h as $key => $raw_data) { $dates[] = date('H:m:s', $raw_data['utimestamp']); $cpu_load[] = $raw_data['datos']; @@ -287,14 +327,7 @@ class Overview extends Element 'content' => line_graph($data, $options), 'class' => 'margin-top-5 w100p h100p', 'style' => 'max-height: 50px;', - ], - true - ); - - $total = html_print_div( - [ - 'content' => $total, - 'class' => 'text-xl', + 'id' => 'status-cpu', ], true ); diff --git a/pandora_console/include/styles/general_tactical_view.css b/pandora_console/include/styles/general_tactical_view.css index 3763ef1bd9..b758fd7738 100644 --- a/pandora_console/include/styles/general_tactical_view.css +++ b/pandora_console/include/styles/general_tactical_view.css @@ -135,13 +135,14 @@ min-height: 550px; } #horizontalBar { - padding: 0px 20px; + margin: 0px 20px; position: relative; } #horizontalBar .bar { display: flex; color: white; height: 43px; + justify-content: space-between; } #horizontalBar .bar div { @@ -153,7 +154,6 @@ .marks { display: flex; - justify-content: space-between; margin-top: 20px; } .marks .line { @@ -162,14 +162,49 @@ width: 1px; position: absolute; top: 24px; - margin-left: 11px; } -.mark:nth-child(1) .line { - margin-left: 0px; +.mark { + min-height: 30px; +} +.mark .number { + position: absolute; +} +.mark0 { + left: 0%; +} +.mark20 { + left: 20%; +} +.mark40 { + left: 40%; +} +.mark60 { + left: 60%; +} +.mark80 { + left: 80%; +} +.mark100 { + left: 100%; +} +.number20 { + left: 19%; +} +.number40 { + left: 39%; +} +.number60 { + left: 59%; +} +.number80 { + left: 79%; +} +.number100 { + left: 95%; } -.mark:nth-last-child(1) .line { - margin-left: 31px; +.mark:nth-child(1) { + text-align: left; } .labels { diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 944b7f12b4..3a391338ed 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -338,6 +338,7 @@ if (is_metaconsole() === true // Ajax responses. if (is_ajax() === true) { $get_events = (int) get_parameter('get_events', 0); + $external_url = (bool) get_parameter('external_url', 0); $table_id = get_parameter('table_id', ''); $groupRecursion = (bool) get_parameter('groupRecursion', false); $compact_date = (int) get_parameter('compact_date', 0); @@ -472,7 +473,7 @@ if (is_ajax() === true) { $data = array_reduce( $events, - function ($carry, $item) use ($table_id, &$redirection_form_id, $filter, $compact_date) { + function ($carry, $item) use ($table_id, &$redirection_form_id, $filter, $compact_date, $external_url) { global $config; $tmp = (object) $item; @@ -743,8 +744,13 @@ if (is_ajax() === true) { $criticity .= $color.'" data-title="'.$text.'" data-use_title_for_force_title="1">'.$text.''; $tmp->criticity = $criticity; - // Add event severity to end of text. - $evn = ''; + if (isset($external_url) === true && $external_url === true) { + $url = ui_get_full_url('index.php?sec=eventos&sec2=operation/events/events'); + $evn = ''; + } else { + // Add event severity to end of text. + $evn = ''; + } // Grouped events. if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { @@ -3588,7 +3594,7 @@ function show_event_dialo(event, dialog_page) { // History mode flag var history = $("#hidden-history").val(); - + console.log(event); jQuery.post( ajax_file, { @@ -3606,7 +3612,7 @@ function show_event_dialo(event, dialog_page) { .empty() .append(data) .dialog({ - title: event.evento, + title: event.event_title, resizable: true, draggable: true, modal: true, diff --git a/pandora_console/views/tacticalView/view.php b/pandora_console/views/tacticalView/view.php index b1b37d3d46..e6e5be13a7 100644 --- a/pandora_console/views/tacticalView/view.php +++ b/pandora_console/views/tacticalView/view.php @@ -41,8 +41,8 @@
- - + + getLicenseUsageGraph(); ?>
@@ -52,7 +52,7 @@
-
+
@@ -62,13 +62,13 @@
getTagsGraph(); ?>
getModuleGroupGraph(); ?>
@@ -76,13 +76,13 @@
getMonitoringStatusGraph(); ?>
getAgentGroupsGraph(); ?>
@@ -126,14 +126,14 @@
-
- @@ -156,7 +156,7 @@ title; ?>
loading(); ?> @@ -246,7 +246,7 @@ checkAclUserList() === true) : ?>
getDataTableUsers(); ?>
@@ -262,25 +262,25 @@
loading(); ?>
-
-
- @@ -288,7 +288,7 @@
getDataTableEvents(); ?>
@@ -321,17 +321,17 @@
getDataTableGroups(); ?>
checkAcl() === true) : ?>