add new chart histogram

This commit is contained in:
Daniel Barbero Martin 2022-01-18 13:01:49 +01:00
parent 4f46da6633
commit a0a74cf7bb
3 changed files with 98 additions and 11 deletions

View File

@ -669,15 +669,20 @@ class Tree
// HTML of the server type image // HTML of the server type image
$module['serverTypeHTML'] = servers_show_type($module['server_type']); $module['serverTypeHTML'] = servers_show_type($module['server_type']);
// Link to the Module graph // Link to the Module graph.
// ACL // ACL.
$acl_graphs = false; $acl_graphs = false;
$module['showGraphs'] = 0; $module['showGraphs'] = 0;
// Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions // Avoid the check on the metaconsole.
if (!empty($group_id) && !is_metaconsole()) { // Too slow to show/hide an icon depending on the permissions.
$acl_graphs = check_acl_one_of_groups($config['id_user'], $all_groups, 'RR'); if (empty($group_id) === false && is_metaconsole() === false) {
} else if (!empty($all_groups)) { $acl_graphs = check_acl_one_of_groups(
$config['id_user'],
$all_groups,
'RR'
);
} else if (empty($all_groups) === false) {
$acl_graphs = true; $acl_graphs = true;
} }
@ -686,8 +691,24 @@ class Tree
} }
if ($module['showGraphs']) { if ($module['showGraphs']) {
$tresholds = true;
if (empty((float) $module['min_warning']) === true
&& empty((float) $module['max_warning']) === true
&& empty($module['warning_inverse']) === true
&& empty((float) $module['min_critical']) === true
&& empty((float) $module['max_critical']) === true
&& empty($module['critical_inverse']) === true
) {
$tresholds = false;
}
$graphType = return_graphtype($module['id_module_type']); $graphType = return_graphtype($module['id_module_type']);
$url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); $url = ui_get_full_url(
'operation/agentes/stat_win.php',
false,
false,
false
);
$winHandle = dechex(crc32($module['id'].$module['name'])); $winHandle = dechex(crc32($module['id'].$module['name']));
$graph_params = [ $graph_params = [
@ -697,20 +718,20 @@ class Tree
'refresh' => SECONDS_10MINUTES, 'refresh' => SECONDS_10MINUTES,
]; ];
if (is_metaconsole()) { if (is_metaconsole() === true) {
// Set the server id // Set the server id.
$graph_params['server'] = $module['serverID']; $graph_params['server'] = $module['serverID'];
} }
$graph_params_str = http_build_query($graph_params); $graph_params_str = http_build_query($graph_params);
$moduleGraphURL = "$url?$graph_params_str"; $moduleGraphURL = $url.'?'.$graph_params_str;
$module['moduleGraph'] = [ $module['moduleGraph'] = [
'url' => $moduleGraphURL, 'url' => $moduleGraphURL,
'handle' => $winHandle, 'handle' => $winHandle,
]; ];
// Info to be able to open the snapshot image new page // Info to be able to open the snapshot image new page.
$module['snapshot'] = ui_get_snapshot_link( $module['snapshot'] = ui_get_snapshot_link(
[ [
'id_module' => $module['id'], 'id_module' => $module['id'],
@ -720,6 +741,16 @@ class Tree
], ],
true true
); );
if ($tresholds === true || $graphType === 'boolean') {
$graph_params['histogram'] = 1;
$graph_params_str_th = http_build_query($graph_params);
$moduleGraphURLTh = $url.'?'.$graph_params_str_th;
$module['histogramGraph'] = [
'url' => $moduleGraphURLTh,
'handle' => $winHandle,
];
}
} }
$module_alerts = alerts_get_alerts_agent_module($module['id']); $module_alerts = alerts_get_alerts_agent_module($module['id']);

View File

@ -990,6 +990,35 @@ var TreeController = {
typeof element.showGraphs != "undefined" && typeof element.showGraphs != "undefined" &&
element.showGraphs != 0 element.showGraphs != 0
) { ) {
// Graph hisstogram pop-up
if (typeof element.histogramGraph != "undefined") {
var graphImageHistogram = $(
'<img src="' +
(controller.baseURL.length > 0
? controller.baseURL
: "") +
'images/histograma.png" /> '
);
graphImageHistogram
.addClass("module-graph")
.click(function(e) {
e.stopPropagation();
try {
winopeng_var(
element.histogramGraph.url,
element.histogramGraph.handle,
800,
480
);
} catch (error) {
// console.log(error);
}
});
$content.append(graphImageHistogram);
}
// Graph pop-up // Graph pop-up
if (typeof element.moduleGraph != "undefined") { if (typeof element.moduleGraph != "undefined") {
if (element.statusImageHTML.indexOf("data:image") != -1) { if (element.statusImageHTML.indexOf("data:image") != -1) {

View File

@ -1725,6 +1725,17 @@ $table->data[4][0] .= __('Not condition').'&nbsp;'.ui_print_help_tip(__('If you
} }
if ($row['history_data'] == 1 && $acl_graphs) { if ($row['history_data'] == 1 && $acl_graphs) {
$tresholds = true;
if (empty((float) $module['min_warning']) === true
&& empty((float) $module['max_warning']) === true
&& empty($module['warning_inverse']) === true
&& empty((float) $module['min_critical']) === true
&& empty((float) $module['max_critical']) === true
&& empty($module['critical_inverse']) === true
) {
$tresholds = false;
}
$graph_type = return_graphtype($row['module_type']); $graph_type = return_graphtype($row['module_type']);
$url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false);
@ -1738,6 +1749,10 @@ $table->data[4][0] .= __('Not condition').'&nbsp;'.ui_print_help_tip(__('If you
'refresh' => SECONDS_10MINUTES, 'refresh' => SECONDS_10MINUTES,
]; ];
if ($tresholds === true || $graph_type === 'boolean') {
$graph_params['histogram'] = 1;
}
if (is_metaconsole() && isset($row['server_id'])) { if (is_metaconsole() && isset($row['server_id'])) {
// Set the server id. // Set the server id.
$graph_params['server'] = $row['server_id']; $graph_params['server'] = $row['server_id'];
@ -1749,6 +1764,18 @@ $table->data[4][0] .= __('Not condition').'&nbsp;'.ui_print_help_tip(__('If you
$data[8] = get_module_realtime_link_graph($row); $data[8] = get_module_realtime_link_graph($row);
if ($tresholds === true || $graph_type === 'boolean') {
$data[8] .= '<a href="javascript:'.$link.'">'.html_print_image(
'images/histograma.png',
true,
[
'border' => '0',
'alt' => '',
'class' => 'invert_filter',
]
).'</a>';
}
if (!is_snapshot_data($row['datos'])) { if (!is_snapshot_data($row['datos'])) {
$data[8] .= '<a href="javascript:'.$link.'">'.html_print_image('images/chart.png', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter']).'</a>'; $data[8] .= '<a href="javascript:'.$link.'">'.html_print_image('images/chart.png', true, ['border' => '0', 'alt' => '', 'class' => 'invert_filter']).'</a>';
} }