Fix loading charts modules and interfaces

This commit is contained in:
Daniel Barbero Martin 2020-12-09 14:05:40 +01:00
parent 4b51e26086
commit aa52ab01df
9 changed files with 341 additions and 125 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -38,23 +38,36 @@ if (check_login()) {
$get_plugin_macros = get_parameter('get_plugin_macros');
$search_modules = get_parameter('search_modules');
$get_module_detail = get_parameter('get_module_detail', 0);
$get_module_autocomplete_input = (bool) get_parameter('get_module_autocomplete_input');
$get_module_autocomplete_input = (bool) get_parameter(
'get_module_autocomplete_input'
);
$add_module_relation = (bool) get_parameter('add_module_relation');
$remove_module_relation = (bool) get_parameter('remove_module_relation');
$change_module_relation_updates = (bool) get_parameter('change_module_relation_updates');
$change_module_relation_updates = (bool) get_parameter(
'change_module_relation_updates'
);
$get_id_tag = (bool) get_parameter('get_id_tag', 0);
$get_type = (bool) get_parameter('get_type', 0);
$list_modules = (bool) get_parameter('list_modules', 0);
$get_agent_modules_json_by_name = (bool) get_parameter('get_agent_modules_json_by_name', 0);
$get_agent_modules_json_by_name = (bool) get_parameter(
'get_agent_modules_json_by_name',
0
);
$get_graph_module = (bool) get_parameter('get_graph_module', 0);
$get_graph_module_interfaces = (bool) get_parameter(
'get_graph_module_interfaces',
0
);
if ($get_agent_modules_json_by_name) {
if ($get_agent_modules_json_by_name === true) {
$agent_name = get_parameter('agent_name');
$agent_id = agents_get_agent_id($agent_name);
$agent_modules = db_get_all_rows_sql(
'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo
WHERE id_agente = '.$agent_id
'SELECT id_agente_modulo as id_module,
nombre as name FROM tagente_modulo
WHERE id_agente = '.$agent_id
);
echo json_encode($agent_modules);
@ -91,7 +104,10 @@ if (check_login()) {
$id_agents = json_decode(io_safe_output(get_parameter('id_agents')));
$filter = '%'.get_parameter('q', '').'%';
$other_filter = json_decode(io_safe_output(get_parameter('other_filter')), true);
$other_filter = json_decode(
io_safe_output(get_parameter('other_filter')),
true
);
// TODO TAGS agents_get_modules.
$modules = agents_get_modules(
$id_agents,
@ -112,9 +128,13 @@ if (check_login()) {
}
if ($get_module_detail) {
// This script is included manually to be included after jquery and avoid error.
// This script is included manually to be
// included after jquery and avoid error.
ui_include_time_picker();
ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/');
ui_require_jquery_file(
'ui.datepicker-'.get_user_language(),
'include/javascript/i18n/'
);
$module_id = (int) get_parameter('id_module');
$period = get_parameter('period', SECONDS_1DAY);
@ -145,10 +165,22 @@ if (check_login()) {
$free_checkbox = (bool) get_parameter('free_checkbox', false);
$selection_mode = get_parameter('selection_mode', 'fromnow');
$utimestamp = get_system_time();
$date_from = (string) get_parameter('date_from', date(DATE_FORMAT, ($utimestamp - SECONDS_1DAY)));
$time_from = (string) get_parameter('time_from', date(TIME_FORMAT, ($utimestamp - SECONDS_1DAY)));
$date_to = (string) get_parameter('date_to', date(DATE_FORMAT, $utimestamp));
$time_to = (string) get_parameter('time_to', date(TIME_FORMAT, $utimestamp));
$date_from = (string) get_parameter(
'date_from',
date(DATE_FORMAT, ($utimestamp - SECONDS_1DAY))
);
$time_from = (string) get_parameter(
'time_from',
date(TIME_FORMAT, ($utimestamp - SECONDS_1DAY))
);
$date_to = (string) get_parameter(
'date_to',
date(DATE_FORMAT, $utimestamp)
);
$time_to = (string) get_parameter(
'time_to',
date(TIME_FORMAT, $utimestamp)
);
// Definition of new table.
$formtable = new stdClass();
@ -189,7 +221,17 @@ if (check_login()) {
'style="margin-right: 15px;"',
true
).__('Choose a time from now');
$formtable->data[0][1] = html_print_select($periods, 'period', $period, '', '', 0, true, false, false);
$formtable->data[0][1] = html_print_select(
$periods,
'period',
$period,
'',
'',
0,
true,
false,
false
);
$formtable->data[0][2] = '';
$formtable->data[0][3] = "<a href='javascript: show_module_detail_dialog(".$module_id.', '.$agentId.', "'.$server_name.'", 0, -1,"'.modules_get_agentmodule_name($module_id)."\")'>".html_print_image('images/refresh.png', true, ['style' => 'vertical-align: middle;', 'border' => '0' ]).'</a>';
$formtable->rowspan[0][3] = 2;
@ -248,8 +290,20 @@ if (check_login()) {
$freesearch_object = '';
if (preg_match('/_string/', $moduletype_name)) {
$formtable->data[2][0] = __('Free search').' ';
$formtable->data[2][1] = html_print_input_text('freesearch', $freesearch, '', 20, null, true);
$formtable->data[2][2] = html_print_checkbox('free_checkbox', 1, $free_checkbox, true);
$formtable->data[2][1] = html_print_input_text(
'freesearch',
$freesearch,
'',
20,
null,
true
);
$formtable->data[2][2] = html_print_checkbox(
'free_checkbox',
1,
$free_checkbox,
true
);
$formtable->data[2][2] .= ' '.__('Exact phrase');
$freesearch_object = json_encode(
[
@ -359,8 +413,16 @@ if (check_login()) {
'web_content_string'
);
$post_process = db_get_value_filter('post_process', 'tagente_modulo', ['id_agente_modulo' => $module_id]);
$unit = db_get_value_filter('unit', 'tagente_modulo', ['id_agente_modulo' => $module_id]);
$post_process = db_get_value_filter(
'post_process',
'tagente_modulo',
['id_agente_modulo' => $module_id]
);
$unit = db_get_value_filter(
'unit',
'tagente_modulo',
['id_agente_modulo' => $module_id]
);
foreach ($result as $row) {
$data = [];
@ -400,32 +462,65 @@ if (check_login()) {
// Fixed the data from Selenium Plugin.
if ($row[$attr[0]] != strip_tags($row[$attr[0]])) {
$data[] = html_print_result_div($row[$attr[0]]);
} else if (is_numeric($row[$attr[0]]) && !modules_is_string_type($row['module_type'])) {
} else if (is_numeric($row[$attr[0]])
&& !modules_is_string_type($row['module_type'])
) {
switch ($row['module_type']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module_id);
$value = db_get_value(
'snmp_oid',
'tagente_modulo',
'id_agente_modulo',
$module_id
);
// System Uptime:
// In case of System Uptime module, shows data in format "Days hours minutes seconds" if and only if
// In case of System Uptime module,
// shows data in format
// "Days hours minutes seconds" if and only if
// selected module unit is "_timeticks_"
// Take notice that selected unit may not be postrocess unit
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0') {
$data_macro = modules_get_unit_macro($row[$attr[0]], $unit);
// Take notice that selected unit
// may not be postrocess unit.
if ($value == '.1.3.6.1.2.1.1.3.0'
|| $value == '.1.3.6.1.2.1.25.1.1.0'
) {
$data_macro = modules_get_unit_macro(
$row[$attr[0]],
$unit
);
if ($data_macro) {
$data[] = $data_macro;
} else {
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
$data[] = remove_right_zeros(
number_format(
$row[$attr[0]],
$config['graph_precision']
)
);
}
} else {
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
$data[] = remove_right_zeros(
number_format(
$row[$attr[0]],
$config['graph_precision']
)
);
}
break;
default:
$data_macro = modules_get_unit_macro($row[$attr[0]], $unit);
$data_macro = modules_get_unit_macro(
$row[$attr[0]],
$unit
);
if ($data_macro) {
$data[] = $data_macro;
} else {
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
$data[] = remove_right_zeros(
number_format(
$row[$attr[0]],
$config['graph_precision']
)
);
}
break;
}
@ -433,11 +528,16 @@ if (check_login()) {
if ($row[$attr[0]] == '') {
$data[] = 'No data';
} else {
$data_macro = modules_get_unit_macro($row[$attr[0]], $unit);
$data_macro = modules_get_unit_macro(
$row[$attr[0]],
$unit
);
if ($data_macro) {
$data[] = $data_macro;
} else {
$data[] = html_print_result_div($row[$attr[0]]);
$data[] = html_print_result_div(
$row[$attr[0]]
);
}
}
}
@ -453,7 +553,16 @@ if (check_login()) {
if (empty($table->data)) {
ui_print_error_message(__('No available data to show'));
} else {
ui_pagination(count($count), false, $offset, 0, false, 'offset', true, 'binary_dialog');
ui_pagination(
count($count),
false,
$offset,
0,
false,
'offset',
true,
'binary_dialog'
);
html_print_table($table);
}
@ -727,11 +836,17 @@ if (check_login()) {
}
}
$status_filter_monitor = (int) get_parameter('status_filter_monitor', -1);
$status_filter_monitor = (int) get_parameter(
'status_filter_monitor',
-1
);
$status_text_monitor = get_parameter('status_text_monitor', '');
$filter_monitors = (bool) get_parameter('filter_monitors', false);
$status_module_group = get_parameter('status_module_group', -1);
$monitors_change_filter = (bool) get_parameter('monitors_change_filter', false);
$monitors_change_filter = (bool) get_parameter(
'monitors_change_filter',
false
);
$status_filter_sql = '1 = 1';
if ($status_filter_monitor == AGENT_MODULE_STATUS_NOT_NORMAL) {
@ -787,7 +902,9 @@ if (check_login()) {
AND tagente_estado.estado != $monitor_filter
";
$count_modules = db_get_all_rows_sql('SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)'.$sql_condition);
$count_modules = db_get_all_rows_sql(
'SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)'.$sql_condition
);
if (isset($count_modules[0])) {
$count_modules = reset($count_modules[0]);
@ -796,7 +913,7 @@ if (check_login()) {
}
// Get monitors/modules
// Get all module from agent
// Get all module from agent.
$sql_modules_info = "SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.*
$sql_condition
GROUP BY tagente_modulo.id_agente_modulo ORDER BY $order_sql";
@ -1195,4 +1312,55 @@ if (check_login()) {
echo $graph_type;
return;
}
if ($get_graph_module === true) {
global $config;
$output = '';
$graph_data = get_parameter('graph_data', '');
$params = json_decode(base64_decode($graph_data), true);
$server_id = (int) get_parameter('server_id', 0);
include_once $config['homedir'].'/include/functions_graph.php';
// Metaconsole connection to the node.
if (is_metaconsole() === true && empty($server_id) === false) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
}
$output .= grafico_modulo_sparse($params);
echo $output;
if (is_metaconsole() === true && empty($server_id) === false) {
metaconsole_restore_db();
}
return;
}
if ($get_graph_module_interfaces === true) {
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
$output = '';
$graph_data = get_parameter('graph_data', '');
$params = json_decode(base64_decode($graph_data), true);
$modules = get_parameter('modules', '');
$modules = json_decode(base64_decode($modules), true);
$graph_data_combined = get_parameter('graph_data_combined', '');
$params_combined = json_decode(
base64_decode($graph_data_combined),
true
);
$output .= graphic_combined_module(
$modules,
$params,
$params_combined
);
echo $output;
return;
}
}

View File

@ -955,7 +955,6 @@ function pandoraFlotArea(
legend,
series_type,
color,
water_mark,
date_array,
data_module_graph,
params,
@ -972,7 +971,6 @@ function pandoraFlotArea(
.shift();
var width = params.width;
var vconsole = params.vconsole;
var dashboard = params.dashboard;
var menu = params.menu;
var min_x = date_array["start_date"] * 1000;
var max_x = date_array["final_date"] * 1000;
@ -2794,17 +2792,6 @@ function pandoraFlotArea(
);
adjust_menu(graph_id, plot, parent_height, width, show_legend);
}
if (!dashboard) {
if (water_mark) {
set_watermark(
graph_id,
plot,
$("#watermark_image_" + graph_id).attr("src")
);
}
//adjust_menu(graph_id, plot, parent_height, width, show_legend);
}
}
function format_unit_yaxes(y) {

View File

@ -262,15 +262,17 @@ function flot_area_graph(
$params['height'] = 1;
}
if (!$vconsole) {
$return .= "<div id='overview_$graph_id' class='overview_graph'
style='margin:0px; margin-top:30px; margin-bottom:50px; width: ".$params['width']."px; height: 200px;'></div>";
if ((bool) $params['vconsole'] === false) {
$return .= '<div id="overview_'.$graph_id.'" class="overview_graph" style="margin:0px; margin-top:30px; margin-bottom:50px; width:'.$params['width'].'px; height: 200px;"></div>';
$legend_top = 10;
if (empty($params['show_legend']) === false) {
$legend_top = (20 + (count($legend) * 18));
}
if ($water_mark != '') {
$return .= "<div id='watermark_$graph_id' style='display:none; position:absolute;'><img id='watermark_image_$graph_id' src='".$water_mark['url']."'></div>";
$watermark = 'true';
} else {
$watermark = 'false';
if ($water_mark != '' && (bool) $params['dashboard'] === false) {
$return .= '<div id="watermark_'.$graph_id.'" style="position:absolute; top: '.$legend_top.'px; left: calc(100% - 100px);">';
$return .= '<img id="watermark_image_'.$graph_id.'" src="'.$water_mark['url'].'">';
$return .= '</div>';
}
}
@ -314,7 +316,6 @@ function flot_area_graph(
$return .= $legend.", \n";
$return .= $series_type.", \n";
$return .= $color.", \n";
$return .= $watermark.", \n";
$return .= $date_array.", \n";
$return .= $data_module_graph.", \n";
$return .= $params.", \n";

View File

@ -351,11 +351,10 @@ class CustomGraphWidget extends Widget
);
$hackLegendHight = (30 * count($sources));
if ($hackLegendHight < ($size['height'] - 10 - $hackLegendHight)) {
$height = ($size['height'] - 10 - $hackLegendHight);
if ($hackLegendHight > ($size['height'] - 10 - $hackLegendHight)) {
$height = ($size['height'] - $hackLegendHight);
} else {
$height = ($size['height'] - 10);
$this->values['showLegend'] = 0;
}
} else {
$height = ($size['height'] - 10);
@ -392,6 +391,7 @@ class CustomGraphWidget extends Widget
'menu' => false,
'show_legend' => $this->values['showLegend'],
'vconsole' => true,
'dashboard' => true,
];
$params_combined = [

View File

@ -373,6 +373,7 @@ class SingleGraphWidget extends Widget
'show_legend' => $this->values['showLegend'],
'show_title' => $module_name,
'menu' => false,
'dashboard' => true,
];
$output = '<div class="container-center">';

View File

@ -6087,3 +6087,17 @@ div.graph div.legend table {
writing-mode: lr-tb;
white-space: nowrap;
}
div.stat-win-spinner {
width: 100%;
height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
div.stat-win-spinner img {
width: 100px;
height: 100px;
}

View File

@ -31,8 +31,6 @@ require_once $config['homedir'].'/include/auth/mysql.php';
require_once $config['homedir'].'/include/functions.php';
require_once $config['homedir'].'/include/functions_db.php';
require_once $config['homedir'].'/include/functions_reporting.php';
require_once $config['homedir'].'/include/functions_graph.php';
require_once $config['homedir'].'/include/functions_custom_graphs.php';
require_once $config['homedir'].'/include/functions_modules.php';
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_tags.php';
@ -45,7 +43,7 @@ $params = json_decode($params_json, true);
// Metaconsole connection to the node.
$server_id = (int) (isset($params['server']) ? $params['server'] : 0);
if ($config['metaconsole'] && empty($server_id) === false) {
if (is_metaconsole() === true && empty($server_id) === false) {
$server = metaconsole_get_connection_by_id($server_id);
// Error connecting.
@ -268,13 +266,15 @@ $table->data[] = $data;
$table->rowclass[] = '';
$form_table = html_print_table($table, true);
$form_table .= '<div style="width:100%; text-align:right;">'.html_print_submit_button(
$form_table .= '<div style="width:100%; text-align:right;">';
$form_table .= html_print_submit_button(
__('Reload'),
'submit',
false,
'class="sub upd"',
true
).'</div>';
);
$form_table .= '</div>';
// Menu.
@ -303,7 +303,7 @@ html_print_div(
);
// Graph.
echo '<div id="stat-win-interface-graph">';
$output = '<div id="stat-win-interface-graph">';
$height = 280;
$width = '90%';
@ -320,8 +320,8 @@ $params = [
'zoom' => $zoom,
];
if (is_metaconsole()) {
$params['id_server'] = $server_id;
if (is_metaconsole() === true) {
$params['server_id'] = $server_id;
}
if ($config['type_interface_charts'] == 'line') {
@ -340,13 +340,13 @@ $params_combined = [
'stacked' => $stacked,
];
graphic_combined_module(
array_values($interface_traffic_modules),
$params,
$params_combined
);
$modules = array_values($interface_traffic_modules);
$output .= '<div id="stat-win-spinner" class="stat-win-spinner">';
$output .= html_print_image('images/spinner_charts.gif', true);
$output .= '</div>';
echo '</div>';
$output .= '</div>';
echo $output;
?>
</body>
@ -362,6 +362,10 @@ ui_require_jquery_file(
true
);
ui_include_time_picker(true);
if (is_metaconsole() === true && empty($server_id) === false) {
metaconsole_restore_db();
}
?>
<script>
var show_overview = false;
@ -370,6 +374,19 @@ ui_include_time_picker(true);
$(document).ready(function() {
height_window = $(window).height();
width_window = $(window).width();
var graph_data = "<?php echo base64_encode(json_encode($params)); ?>";
var modules = "<?php echo base64_encode(json_encode($modules)); ?>";
var graph_data_combined = "<?php echo base64_encode(json_encode($params_combined)); ?>";
var url = "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>";
var serverId = "<?php echo $server_id; ?>";
get_ajax_modules_interfaces(
url,
graph_data,
serverId,
graph_data_combined,
modules
);
});
$("*").filter(function() {
@ -423,4 +440,26 @@ ui_include_time_picker(true);
}
});
function get_ajax_modules_interfaces(url, graph_data, serverId, graph_data_combined, modules) {
$.ajax({
type: "POST",
url: url,
dataType: "html",
data: {
page: "include/ajax/module",
get_graph_module_interfaces: true,
graph_data: graph_data,
server_id: serverId,
graph_data_combined: graph_data_combined,
modules: modules
},
success: function (data) {
$("#stat-win-spinner").hide();
$("#stat-win-interface-graph").append(data);
},
error: function (error) {
console.error(error);
}
});
}
</script>

View File

@ -31,7 +31,6 @@ require_once $config['homedir'].'/include/auth/mysql.php';
require_once $config['homedir'].'/include/functions.php';
require_once $config['homedir'].'/include/functions_db.php';
require_once $config['homedir'].'/include/functions_reporting.php';
require_once $config['homedir'].'/include/functions_graph.php';
require_once $config['homedir'].'/include/functions_modules.php';
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_tags.php';
@ -41,7 +40,7 @@ enterprise_include_once('include/functions_agents.php');
check_login();
// Metaconsole connection to the node.
$server_id = (int) get_parameter('server');
$server_id = (int) get_parameter('server', 0);
if (is_metaconsole() === true && empty($server_id) === false) {
$server = metaconsole_get_connection_by_id($server_id);
// Error connecting.
@ -445,59 +444,39 @@ ui_print_message_dialog(
]
);
$params = [
'agent_module_id' => $id,
'period' => $period,
'show_events' => $draw_events,
'title' => $label,
'unit_name' => $unit,
'show_alerts' => $draw_alerts,
'date' => $date,
'unit' => $unit,
'baseline' => $baseline,
'homeurl' => $urlImage,
'adapt_key' => 'adapter_'.$graph_type,
'compare' => $time_compare,
'show_unknown' => $unknown_graph,
'percentil' => (($show_percentil) ? $config['percentil'] : null),
'type_graph' => $config['type_module_charts'],
'fullscale' => $fullscale,
'zoom' => $zoom,
'height' => 300,
'type_mode_graph' => $type_mode_graph,
];
// Graph.
$output = '<div id="stat-win-module-graph">';
switch ($graph_type) {
case 'boolean':
case 'sparse':
case 'string':
$params = [
'agent_module_id' => $id,
'period' => $period,
'show_events' => $draw_events,
'title' => $label,
'unit_name' => $unit,
'show_alerts' => $draw_alerts,
'date' => $date,
'unit' => $unit,
'baseline' => $baseline,
'homeurl' => $urlImage,
'adapt_key' => 'adapter_'.$graph_type,
'compare' => $time_compare,
'show_unknown' => $unknown_graph,
'percentil' => (($show_percentil) ? $config['percentil'] : null),
'type_graph' => $config['type_module_charts'],
'fullscale' => $fullscale,
'zoom' => $zoom,
'height' => 300,
'type_mode_graph' => $type_mode_graph,
];
$output .= grafico_modulo_sparse($params);
$output .= '<br>';
if ($show_events_graph) {
$width = '500';
$height = '450';
$output .= graphic_module_events(
$id,
$width,
$height,
$period,
$config['homeurl'],
$zoom,
'adapted_'.$graph_type,
$date,
true
);
}
break;
default:
$output .= fs_error_image('../images');
break;
}
$output .= '<div id="stat-win-spinner" class="stat-win-spinner">';
$output .= html_print_image('images/spinner_charts.gif', true);
$output .= '</div>';
$output .= '</div>';
echo $output;
if (is_metaconsole() === true && empty($server_id) === false) {
metaconsole_restore_db();
}
?>
</body>
@ -580,5 +559,32 @@ ui_include_time_picker(true);
arrow.attr('src',arrow.attr('src').replace(arrow_up, arrow_down));
}
});
var graph_data = "<?php echo base64_encode(json_encode($params)); ?>";
var url = "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>";
var serverId = "<?php echo $server_id; ?>";
get_ajax_module(url, graph_data, serverId);
});
function get_ajax_module(url, graph_data, serverId) {
$.ajax({
type: "POST",
url: url,
dataType: "html",
data: {
page: "include/ajax/module",
get_graph_module: true,
graph_data: graph_data,
server_id: serverId
},
success: function (data) {
$("#stat-win-spinner").hide();
$("#stat-win-module-graph").append(data);
},
error: function (error) {
console.error(error);
}
});
}
</script>