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 .= '