mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
#8642 Added heatmap widget 4
This commit is contained in:
parent
0e4d423825
commit
62d1249fe0
BIN
pandora_console/images/widgets/heatmap.png
Normal file
BIN
pandora_console/images/widgets/heatmap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
@ -14,7 +14,7 @@
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
|
||||
* Copyright (c) 2005-2023 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -160,27 +160,40 @@ class Heatmap
|
||||
false
|
||||
),
|
||||
'data' => [
|
||||
'page' => 'operation/heatmap',
|
||||
'method' => 'showHeatmap',
|
||||
'randomId' => $this->randomId,
|
||||
'type' => $this->type,
|
||||
'filter' => $this->filter,
|
||||
'refresh' => $this->refresh,
|
||||
'search' => $this->search,
|
||||
'group' => $this->group,
|
||||
'page' => 'operation/heatmap',
|
||||
'method' => 'showHeatmap',
|
||||
'randomId' => $this->randomId,
|
||||
'type' => $this->type,
|
||||
'filter' => $this->filter,
|
||||
'refresh' => $this->refresh,
|
||||
'search' => $this->search,
|
||||
'group' => $this->group,
|
||||
'dashboard' => (int) $this->dashboard,
|
||||
],
|
||||
];
|
||||
|
||||
echo '<div id="div_'.$this->randomId.'" class="mainDiv" style="width: 100%;height: 100%">';
|
||||
$style_dashboard = '';
|
||||
if ($this->dashboard === true) {
|
||||
$style_dashboard = 'min-height: 0px';
|
||||
}
|
||||
|
||||
echo '<div id="div_'.$this->randomId.'" class="mainDiv" style="width: 100%;height: 100%;'.$style_dashboard.'">';
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
const randomId = '<?php echo $this->randomId; ?>';
|
||||
const refresh = '<?php echo $this->refresh; ?>';
|
||||
const dashboard = '<?php echo $this->dashboard; ?>';
|
||||
|
||||
let setting = <?php echo json_encode($settings); ?>;
|
||||
setting['data']['height'] = $(`#div_${randomId}`).height() + 10;
|
||||
setting['data']['width'] = $(`#div_${randomId}`).width();
|
||||
|
||||
if (dashboard === '1') {
|
||||
setting['data']['width'] -= 10;
|
||||
setting['data']['height'] -= 10;
|
||||
}
|
||||
|
||||
var totalModules = 0;
|
||||
|
||||
// Initial charge.
|
||||
@ -209,11 +222,13 @@ class Heatmap
|
||||
let target = $(`#${randomId}_${randomPoint}`);
|
||||
setTimeout(function() {
|
||||
let class_name = target.attr('class');
|
||||
class_name = class_name.split(' ')[0];
|
||||
const newClassName = class_name.split('_')[0];
|
||||
target.removeClass(`${class_name} hover`);
|
||||
target.addClass(`${newClassName}_${solid} hover`);
|
||||
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
|
||||
if (typeof class_name !== 'undefined') {
|
||||
class_name = class_name.split(' ')[0];
|
||||
const newClassName = class_name.split('_')[0];
|
||||
target.removeClass(`${class_name} hover`);
|
||||
target.addClass(`${newClassName}_${solid} hover`);
|
||||
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
|
||||
@ -348,6 +363,8 @@ class Heatmap
|
||||
*/
|
||||
protected function getAllAgents()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$filter['disabled'] = 0;
|
||||
|
||||
$alias = '';
|
||||
@ -355,6 +372,14 @@ class Heatmap
|
||||
$alias = ' AND alias LIKE "%'.$this->search.'%"';
|
||||
}
|
||||
|
||||
$id_user_groups = '';
|
||||
if (users_is_admin() === false) {
|
||||
$user_groups = array_keys(users_get_groups($config['user'], 'AR', false));
|
||||
if (empty($user_groups) === false) {
|
||||
$id_user_groups = ' AND id_grupo IN ('.implode(',', $user_groups).')';
|
||||
}
|
||||
}
|
||||
|
||||
$id_grupo = '';
|
||||
if (empty($this->filter) === false && current($this->filter) != 0) {
|
||||
$id_grupo = ' AND id_grupo IN ('.implode(',', $this->filter).')';
|
||||
@ -366,8 +391,9 @@ class Heatmap
|
||||
unknown_count,notinit_count,total_count,fired_count,
|
||||
(SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente
|
||||
ORDER BY last_status_change DESC LIMIT 1) AS last_status_change
|
||||
FROM tagente WHERE `disabled` = 0 %s %s ORDER BY id_grupo,id_agente ASC',
|
||||
FROM tagente WHERE `disabled` = 0 %s %s %s ORDER BY id_grupo,id_agente ASC',
|
||||
$alias,
|
||||
$id_user_groups,
|
||||
$id_grupo
|
||||
);
|
||||
|
||||
@ -429,6 +455,8 @@ class Heatmap
|
||||
*/
|
||||
protected function getAllModulesByGroup()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$filter_group = '';
|
||||
if (empty($this->filter) === false && current($this->filter) != -1) {
|
||||
$filter_group = 'AND am.id_module_group IN ('.implode(',', $this->filter).')';
|
||||
@ -439,12 +467,26 @@ class Heatmap
|
||||
$filter_name = 'AND nombre LIKE "%'.$this->search.'%"';
|
||||
}
|
||||
|
||||
$id_user_groups = '';
|
||||
if (users_is_admin() === false) {
|
||||
$user_groups = array_keys(users_get_groups($config['user'], 'AR', false));
|
||||
if (empty($user_groups) === 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// All modules.
|
||||
$sql = sprintf(
|
||||
'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_module_group AS id_grupo,
|
||||
ae.last_status_change FROM tagente_modulo am
|
||||
INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo
|
||||
%s
|
||||
WHERE am.disabled = 0 %s %s GROUP BY am.id_module_group, am.id_agente_modulo',
|
||||
$id_user_groups,
|
||||
$filter_group,
|
||||
$filter_name
|
||||
);
|
||||
@ -527,6 +569,8 @@ class Heatmap
|
||||
*/
|
||||
protected function getAllModulesByTag()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$filter_tag = '';
|
||||
if (empty($this->filter) === false && $this->filter[0] !== '0') {
|
||||
$tags = implode(',', $this->filter);
|
||||
@ -538,12 +582,26 @@ class Heatmap
|
||||
$filter_name = 'AND nombre LIKE "%'.$this->search.'%"';
|
||||
}
|
||||
|
||||
$id_user_groups = '';
|
||||
if (users_is_admin() === false) {
|
||||
$user_groups = array_keys(users_get_groups($config['user'], 'AR', false));
|
||||
if (empty($user_groups) === 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// All modules.
|
||||
$sql = sprintf(
|
||||
'SELECT ae.id_agente_modulo AS id, ae.estado AS `status`, tm.id_tag AS id_grupo,
|
||||
ae.last_status_change FROM tagente_estado ae
|
||||
%s
|
||||
INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo
|
||||
WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo',
|
||||
$id_user_groups,
|
||||
$filter_tag,
|
||||
$filter_name
|
||||
);
|
||||
@ -626,17 +684,33 @@ class Heatmap
|
||||
*/
|
||||
protected function getAllModulesByAgents()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$filter_name = '';
|
||||
if (empty($this->search) === false) {
|
||||
$filter_name = 'AND nombre LIKE "%'.$this->search.'%"';
|
||||
}
|
||||
|
||||
$id_user_groups = '';
|
||||
if (users_is_admin() === false) {
|
||||
$user_groups = array_keys(users_get_groups($config['user'], 'AR', false));
|
||||
if (empty($user_groups) === 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// All modules.
|
||||
$sql = sprintf(
|
||||
'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_agente AS id_grupo,
|
||||
ae.last_status_change FROM tagente_modulo am
|
||||
INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo
|
||||
%s
|
||||
WHERE am.disabled = 0 %s GROUP BY ae.id_agente_modulo ORDER BY id_grupo',
|
||||
$id_user_groups,
|
||||
$filter_name
|
||||
);
|
||||
|
||||
@ -912,7 +986,7 @@ class Heatmap
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
if (count($groups) > 1 && $this->group === 1) {
|
||||
if (count($groups) > 1 && $this->group === 1 && $this->dashboard === false) {
|
||||
$x_back = 0;
|
||||
$y_back = 0;
|
||||
|
||||
@ -1111,7 +1185,7 @@ class Heatmap
|
||||
echo '</svg>';
|
||||
|
||||
// Dialog.
|
||||
echo '<div id="info_dialog" style="padding:15px" class="invisible"></div>';
|
||||
echo '<div id="info_dialog"></div>';
|
||||
}
|
||||
|
||||
|
||||
|
@ -1560,3 +1560,36 @@ function showManualThresholds(element) {
|
||||
$(".dashboard-input-threshold-critical").addClass("invisible_important");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
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();
|
||||
$("#li_module_groups").hide();
|
||||
break;
|
||||
|
||||
default:
|
||||
case "0":
|
||||
$("#li_tags").hide();
|
||||
$("#li_groups").show();
|
||||
$("#li_module_groups").hide();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -192,6 +192,26 @@ class HeatmapWidget extends Widget
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::decoders($decoder);
|
||||
|
||||
if (isset($decoder['search']) === true) {
|
||||
$values['search'] = $decoder['search'];
|
||||
}
|
||||
|
||||
if (isset($decoder['type']) === true) {
|
||||
$values['type'] = $decoder['type'];
|
||||
}
|
||||
|
||||
if (isset($decoder['groups']) === true) {
|
||||
$values['groups'] = $decoder['groups'];
|
||||
}
|
||||
|
||||
if (isset($decoder['tags']) === true) {
|
||||
$values['tags'] = $decoder['tags'];
|
||||
}
|
||||
|
||||
if (isset($decoder['module_groups']) === true) {
|
||||
$values['module_groups'] = $decoder['module_groups'];
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
@ -205,9 +225,117 @@ class HeatmapWidget extends Widget
|
||||
*/
|
||||
public function getFormInputs(): array
|
||||
{
|
||||
global $config;
|
||||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
$values = $this->values;
|
||||
|
||||
// Search.
|
||||
$inputs[] = [
|
||||
'label' => \__('Search'),
|
||||
'arguments' => [
|
||||
'name' => 'search',
|
||||
'type' => 'text',
|
||||
'class' => 'event-widget-input',
|
||||
'value' => $values['search'],
|
||||
'return' => true,
|
||||
'size' => 30,
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Type'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => [
|
||||
0 => __('Group agents'),
|
||||
1 => __('Group modules by tag'),
|
||||
2 => __('Group modules by module group'),
|
||||
3 => __('Group modules by agents'),
|
||||
],
|
||||
'name' => 'type',
|
||||
'selected' => $values['type'],
|
||||
'script' => 'type_change()',
|
||||
'return' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Filters.
|
||||
$inputs[] = [
|
||||
'label' => __('Groups'),
|
||||
'style' => ($values['type'] === '0') ? '' : 'display:none',
|
||||
'id' => 'li_groups',
|
||||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groups[]',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => explode(',', $values['groups'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
if (tags_has_user_acl_tags($config['id_user']) === false) {
|
||||
$tags = db_get_all_rows_sql(
|
||||
'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name'
|
||||
);
|
||||
} else {
|
||||
$user_tags = tags_get_user_tags($config['id_user'], 'AR');
|
||||
if (empty($user_tags) === false) {
|
||||
$id_user_tags = array_keys($user_tags);
|
||||
$tags = db_get_all_rows_sql(
|
||||
'SELECT id_tag, name FROM ttag
|
||||
WHERE id_tag IN ('.implode(',', $id_user_tags).')
|
||||
ORDER BY name'
|
||||
);
|
||||
} else {
|
||||
$tags = db_get_all_rows_sql(
|
||||
'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Tag'),
|
||||
'style' => ($values['type'] === '1') ? '' : 'display:none',
|
||||
'id' => 'li_tags',
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $tags,
|
||||
'name' => 'tags[]',
|
||||
'selected' => explode(',', $values['tags'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$module_groups_aux = db_get_all_rows_sql(
|
||||
'SELECT id_mg, name FROM tmodule_group ORDER BY name'
|
||||
);
|
||||
|
||||
$module_groups = [];
|
||||
foreach ($module_groups_aux as $key => $module_group) {
|
||||
$module_groups[$module_group['id_mg']] = $module_group['name'];
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'label' => __('Module group'),
|
||||
'style' => ($values['type'] === '2') ? '' : 'display:none',
|
||||
'id' => 'li_module_groups',
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $module_groups,
|
||||
'name' => 'module_groups[]',
|
||||
'selected' => explode(',', $values['module_groups'][0]),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
'nothing' => __('Not assigned'),
|
||||
'nothing_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
@ -222,6 +350,27 @@ class HeatmapWidget extends Widget
|
||||
// Retrieve global - common inputs.
|
||||
$values = parent::getPost();
|
||||
|
||||
$values['search'] = \get_parameter('search', '');
|
||||
$values['type'] = \get_parameter('type', 0);
|
||||
|
||||
switch ((int) $values['type']) {
|
||||
case 2:
|
||||
$values['module_groups'] = \get_parameter('module_groups', 0);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$values['tags'] = \get_parameter('tags', 0);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
$values['groups'] = \get_parameter('groups', 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Do nothing.
|
||||
break;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
@ -256,8 +405,8 @@ class HeatmapWidget extends Widget
|
||||
public function getSizeModalConfiguration(): array
|
||||
{
|
||||
$size = [
|
||||
'width' => 400,
|
||||
'height' => 205,
|
||||
'width' => 500,
|
||||
'height' => 300,
|
||||
];
|
||||
|
||||
return $size;
|
||||
@ -276,10 +425,23 @@ class HeatmapWidget extends Widget
|
||||
\ui_require_css_file('heatmap', 'include/styles/', true);
|
||||
|
||||
$values = $this->values;
|
||||
hd($values, true);
|
||||
$search = (empty($values['search']) === false) ? $values['search'] : '';
|
||||
$type = (empty($values['type']) === false) ? $values['type'] : 0;
|
||||
$filter = [];
|
||||
if (isset($values['groups'])) {
|
||||
$filter = explode(',', $values['groups'][0]);
|
||||
}
|
||||
|
||||
if (isset($values['tags'])) {
|
||||
$filter = explode(',', $values['tags'][0]);
|
||||
}
|
||||
|
||||
if (isset($values['module_groups'])) {
|
||||
$filter = explode(',', $values['module_groups'][0]);
|
||||
}
|
||||
|
||||
// Control call flow.
|
||||
$heatmap = new Heatmap(0, [], null, 300, 400, 200, 0, 1);
|
||||
$heatmap = new Heatmap($type, $filter, null, 300, 400, 200, $search, 0, true);
|
||||
// AJAX controller.
|
||||
if (is_ajax() === true) {
|
||||
$method = get_parameter('method');
|
||||
|
@ -62,6 +62,8 @@ if ($group_sent === true) {
|
||||
$group = (int) get_parameter('group', true);
|
||||
}
|
||||
|
||||
$dashboard = (bool) get_parameter('dashboard', false);
|
||||
|
||||
$is_ajax = is_ajax();
|
||||
if ($is_ajax === false && $pure === false) {
|
||||
$viewtab['config'] = '<a id="config" href="">'.html_print_image(
|
||||
@ -192,6 +194,7 @@ if ($is_ajax === false && $pure === true) {
|
||||
html_print_input_hidden('type', $type);
|
||||
html_print_input_hidden('search', $search);
|
||||
html_print_input_hidden('filter', implode(',', $filter));
|
||||
html_print_input_hidden('dashboard', $dashboard);
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
@ -230,7 +233,7 @@ if ($is_ajax === false && $pure === true) {
|
||||
// Control call flow.
|
||||
try {
|
||||
// Heatmap construct.
|
||||
$heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group);
|
||||
$heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group, $dashboard);
|
||||
} catch (Exception $e) {
|
||||
if (is_ajax() === true) {
|
||||
echo json_encode(['error' => '[Heatmap]'.$e->getMessage() ]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user