#10740 heatmap improvements

This commit is contained in:
Daniel Maya 2023-04-04 15:14:10 +02:00
parent 89aa227b98
commit dc654c0b6d
6 changed files with 240 additions and 47 deletions

View File

@ -137,6 +137,7 @@ if (is_ajax() === true) {
switch ($type) {
case 0:
case 3:
default:
$label = __('Group');
$input = html_print_input(
@ -234,10 +235,6 @@ if (is_ajax() === true) {
'5'
);
break;
case 3:
// Empty.
break;
}
echo html_print_label_input_block(
@ -246,6 +243,7 @@ if (is_ajax() === true) {
[
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
'div_id' => 'filter_type',
]
);
}
@ -259,10 +257,19 @@ if (is_ajax() === true) {
$nd->connect();
}
echo '<div class="box-flat white_table_graph">';
switch ($type) {
case 3:
case 2:
$data = db_get_row('tagente_modulo', 'id_agente_modulo', $id);
$sql = sprintf(
'SELECT * FROM tagente_modulo ag
INNER JOIN tagente_estado ae ON ag.id_agente_modulo = ae.id_agente_modulo
WHERE ag.id_agente_modulo = %d',
$id
);
$data = db_get_row_sql($sql);
// Nombre.
$link = sprintf(
@ -298,6 +305,92 @@ if (is_ajax() === true) {
echo '<p class="title-dialog">'.__('Module group').'</p>';
echo '<p class="info-dialog">'.$group.'</p>';
echo '</div>';
$graph_type = return_graphtype($data['module_type']);
$url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false);
$handle = dechex(crc32($data['id_agente_modulo'].$data['module_name']));
$win_handle = 'day_'.$handle;
$graph_params = [
'type' => $graph_type,
'period' => SECONDS_1DAY,
'id' => $data['id_agente_modulo'],
'refresh' => SECONDS_10MINUTES,
];
$graph_params_str = http_build_query($graph_params);
$link = 'winopeng_var(\''.$url.'?'.$graph_params_str.'\',\''.$win_handle.'\', 800, 480)';
$img_graph = html_print_anchor(
[
'href' => 'javascript:'.$link,
'content' => html_print_image('images/module-graph.svg', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter main_menu_icon']),
],
true
);
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Data').'</p>';
$data_module = '';
if (is_numeric($data['datos'])) {
$data_module = remove_right_zeros(
number_format(
$data['datos'],
$config['graph_precision'],
$config['decimal_separator'],
$config['thousand_separator']
)
);
echo '<p class="info-dialog">'.$data_module.' '.$data['unit'].'&nbsp;&nbsp;&nbsp;'.$img_graph.'</p>';
} else {
$data_module = $data['datos'];
echo '<p class="info-dialog">'.$data['datos'].' '.$data['unit'].'&nbsp;&nbsp;&nbsp;'.$img_graph.'</p>';
}
echo '</div>';
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Date of last data').'</p>';
echo '<p class="info-dialog">'.date('Y-m-d H:i:s', $data['utimestamp']).'</p>';
echo '</div>';
$status = modules_get_agentmodule_status($id);
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
$status = ui_print_status_image('module_ok.png', $data_module, true);
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$status = ui_print_status_image('module_critical.png', $data_module, false);
break;
case AGENT_MODULE_STATUS_WARNING:
$status = ui_print_status_image('module_warning.png', $data_module, false);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
$status = ui_print_status_image('module_alertsfired.png', $data_module, false);
break;
case 4:
$status = ui_print_status_image('module_no_data.png', $data_module, false);
break;
default:
case AGENT_MODULE_STATUS_UNKNOWN:
$status = ui_print_status_image('module_unknown.png', $data_module, false);
break;
}
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Status').'</p>';
echo '<div class="status_rounded_rectangles">'.$status.'</div>';
echo '</div>';
break;
case 1:
@ -381,6 +474,43 @@ if (is_ajax() === true) {
echo '<p class="info-dialog">'.$data['comentarios'].'</p>';
echo '</div>';
// Last contact.
$lastContactDate = ui_print_timestamp($data['ultimo_contacto'], true);
$remoteContactDate = ($data['ultimo_contacto_remoto'] === '01-01-1970 00:00:00') ? __('Never') : date_w_fixed_tz($data['ultimo_contacto_remoto']);
$lastAndRemoteContact = sprintf('%s / %s', $lastContactDate, $remoteContactDate);
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Last contact').' / '.__('Remote').'</p>';
echo '<p class="info-dialog">'.$lastAndRemoteContact.'</p>';
echo '</div>';
// Next contact progress.
$progress = agents_get_next_contact($id);
$tempTimeToShow = ($data['intervalo'] - (strtotime('now') - strtotime($data['ultimo_contacto'])));
$progressCaption = ($tempTimeToShow >= 0) ? sprintf('%d s', $tempTimeToShow) : __('Out of bounds');
$ajaxNextContactInterval = (empty($data['intervalo']) === true) ? 0 : (100 / $data['intervalo']);
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Next contact').'</p>';
echo '<p class="info-dialog">'.ui_progress(
$progress,
'80%',
'1.2',
'#ececec',
true,
$progressCaption,
[
'page' => 'operation/agentes/ver_agente',
'interval' => $ajaxNextContactInterval,
'data' => [
'id_agente' => $id,
'refresh_contact' => 1,
],
]
).'</p>';
echo '</div>';
// Group.
$secondary_groups = '';
$secondary = enterprise_hook('agents_get_secondary_groups', [$data['id_agente']]);
@ -394,6 +524,27 @@ if (is_ajax() === true) {
echo '<p class="info-dialog">'.groups_get_name($data['id_grupo']).$secondary_groups.'</p>';
echo '</div>';
echo '<div class="div-dialog">';
echo graph_agent_status(
$id,
150,
150,
true,
false,
false,
true
);
echo '</div>';
echo '<div class="div-dialog" style="justify-content: center;">';
echo reporting_tiny_stats(
$data,
true,
'agent',
// Useless.
':',
true
);
echo '</div>';
// Events.
$result_graph_event = enterprise_hook(
@ -419,6 +570,8 @@ if (is_ajax() === true) {
break;
}
echo '</div>';
if (empty($id_server) === false) {
$nd->disconnect();
}

View File

@ -282,7 +282,6 @@ class Heatmap
while (cont <= limit) {
if (typeof lista[cont] !== 'undefined') {
const rect = document.getElementsByName(`${lista[cont]['id']}`);
console.log(rect[0]);
$(`#${rect[0].id}`).removeClass();
$(`#${rect[0].id}`).addClass(`${lista[cont]['status']} hover`);
}
@ -938,10 +937,27 @@ class Heatmap
if (users_is_admin() === false) {
$user_groups = array_keys(users_get_groups($config['user'], 'AR', false));
if (empty($user_groups) === false) {
if (empty($this->filter) === false && empty(current($this->filter)) === false) {
$user_groups = array_intersect($this->filter, $user_groups);
$id_user_groups = sprintf(
'INNER JOIN tagente a ON a.id_agente = ae.id_agente
AND a.id_grupo IN (%s)',
implode(',', $user_groups)
);
} else {
$id_user_groups = sprintf(
'INNER JOIN tagente a ON a.id_agente = ae.id_agente
AND a.id_grupo IN (%s)',
implode(',', $user_groups)
);
}
}
} else {
if (empty($this->filter) === false && empty(current($this->filter)) === false) {
$id_user_groups = sprintf(
'INNER JOIN tagente a ON a.id_agente = ae.id_agente
AND a.id_grupo IN (%s)',
implode(',', $user_groups)
implode(',', $this->filter)
);
}
}
@ -1292,13 +1308,31 @@ class Heatmap
const id = name.split('|')[0];
const server = name.split('|')[1];
let height = 400;
let width = 530;
switch (type) {
case 0:
height = 670;
width = 460;
break;
case 2:
case 3:
height = 450;
width = 460;
break;
default:
break;
}
$("#info_dialog").dialog({
resizable: true,
draggable: true,
modal: true,
closeOnEscape: true,
height: 400,
width: 530,
height: height,
width: width,
title: '<?php echo __('Info'); ?>',
open: function() {
$.ajax({

View File

@ -1571,16 +1571,12 @@ function type_change() {
var type = document.getElementById("type").value;
switch (type) {
case "3":
$("#li_tags").hide();
$("#li_groups").hide();
$("#li_module_groups").hide();
break;
case "2":
$("#li_tags").hide();
$("#li_groups").hide();
$("#li_module_groups").show();
break;
case "1":
$("#li_tags").show();
$("#li_groups").hide();
@ -1588,6 +1584,7 @@ function type_change() {
break;
default:
case "3":
case "0":
$("#li_tags").hide();
$("#li_groups").show();

View File

@ -264,7 +264,7 @@ class HeatmapWidget extends Widget
// Filters.
$inputs[] = [
'label' => __('Groups'),
'style' => ($values['type'] === '0') ? '' : 'display:none',
'style' => ($values['type'] === '0' || $values['type'] === '3') ? '' : 'display:none',
'id' => 'li_groups',
'arguments' => [
'type' => 'select_groups',
@ -363,6 +363,7 @@ class HeatmapWidget extends Widget
break;
case 0:
case 3:
$values['groups'] = \get_parameter('groups', 0);
break;

View File

@ -255,13 +255,14 @@ div#heatmap-controls div.heatmap-refr > div {
.title-dialog {
width: 40%;
font-weight: bold;
font-weight: bold !important;
padding-left: 20px;
}
.info-dialog {
width: 60%;
font-weight: bold;
display: flex;
align-items: center;
}
.polyline {
@ -285,3 +286,39 @@ div#heatmap-controls div.heatmap-refr > div {
.big-size {
font-size: 0.4px;
}
.progress_main {
height: 2.5em;
border: 2px solid #82b92e;
position: relative;
width: 100%;
display: inline-block;
display: flex;
border-radius: 4px;
line-height: 9pt;
font-size: 9pt;
}
.progress_main_noborder {
height: 2.5em;
position: relative;
width: 100%;
display: inline-block;
display: flex;
}
.progress_main:before {
content: attr(data-label);
position: absolute;
text-align: center;
left: 0;
right: 0;
margin-top: 0.2em;
}
.progress {
width: 0%;
background: #82b92e;
height: 100%;
float: left;
}

View File

@ -331,16 +331,7 @@ if ((bool) $has_remote_conf) {
}
}
// $table_agent_count_modules .= ui_print_help_tip(__('Agent statuses are re-calculated by the server, they are not shown in real time.'), true);
/*
$table_agent = html_print_div(
[
'class' => 'agent_details_header',
'content' => $table_agent_header,
],
true
);
*/
$table_agent = $agentStatusHeader.'
<div class="agent_details_content">
<div class="agent_details_graph">
@ -352,26 +343,6 @@ $table_agent = $agentStatusHeader.'
</div>';
/*
$table_agent = '
<div class="agent_details_header">
'.$table_agent_header.'
</div>
<div class="agent_details_content">
<div class="agent_details_graph">
'.$table_agent_graph.'
<div class="agent_details_bullets">
'.$table_agent_count_modules.'
</div>
</div>
<div class="agent_details_info">
'.$alive_animation.$table_agent_os.$table_agent_ip.$table_agent_version.$table_agent_description.$remote_cfg.'
</div>
</div>';
*/
/*
* END: TABLE AGENT BUILD.
*/