Merge branch 'ent-9125-Bug-a-la-hora-de-crear-gráficas-personalizadas-desde-el-agente' into 'develop'

Ent 9125 bug a la hora de crear gráficas personalizadas desde el agente

https://brutus.artica.es:8081/artica/pandora_enterprise/-/issues/9125

See merge request artica/pandorafms!4946
This commit is contained in:
Jimmy Olano 2022-06-29 22:25:00 +00:00
commit f07ed9e4e9
1 changed files with 94 additions and 96 deletions

View File

@ -18,7 +18,7 @@ require_once 'include/functions_agents.php';
require_once 'include/functions_custom_graphs.php'; require_once 'include/functions_custom_graphs.php';
ui_require_javascript_file('calendar'); ui_require_javascript_file('calendar');
if (! check_acl($config['id_user'], $id_grupo, 'AR') && ! check_acl($config['id_user'], 0, 'AW')) { if (!check_acl($config['id_user'], $id_grupo, 'AR') && !check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit( db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION, AUDIT_LOG_ACL_VIOLATION,
'Trying to access (read) to agent '.agents_get_name($id_agente) 'Trying to access (read) to agent '.agents_get_name($id_agente)
@ -53,7 +53,7 @@ $modules_networkmap_no_proc = agents_get_modules(
false, false,
[ [
'id_modulo' => 2, 'id_modulo' => 2,
// networkmap type // Networkmap type.
'id_tipo_modulo' => [ 'id_tipo_modulo' => [
'<>2', '<>2',
// != generic_proc // != generic_proc
@ -133,7 +133,7 @@ if (empty($modules_boolean)) {
$modules_boolean = []; $modules_boolean = [];
} }
// Cleaned the duplicate $modules and other things // Cleaned the duplicate $modules and other things.
$modules_others = array_diff_key( $modules_others = array_diff_key(
$modules_others, $modules_others,
$modules_networkmap_no_proc $modules_networkmap_no_proc
@ -278,7 +278,7 @@ if ($start_date != $current) {
} }
if ($combined) { if ($combined) {
// Pass the $modules before the ajax call // Pass the $modules before the ajax call.
echo '<div class="combined-graph-container center w100p"'.'data-period="'.$period.'"'.'data-stacked="'.CUSTOM_GRAPH_LINE.'"'.'data-date="'.$date.'"'.'data-height="'.$height.'"'.'>'.html_print_image('images/spinner.gif', true).'</div>'; echo '<div class="combined-graph-container center w100p"'.'data-period="'.$period.'"'.'data-stacked="'.CUSTOM_GRAPH_LINE.'"'.'data-date="'.$date.'"'.'data-height="'.$height.'"'.'>'.html_print_image('images/spinner.gif', true).'</div>';
} else { } else {
foreach ($modules as $id_module) { foreach ($modules as $id_module) {
@ -296,7 +296,7 @@ echo '<div id="graph-error-message" class="invisible">';
ui_print_error_message(__('There was an error loading the graph')); ui_print_error_message(__('There was an error loading the graph'));
echo '</div>'; echo '</div>';
// Dialog to save the custom graph // Dialog to save the custom graph.
echo "<div id='dialog_save_custom_graph' class='invisible'>"; echo "<div id='dialog_save_custom_graph' class='invisible'>";
$table = new stdClass(); $table = new stdClass();
$table->width = '100%'; $table->width = '100%';
@ -314,40 +314,40 @@ $table->data[0][1] = html_print_input_text(
html_print_table($table); html_print_table($table);
echo "<div style='width: ".$table->width."; text-align: right;'>"; echo "<div style='width: ".$table->width."; text-align: right;'>";
html_print_image( html_print_image(
'images/spinner.gif', 'images/spinner.gif',
false, false,
[ [
'style' => 'display: none', 'style' => 'display: none',
'class' => 'loading_save', 'class' => 'loading_save',
] ]
); );
html_print_image( html_print_image(
'images/ok.png', 'images/ok.png',
false, false,
[ [
'style' => 'display: none', 'style' => 'display: none',
'class' => 'ok_save', 'class' => 'ok_save',
] ]
); );
html_print_image( html_print_image(
'images/error_red.png', 'images/error_red.png',
false, false,
[ [
'style' => 'display: none', 'style' => 'display: none',
'class' => 'error_save', 'class' => 'error_save',
] ]
); );
html_print_button( html_print_button(
__('Save'), __('Save'),
'save_custom_graph', 'save_custom_graph',
false, false,
'save_custom_graph_second_step();', 'save_custom_graph_second_step();',
'class="button_save sub save"' 'class="button_save sub save"'
); );
echo '</div>'; echo '</div>';
echo '</div>'; echo '</div>';
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$("#dialog_save_custom_graph").dialog({ $("#dialog_save_custom_graph").dialog({
@ -359,7 +359,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
}); });
}); });
$('#button-save_custom_graph').click(function (event) { $('#button-save_custom_graph').click(function(event) {
$("#dialog_save_custom_graph").dialog("open"); $("#dialog_save_custom_graph").dialog("open");
}); });
@ -373,7 +373,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
params["id_modules"] = <?php echo json_encode($modules); ?>; params["id_modules"] = <?php echo json_encode($modules); ?>;
params["name"] = $("input[name='name_custom_graph']").val(); params["name"] = $("input[name='name_custom_graph']").val();
params["description"] = "<?php echo __('Custom graph create from the tab graphs in the agent.'); ?>"; params["description"] = "<?php echo __('Custom graph create from the tab graphs in the agent.'); ?>";
params["stacked"] = <?php echo CUSTOM_GRAPH_LINE; ?>; params["stacked"] = parseInt($("#option_type").val());
params["width"] = <?php echo $width; ?>; params["width"] = <?php echo $width; ?>;
params["height"] = <?php echo $height; ?>; params["height"] = <?php echo $height; ?>;
params["events"] = <?php echo $draw_events; ?>; params["events"] = <?php echo $draw_events; ?>;
@ -381,17 +381,16 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
params["save_custom_graph"] = 1; params["save_custom_graph"] = 1;
params["page"] = "include/ajax/graph.ajax"; params["page"] = "include/ajax/graph.ajax";
jQuery.ajax ({ jQuery.ajax({
data: params, data: params,
dataType: "json", dataType: "json",
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
success: function (data) { success: function(data) {
$(".loading_save").hide(); $(".loading_save").hide();
if (data.correct) { if (data.correct) {
$(".ok_save").show(); $(".ok_save").show();
} } else {
else {
$(".error_save").show(); $(".error_save").show();
$(".button_save").enable(); $(".button_save").enable();
} }
@ -401,7 +400,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
// Load graphs // Load graphs
$(document).ready(function() { $(document).ready(function() {
$('#combined').change(function () { $('#combined').change(function() {
if ($('#combined').val() == 1) { if ($('#combined').val() == 1) {
$('#option_type').empty(); $('#option_type').empty();
$('#option_type').append($('<option>', { $('#option_type').append($('<option>', {
@ -420,8 +419,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
value: 3, value: 3,
text: "<?php echo __('Line stack'); ?>" text: "<?php echo __('Line stack'); ?>"
})); }));
} } else {
else {
$('#option_type').empty(); $('#option_type').empty();
$('#option_type').append($('<option>', { $('#option_type').append($('<option>', {
value: 0, value: 0,
@ -434,11 +432,11 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
} }
}); });
var getModulesPHP = function () { var getModulesPHP = function() {
return <?php echo json_encode($modules); ?>; return <?php echo json_encode($modules); ?>;
} }
var requestGraph = function (type, data) { var requestGraph = function(type, data) {
data = data || {}; data = data || {};
type = type || 'custom'; type = type || 'custom';
data.page = 'include/ajax/graph.ajax'; data.page = 'include/ajax/graph.ajax';
@ -452,7 +450,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
}) })
} }
var requestCustomGraph = function (graphId, width, height, period, stacked, date, modules) { var requestCustomGraph = function(graphId, width, height, period, stacked, date, modules) {
return requestGraph('custom', { return requestGraph('custom', {
page: 'include/ajax/graph.ajax', page: 'include/ajax/graph.ajax',
print_custom_graph: 1, print_custom_graph: 1,
@ -466,7 +464,7 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
}); });
} }
var requestSparseGraph = function (moduleId, period, showEvents, width, height, title, showAlerts, date, unit, type_g) { var requestSparseGraph = function(moduleId, period, showEvents, width, height, title, showAlerts, date, unit, type_g) {
return requestGraph('sparse', { return requestGraph('sparse', {
page: 'include/ajax/graph.ajax', page: 'include/ajax/graph.ajax',
print_sparse_graph: 1, print_sparse_graph: 1,
@ -483,13 +481,13 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
}); });
} }
var loadCustomGraphs = function () { var loadCustomGraphs = function() {
$('div.combined-graph-container').each(function (index, el) { $('div.combined-graph-container').each(function(index, el) {
loadCustomGraph(el); loadCustomGraph(el);
}); });
} }
var loadCustomGraph = function (element) { var loadCustomGraph = function(element) {
var $container = $(element); var $container = $(element);
var $errorMessage = $('div#graph-error-message'); var $errorMessage = $('div#graph-error-message');
var period = $container.data('period'); var period = $container.data('period');
@ -516,10 +514,10 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
var modules = getModulesPHP(); var modules = getModulesPHP();
var width = $container.width() - 20; var width = $container.width() - 20;
var handleSuccess = function (data) { var handleSuccess = function(data) {
$container.html(data); $container.html(data);
} }
var handleError = function (xhr, textStatus, errorThrown) { var handleError = function(xhr, textStatus, errorThrown) {
$container.html($errorMessage.html()); $container.html($errorMessage.html());
} }
@ -528,13 +526,13 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
.fail(handleError); .fail(handleError);
} }
var loadSparseGraphs = function () { var loadSparseGraphs = function() {
$('div.sparse-graph-container').each(function (index, el) { $('div.sparse-graph-container').each(function(index, el) {
loadSparseGraph(el); loadSparseGraph(el);
}); });
} }
var loadSparseGraph = function (element) { var loadSparseGraph = function(element) {
var $container = $(element); var $container = $(element);
var $errorMessage = $('div#graph-error-message'); var $errorMessage = $('div#graph-error-message');
var moduleId = $container.data('id_module'); var moduleId = $container.data('id_module');
@ -559,10 +557,10 @@ echo "<div style='width: ".$table->width."; text-align: right;'>";
var width = $container.width() - 20; var width = $container.width() - 20;
var handleSuccess = function (data) { var handleSuccess = function(data) {
$container.html(data); $container.html(data);
} }
var handleError = function (xhr, textStatus, errorThrown) { var handleError = function(xhr, textStatus, errorThrown) {
$container.html($errorMessage.html()); $container.html($errorMessage.html());
} }