pandorafms/pandora_console/include/ajax/heatmap.ajax.php

429 lines
16 KiB
PHP
Raw Normal View History

2022-02-25 09:41:32 +01:00
<?php
/**
* Heatmap.
*
* @category Heatmap
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 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
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
2023-03-24 14:11:08 +01:00
use PandoraFMS\Enterprise\Metaconsole\Node;
2022-02-25 09:41:32 +01:00
if (is_ajax() === true) {
global $config;
// Login check.
check_login();
$getFilters = (bool) get_parameter('getFilters', 0);
$getFilterType = (bool) get_parameter('getFilterType', 0);
$getInfo = (bool) get_parameter('getInfo', 0);
$type = get_parameter('type', 0);
if ($getFilters === true) {
2022-03-31 09:46:30 +02:00
$refresh = get_parameter('refresh', SECONDS_5MINUTES);
2022-02-25 09:41:32 +01:00
$search = get_parameter('search', '');
2022-03-07 13:11:54 +01:00
$group = get_parameter('group', true);
2022-02-25 09:41:32 +01:00
echo '<form id="form_dialog" method="post">';
2023-03-30 12:25:45 +02:00
echo html_print_label_input_block(
__('Refresh'),
html_print_select(
[
'30' => __('30 seconds'),
(string) SECONDS_1MINUTE => __('1 minute'),
'180' => __('3 minutes'),
(string) SECONDS_5MINUTES => __('5 minutes'),
],
'refresh',
$refresh,
'',
'',
0,
true,
false,
false,
'',
false,
'width: 100%; margin-top: 10px;'
),
2022-02-25 09:41:32 +01:00
[
2023-03-30 12:25:45 +02:00
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
]
2022-02-25 09:41:32 +01:00
);
2023-03-30 12:25:45 +02:00
echo html_print_label_input_block(
__('Search'),
html_print_input_text(
'search',
$search,
'',
30,
255,
true,
false,
false,
'',
'w100p'
),
[
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
]
);
2022-02-25 09:41:32 +01:00
2023-03-30 12:25:45 +02:00
echo html_print_label_input_block(
__('Type'),
html_print_select(
[
0 => __('Group agents'),
1 => __('Group modules by tag'),
2 => __('Group modules by module group'),
3 => __('Group modules by agents'),
],
'type',
$type,
'',
'',
0,
true,
false,
false,
'',
false,
'width: 100%; margin-top: 10px;'
),
2022-02-25 09:41:32 +01:00
[
2023-03-30 12:25:45 +02:00
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
]
2022-02-25 09:41:32 +01:00
);
2022-03-07 13:11:54 +01:00
2023-03-30 12:25:45 +02:00
echo html_print_label_input_block(
__('Show groups'),
'<div class="w100p">'.html_print_checkbox('group', 1, $group, true).'</div>',
[
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
]
);
2022-02-25 09:41:32 +01:00
echo '</form>';
}
if ($getFilterType === true) {
$filter = get_parameter('filter', 0);
2023-03-30 12:25:45 +02:00
$label = ' ';
2022-02-25 09:41:32 +01:00
switch ($type) {
case 0:
default:
2023-03-30 12:25:45 +02:00
$label = __('Group');
$input = html_print_input(
2022-02-25 09:41:32 +01:00
[
'type' => 'select_groups',
'returnAllGroup' => true,
'name' => 'filter[]',
'selected' => $filter,
'return' => true,
'required' => true,
'privilege' => 'AR',
2022-03-30 10:21:30 +02:00
'multiple' => true,
2022-02-25 09:41:32 +01:00
]
);
break;
case 1:
2023-03-30 12:25:45 +02:00
$label = __('Tag');
2022-02-25 09:41:32 +01:00
if (tags_has_user_acl_tags($config['id_user']) === false) {
2023-03-30 12:25:45 +02:00
$input = html_print_select_from_sql(
2022-02-25 09:41:32 +01:00
'SELECT id_tag, name
FROM ttag
2022-03-07 13:11:54 +01:00
WHERE id_tag
ORDER BY name',
2022-02-25 09:41:32 +01:00
'filter[]',
$filter,
'',
'',
'',
true,
true,
false,
false,
2023-03-30 12:25:45 +02:00
'width: 100%',
2022-02-25 09:41:32 +01:00
'5'
);
} else {
$user_tags = tags_get_user_tags($config['id_user'], 'AR');
if (!empty($user_tags)) {
$id_user_tags = array_keys($user_tags);
2023-03-30 12:25:45 +02:00
$input = html_print_select_from_sql(
2022-02-25 09:41:32 +01:00
'SELECT id_tag, name
FROM ttag
2022-03-07 13:11:54 +01:00
WHERE id_tag IN ('.implode(',', $id_user_tags).')
ORDER BY name',
2022-02-25 09:41:32 +01:00
'filter[]',
$filter,
'',
'',
'',
true,
true,
false,
false,
2023-03-30 12:25:45 +02:00
'width: 100%',
2022-02-25 09:41:32 +01:00
'5'
);
} else {
2023-03-30 12:25:45 +02:00
$input = html_print_select_from_sql(
2022-02-25 09:41:32 +01:00
'SELECT id_tag, name
FROM ttag
2022-03-07 13:11:54 +01:00
WHERE id_tag
ORDER BY name',
2022-02-25 09:41:32 +01:00
'filter[]',
$filter,
'',
'',
'',
true,
true,
false,
false,
2023-03-30 12:25:45 +02:00
'width: 100%',
2022-02-25 09:41:32 +01:00
'5'
);
}
}
break;
case 2:
2023-03-30 12:25:45 +02:00
$label = __('Module group');
$input = html_print_select_from_sql(
2022-03-30 10:21:30 +02:00
'SELECT id_mg, name FROM tmodule_group ORDER BY name',
2022-02-25 09:41:32 +01:00
'filter[]',
$filter,
'',
2022-03-30 10:21:30 +02:00
__('Not assigned'),
'0',
true,
true,
2022-02-25 09:41:32 +01:00
true,
false,
2023-03-30 12:25:45 +02:00
'width: 100%',
2022-03-30 10:21:30 +02:00
'5'
2022-02-25 09:41:32 +01:00
);
break;
2022-10-14 13:53:05 +02:00
case 3:
// Empty.
break;
2022-02-25 09:41:32 +01:00
}
2023-03-30 12:25:45 +02:00
echo html_print_label_input_block(
$label,
$input,
[
'label_class' => 'font-title-font',
'div_class' => 'mrgn_top_10px',
]
);
2022-02-25 09:41:32 +01:00
}
if ($getInfo === true) {
2022-03-30 10:21:30 +02:00
enterprise_include_once('include/functions_agents.php');
2022-02-25 09:41:32 +01:00
$id = get_parameter('id', 0);
2023-03-24 14:11:08 +01:00
$id_server = get_parameter('id_server', 0);
if (empty($id_server) === false) {
$nd = new Node($id_server);
$nd->connect();
}
2022-02-25 09:41:32 +01:00
switch ($type) {
2022-10-14 13:53:05 +02:00
case 3:
2022-02-25 09:41:32 +01:00
case 2:
2022-03-07 13:11:54 +01:00
$data = db_get_row('tagente_modulo', 'id_agente_modulo', $id);
2022-03-30 10:21:30 +02:00
2022-03-07 13:11:54 +01:00
// Nombre.
2022-03-30 10:21:30 +02:00
$link = sprintf(
'index.php?sec=view&sec2=operation/agentes/status_monitor%s&ag_modulename=%s',
'&refr=0&ag_group=0&module_option=1&status=-1',
$data['nombre']
);
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Module name').'</p>';
2022-03-30 10:21:30 +02:00
echo '<a href="'.$link.'" class="info-dialog">'.$data['nombre'].'</a>';
2022-03-07 13:11:54 +01:00
echo '</div>';
// Descripcion.
2022-03-30 10:21:30 +02:00
$description = (empty($data['descripcion']) === true) ? '-' : $data['descripcion'];
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Description').'</p>';
2022-03-30 10:21:30 +02:00
echo '<p class="info-dialog">'.$description.'</p>';
2022-03-07 13:11:54 +01:00
echo '</div>';
// Agent.
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Agent').'</p>';
echo '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$data['id_agente'].'"
class="info-dialog" target="_blank">'.agents_get_alias($data['id_agente']).'</a>';
echo '</div>';
// Group.
2022-03-30 10:21:30 +02:00
$group = (empty($data['id_module_group']) === true)
? '-'
: modules_get_modulegroup_name($data['id_module_group']);
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
2022-03-30 10:21:30 +02:00
echo '<p class="title-dialog">'.__('Module group').'</p>';
echo '<p class="info-dialog">'.$group.'</p>';
2022-03-07 13:11:54 +01:00
echo '</div>';
2022-02-25 09:41:32 +01:00
break;
case 1:
2022-03-07 13:11:54 +01:00
$data = db_get_row('tagente_modulo', 'id_agente_modulo', $id);
2022-03-30 10:21:30 +02:00
2022-03-07 13:11:54 +01:00
// Nombre.
2022-03-30 10:21:30 +02:00
$link = sprintf(
'index.php?sec=view&sec2=operation/agentes/status_monitor%s&ag_modulename=%s',
'&refr=0&ag_group=0&module_option=1&status=-1',
$data['nombre']
);
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Module name').'</p>';
2022-03-30 10:21:30 +02:00
echo '<a href="'.$link.'" class="info-dialog" target="_blank">'.$data['nombre'].'</a>';
2022-03-07 13:11:54 +01:00
echo '</div>';
// Descripcion.
2022-03-30 10:21:30 +02:00
$description = (empty($data['descripcion']) === true) ? '-' : $data['descripcion'];
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
2022-03-30 10:21:30 +02:00
echo '<p class="title-dialog">'.__('Description').'</p>';
echo '<p class="info-dialog">'.$description.'</p>';
2022-03-07 13:11:54 +01:00
echo '</div>';
// Agent.
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Agent').'</p>';
echo '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$data['id_agente'].'"
class="info-dialog" target="_blank">'.agents_get_alias($data['id_agente']).'</a>';
echo '</div>';
// Group.
2022-03-30 10:21:30 +02:00
$group = (empty($data['id_module_group']) === true)
? '-'
: modules_get_modulegroup_name($data['id_module_group']);
2022-03-07 13:11:54 +01:00
echo '<div class="div-dialog">';
2022-03-30 10:21:30 +02:00
echo '<p class="title-dialog">'.__('Module group').'</p>';
echo '<p class="info-dialog">'.$group.'</p>';
2022-03-07 13:11:54 +01:00
echo '</div>';
// Tag.
$tags = db_get_all_rows_sql('SELECT id_tag FROM ttag_module WHERE id_agente_modulo ='.$id);
$tags_name = '';
echo '<div class="div-dialog">';
echo '<p class="title-dialog">'.__('Tag').'</p>';
foreach ($tags as $key => $tag) {
$tags_name .= tags_get_name($tag['id_tag']).', ';
}
$tags_name = trim($tags_name, ', ');
echo '<p class="info-dialog">'.$tags_name.'</p>';
echo '</div>';
2022-02-25 09:41:32 +01:00
break;
case 0:
default:
$data = agents_get_agent($id);
// Alias.
echo '<div class="div-dialog">';
2022-03-07 13:11:54 +01:00
echo '<p class="title-dialog">'.__('Agent').'</p>';
echo '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$data['id_agente'].'"
class="info-dialog" target="_blank">'.$data['alias'].'</a>';
2022-02-25 09:41:32 +01:00
echo '</div>';
// Ip.
echo '<div class="div-dialog">';
2022-03-07 13:11:54 +01:00
echo '<p class="title-dialog">'.__('IP').'</p>';
echo '<p class="info-dialog">'.$data['direccion'].'</p>';
2022-02-25 09:41:32 +01:00
echo '</div>';
// OS.
echo '<div class="div-dialog">';
2022-03-07 13:11:54 +01:00
echo '<p class="title-dialog">'.__('OS').'</p>';
echo '<p class="info-dialog">'.ui_print_os_icon($data['id_os'], true, true).'</p>';
2022-02-25 09:41:32 +01:00
echo '</div>';
// Description.
echo '<div class="div-dialog">';
2022-03-07 13:11:54 +01:00
echo '<p class="title-dialog">'.__('Description').'</p>';
echo '<p class="info-dialog">'.$data['comentarios'].'</p>';
2022-02-25 09:41:32 +01:00
echo '</div>';
// Group.
2022-03-30 10:21:30 +02:00
$secondary_groups = '';
2023-01-23 13:58:06 +01:00
$secondary = enterprise_hook('agents_get_secondary_groups', [$data['id_agente']]);
2022-03-30 10:21:30 +02:00
if (isset($secondary['for_select']) === true && empty($secondary['for_select']) === false) {
$secondary_groups = implode(', ', $secondary['for_select']);
$secondary_groups = ', '.$secondary_groups;
}
2022-02-25 09:41:32 +01:00
echo '<div class="div-dialog">';
2022-03-07 13:11:54 +01:00
echo '<p class="title-dialog">'.__('Group').'</p>';
2022-03-30 10:21:30 +02:00
echo '<p class="info-dialog">'.groups_get_name($data['id_grupo']).$secondary_groups.'</p>';
2022-02-25 09:41:32 +01:00
echo '</div>';
2022-03-30 10:21:30 +02:00
2022-02-25 09:41:32 +01:00
// Events.
2023-01-23 13:58:06 +01:00
$result_graph_event = enterprise_hook(
'graph_graphic_agentevents',
[
$id,
100,
40,
SECONDS_1DAY,
'',
true,
false,
false,
1,
]
2022-02-25 09:41:32 +01:00
);
2023-01-23 13:58:06 +01:00
if ($result_graph_event !== -1) {
echo '<div class="div-dialog">';
echo $result_graph_event;
echo '</div>';
}
2022-02-25 09:41:32 +01:00
break;
}
2023-03-24 14:11:08 +01:00
if (empty($id_server) === false) {
$nd->disconnect();
}
2022-02-25 09:41:32 +01:00
}
return;
}