This commit is contained in:
Daniel Cebrian 2023-10-10 15:15:43 +02:00
parent 2c352ad9dd
commit a02482ac5d
8 changed files with 251 additions and 95 deletions

View File

@ -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",

View File

@ -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 = '<span class="subtitle">'.__('Unknown agents').'</span>';
$number = html_print_div(

View File

@ -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',

View File

@ -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(

View File

@ -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 .= '</div>';
$output .= '
<div class="marks">
<div class="mark"><div class="line"></div><span class="number">0 %</span></div>
<div class="mark"><div class="line"></div><span class="number">20 %</span></div>
<div class="mark"><div class="line"></div><span class="number">40 %</span></div>
<div class="mark"><div class="line"></div><span class="number">60 %</span></div>
<div class="mark"><div class="line"></div><span class="number">80 %</span></div>
<div class="mark"><div class="line"></div><span class="number">100 %</span></div>
<div class="mark"><div class="line mark0"></div><span class="number">0 %</span></div>
<div class="mark"><div class="line mark20"></div><span class="number number20">20 %</span></div>
<div class="mark"><div class="line mark40"></div><span class="number number40">40 %</span></div>
<div class="mark"><div class="line mark60"></div><span class="number number60">60 %</span></div>
<div class="mark"><div class="line mark80"></div><span class="number number80">80 %</span></div>
<div class="mark"><div class="line mark100"></div><span class="number number100">100 %</span></div>
</div>';
$output .= '</div>';
@ -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
);

View File

@ -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 {

View File

@ -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.'</div>';
$tmp->criticity = $criticity;
// Add event severity to end of text.
$evn = '<a href="javascript:" onclick="show_event_dialog(\''.$tmp->b64.'\')">';
if (isset($external_url) === true && $external_url === true) {
$url = ui_get_full_url('index.php?sec=eventos&sec2=operation/events/events');
$evn = '<a href="'.$url.'&show_event_dialog='.$tmp->b64.'">';
} else {
// Add event severity to end of text.
$evn = '<a href="javascript:" onclick="show_event_dialog(\''.$tmp->b64.'\')">';
}
// 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,

View File

@ -41,8 +41,8 @@
</div>
<div class="br-t">
<div class="padding10">
<span class="subtitle link">
<?php echo __('License usage'); ?> <a href=""><?php echo __('Info'); ?></a>
<span class="subtitle">
<?php echo __('License usage'); ?>
</span>
<?php echo $Overview->getLicenseUsageGraph(); ?>
</div>
@ -52,7 +52,7 @@
</div>
</div>
</div>
<div class="row">
<div class="row flex-nowrap">
<div class="col-7 pdd_5px">
<div class="container">
<div class="title">
@ -62,13 +62,13 @@
<div class="row">
<div class="col-6 br-r br-b">
<div class="subtitle link padding10 padding2">
<?php echo __('Top-10 Tags'); ?> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Top-10 Tags'); ?> <a href="index.php?sec=gusuarios&sec2=godmode/tag/tag"><?php echo __('Info'); ?></a>
</div>
<?php echo $MonitoringElements->getTagsGraph(); ?>
</div>
<div class="col-6 br-b">
<div class="subtitle link padding10 padding2">
<?php echo __('Top-10 module groups'); ?> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Top-10 module groups'); ?> <a href="index.php?sec=view&sec2=extensions/module_groups"><?php echo __('Info'); ?></a>
</div>
<?php echo $MonitoringElements->getModuleGroupGraph(); ?>
</div>
@ -76,13 +76,13 @@
<div class="row">
<div class="col-6">
<div class="subtitle link padding10 padding2">
<?php echo __('Status'); ?> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Status'); ?> <a href="index.php?sec=view&sec2=operation/agentes/estado_agente"><?php echo __('Info'); ?></a>
</div>
<?php echo $MonitoringElements->getMonitoringStatusGraph(); ?>
</div>
<div class="col-6 br-l">
<div class="subtitle link padding10 padding2">
<?php echo __('Top-10 Groups'); ?> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Top-10 Groups'); ?> <a href="index.php?sec=view&sec2=operation/agentes/group_view"><?php echo __('Info'); ?></a>
</div>
<?php echo $MonitoringElements->getAgentGroupsGraph(); ?>
</div>
@ -126,14 +126,14 @@
</div>
</div>
<div class="br-t">
<div class="subtitle link padding10 padding2">
<?php echo __('Reads (last 24 hrs)'); ?> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Reads (last 24 hrs)'); ?>
</div>
<?php echo $Database->getReadsGraph(); ?>
</div>
<div class="br-t">
<div class="subtitle link padding10 padding2">
<?php echo __('Writes (last 24 hrs)'); ?> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Writes (last 24 hrs)'); ?>
</div>
<?php echo $Database->getWritesGraph(); ?>
</div>
@ -156,7 +156,7 @@
<?php echo $Groups->title; ?>
</div>
<div class="subtitle link padding10 padding2">
<?php echo __('Status'); ?> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Status'); ?> <a href="index.php?sec=view&sec2=operation/agentes/group_view"><?php echo __('Info'); ?></a>
</div>
<div id="heatmap-group">
<?php echo $Groups->loading(); ?>
@ -246,7 +246,7 @@
<?php if ($Alerts->checkAclUserList() === true) : ?>
<div id="list-users">
<div class="subtitle link padding10 padding2">
<b><?php echo __('Logged in users (24 hrs)'); ?></b> <a href=""><?php echo __('More details'); ?></a>
<b><?php echo __('Logged in users (24 hrs)'); ?></b> <a href="index.php?sec=gusuarios&sec2=godmode/users/user_list"><?php echo __('More details'); ?></a>
</div>
<?php echo $Alerts->getDataTableUsers(); ?>
</div>
@ -262,25 +262,25 @@
<div class="row">
<div class="col-8 br-r">
<div class="subtitle link padding10 padding2">
<?php echo __('Number of events per hour (24 hrs)'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Number of events per hour (24 hrs)'); ?></b> <a href="index.php?sec=eventos&sec2=operation/events/events&filter[event_view_hr]=24&filter[tag_with]=WyIwIl0=&filter[tag_without]=WyIwIl0="><?php echo __('Info'); ?></a>
</div>
<div id="events-last-24"><?php echo $Events->loading(); ?></div>
<div class="row br-t h100p">
<div class="col-4 br-r">
<div class="subtitle link padding10 padding2">
<?php echo __('Criticality'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Criticality'); ?></b>
</div>
<div id="events-criticality"><?php echo $Events->loading(); ?></div>
</div>
<div class="col-4 br-r">
<div class="subtitle link padding10 padding2">
<?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Status'); ?></b>
</div>
<div id="events-status-validate"><?php echo $Events->loading(); ?></div>
</div>
<div class="col-4">
<div class="subtitle link padding10 padding2">
<?php echo __('Pending validation'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Pending validation'); ?></b>
</div>
<div id="events-status-pending-validate"><?php echo $Events->loading(); ?></div>
</div>
@ -288,7 +288,7 @@
</div>
<div class="col-4">
<div class="subtitle link padding10 padding2">
<?php echo __('Active events (8 hrs)'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<?php echo __('Active events (8 hrs)'); ?></b> <a href="index.php?sec=eventos&sec2=operation/events/events"><?php echo __('Info'); ?></a>
</div>
<?php echo $Events->getDataTableEvents(); ?>
</div>
@ -321,17 +321,17 @@
</div>
</div>
<div class="subtitle link padding10 padding2">
<?php echo __('Top 20 groups'); ?></b> <a href=""><?php echo __('More details'); ?></a>
<?php echo __('Top 20 groups'); ?></b> <a href="index.php?sec=view&sec2=operation/agentes/estado_agente"><?php echo __('More details'); ?></a>
</div>
<?php echo $Agents->getDataTableGroups(); ?>
</div>
<div class="col-6">
<div class="subtitle link padding10 padding2">
<?php echo __('Operating system'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2">
<?php echo __('Operating system'); ?></b>
</div>
<?php echo $Agents->getOperatingSystemGraph(); ?>
<div class="subtitle link padding10 padding2 br-t">
<?php echo __('Status'); ?></b> <a href=""><?php echo __('Info'); ?></a>
<div class="subtitle padding10 padding2 br-t">
<?php echo __('Status'); ?></b>
</div>
<?php echo $Agents->getStatusGraph(); ?>
</div>
@ -344,29 +344,29 @@
<?php echo $Configurations->title; ?>
</div>
<div class="row br-b flex-nowrap">
<div class="col-3 flex flex-column center pdd_20px br-r">
<a href="index.php?sec=view&sec2=operation/agentes/group_view" class="col-3 flex flex-column center pdd_20px br-r">
<?php echo $Configurations->getTotalGroups(); ?>
</div>
<div class="col-3 flex flex-column center pdd_20px br-r">
</a>
<a href="index.php?sec=view&sec2=extensions/agents_modules" class="col-3 flex flex-column center pdd_20px br-r">
<?php echo $Configurations->getTotalModules(); ?>
</div>
<div class="col-3 flex flex-column center pdd_20px br-r">
</a>
<a href="index.php?sec=gmodules&sec2=enterprise/godmode/policies/policies" class="col-3 flex flex-column center pdd_20px br-r">
<?php echo $Configurations->getTotalPolicies(); ?>
</div>
<div class="col-3 flex flex-column center pdd_20px">
</a>
<a href="index.php?sec=gservers&sec2=godmode/servers/plugin" class="col-3 flex flex-column center pdd_20px">
<?php echo $Configurations->getTotalRemotePlugins(); ?>
</div>
</a>
</div>
<div class="row flex-nowrap br-b">
<div class="col-4 flex flex-column center pdd_20px br-r">
<a href="index.php?sec=templates&sec2=godmode/modules/manage_module_templates" class="col-4 flex flex-column center pdd_20px br-r">
<?php echo $Configurations->getTotalModuleTemplate(); ?>
</div>
<div class="col-4 flex flex-column center pdd_20px br-r">
</a>
<a href="index.php?sec=view&sec2=operation/agentes/estado_agente&status=5" class="col-4 flex flex-column center pdd_20px br-r">
<?php echo $Configurations->getNotInitModules(); ?>
</div>
<div class="col-4 flex flex-column center pdd_20px">
</a>
<a href="index.php?sec=view&sec2=operation/agentes/estado_agente&status=3" class="col-4 flex flex-column center pdd_20px">
<?php echo $Configurations->getTotalUnknowAgents(); ?>
</div>
</a>
</div>
</div>
<?php if ($ScheduledDowntime->checkAcl() === true) : ?>