From 08ab924160067e8a909c43ca271ff8b6f15cff2b Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 17 Oct 2022 18:08:48 +0200 Subject: [PATCH 1/2] fix performance issue --- .../reporting_builder.item_editor.php | 95 +++++++++++-------- .../include/ajax/reporting.ajax.php | 60 ++++++++++++ 2 files changed, 117 insertions(+), 38 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 3cc78b737c..c1714df9ed 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1786,46 +1786,10 @@ $class = 'databox filters'; $value) { - $agents2[$value['id_agente']] = $value['alias']; - } - } - - if ((empty($agents2)) || $agents2 == -1) { - $agents = []; - } - - $agents_select = []; - if (is_array($id_agents) || is_object($id_agents)) { - foreach ($id_agents as $id) { - foreach ($agents2 as $key => $a) { - if ($key == (int) $id) { - $agents_select[$key] = $key; - } - } - } - } - html_print_select( - $agents2, + [], 'id_agents3[]', - $agents_select, + '', $script = '', '', 0, @@ -6110,6 +6074,58 @@ function addGeneralRow() { } } +function loadLogAgents() { + var params = []; + + params.push("get_log_agents=1"); + params.push("source="); + params.push('id_agents='); + params.push("page=include/ajax/reporting.ajax"); + + $('#id_agents3') + .find('option') + .remove(); + + $('#id_agents3') + .append(''); + + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action= + + + "/ajax.php", + timeout: 300000, + dataType: 'json', + success: function (data) { + if (data['correct']) { + $('#id_agents3') + .find('option') + .remove(); + + var selectElements = []; + var selectedStr = 'selected="selected"' + data['select_agents'].forEach(function(agentAlias, agentID) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents3') + .append(''); + }); + } + } + }); +} + function chooseType() { var meta = ''; type = $("#type").val(); @@ -6278,6 +6294,9 @@ function chooseType() { $("#agents_row").show(); $("#row_source").show(); $("#row_historical_db_check").hide(); + + loadLogAgents(); + break; case 'increment': diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index bafe01307d..977af7f372 100755 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -25,6 +25,9 @@ if (! check_acl($config['id_user'], 0, 'RW')) { exit; } +$get_log_agents = (bool) get_parameter('get_log_agents', 0); +$agents_id = get_parameter('id_agents', []); +$agents_id = get_parameter('source', 0); $delete_sla_item = get_parameter('delete_sla_item', 0); $delete_general_item = get_parameter('delete_general_item', 0); $get_custom_sql = get_parameter('get_custom_sql', 0); @@ -244,3 +247,60 @@ if ($change_custom_fields_macros_report === true) { echo $custom_field_draw; return; } + +if ($get_log_agents === true) { + try { + $agents_id = json_decode($agents_id, true); + } catch (Exception $e) { + $data['correct'] = 0; + echo json_encode($data); + return; + } + + if ($source) { + $sql_log_report = 'SELECT id_agente, alias + FROM tagente, tagent_module_log + WHERE tagente.id_agente = tagent_module_log.id_agent + AND tagente.disabled = 0 + AND tagent_module_log.source like "'.$source.'"'; + } else { + $sql_log_report = 'SELECT id_agente, alias + FROM tagente, tagent_module_log + WHERE tagente.id_agente = tagent_module_log.id_agent + AND tagente.disabled = 0'; + } + + $all_agent_log = db_get_all_rows_sql($sql_log_report); + + if (isset($all_agent_log) && is_array($all_agent_log)) { + foreach ($all_agent_log as $key => $value) { + $select_agents[$value['id_agente']] = $value['alias']; + } + } + + if ((empty($select_agents)) || $select_agents == -1) { + $agents = []; + } + + $agents_selected = []; + if (is_array($agents_id) === true || is_object($agents_id) === true) { + foreach ($select_agents as $key => $a) { + if (in_array((string) $key, $agents_id)) { + $agents_selected[$key] = $key; + } + } + } + + $data['select_agents'] = $select_agents; + $data['agents_selected'] = $agents_selected; + + $data['correct'] = 1; + + if ($result === false) { + $data['correct'] = 0; + } + + echo json_encode($data); + + return; +} From 514b350e140f50ccf5f61790ffdc1e2ddb2f06d6 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 3 Nov 2022 18:20:39 +0100 Subject: [PATCH 2/2] fixed performance problems --- .../reporting_builder.item_editor.php | 126 ++++++++++++++++-- .../include/ajax/reporting.ajax.php | 61 +++++++-- 2 files changed, 167 insertions(+), 20 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index c1714df9ed..3890d8c946 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1815,9 +1815,9 @@ $class = 'databox filters'; $all_agents = agents_get_agents_selected($group); html_print_select( - $all_agents, + [], 'id_agents2[]', - $id_agents, + '', $script = '', '', 0, @@ -6074,6 +6074,79 @@ function addGeneralRow() { } } +function loadGeneralAgents(agent_group) { + var params = []; + + var group = ; + group = agent_group || group; + + params.push("get_agents=1"); + params.push("group="+parseInt(group)); + params.push('id_agents='); + params.push("page=include/ajax/reporting.ajax"); + + + $('#id_agents2') + .find('option') + .remove(); + + $('#id_agents2') + .append(''); + + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action= + + + "/ajax.php", + timeout: 300000, + dataType: 'json', + success: function (data) { + if (data['correct']) { + $('#id_agents2') + .find('option') + .remove(); + + var selectElements = []; + var selectedStr = 'selected="selected"'; + + if (data['select_agents'] === null) { + return; + } + + if (Array.isArray(data['select_agents'])) { + data['select_agents'].forEach(function(agentAlias, agentID) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents2') + .append(''); + }); + } else { + for (const [agentID, agentAlias] of Object.entries(data['select_agents'])) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents2') + .append(''); + } + } + } + } + }); +} + function loadLogAgents() { var params = []; @@ -6111,16 +6184,33 @@ function loadLogAgents() { .remove(); var selectElements = []; - var selectedStr = 'selected="selected"' - data['select_agents'].forEach(function(agentAlias, agentID) { - var optionAttr = ''; - if (typeof data['agents_selected'][agentID] !== 'undefined') { - optionAttr = ' selected="selected"'; - } + var selectedStr = 'selected="selected"'; - $('#id_agents3') - .append(''); - }); + if (data['select_agents'] === null) { + return; + } + + if (Array.isArray(data['select_agents'])) { + data['select_agents'].forEach(function(agentAlias, agentID) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents3') + .append(''); + }); + } else { + for (const [agentID, agentAlias] of Object.entries(data['select_agents'])) { + var optionAttr = ''; + if (typeof data['agents_selected'][agentID] !== 'undefined') { + optionAttr = ' selected="selected"'; + } + + $('#id_agents3') + .append(''); + } + } } } }); @@ -6587,6 +6677,13 @@ function chooseType() { $("#lapse_select").val('0').trigger('change'); $("#hidden-lapse").val('0'); } + + loadGeneralAgents(); + + $("#combo_group").change(function() { + loadGeneralAgents($(this).val()); + }); + break; case 'event_report_group': @@ -6782,6 +6879,12 @@ function chooseType() { $("#agents_modules_row").show(); $("#modules_row").show(); $("#row_historical_db_check").hide(); + + loadGeneralAgents(); + + $("#combo_group").change(function() { + loadGeneralAgents($(this).val()); + }); break; case 'inventory_changes': @@ -7158,7 +7261,6 @@ function change_custom_fields_macros_report(id) { "macro_id": id }, function (data, status) { - console.log(id); $("td#table-macros-definition-"+id+"-value").empty(); $("td#table-macros-definition-"+id+"-value").append(data); }, diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index 977af7f372..ae70c0d3d5 100755 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -26,8 +26,10 @@ if (! check_acl($config['id_user'], 0, 'RW')) { } $get_log_agents = (bool) get_parameter('get_log_agents', 0); +$get_agents = (bool) get_parameter('get_agents', 0); $agents_id = get_parameter('id_agents', []); -$agents_id = get_parameter('source', 0); +$source = get_parameter('source', 0); +$group = get_parameter('group', 0); $delete_sla_item = get_parameter('delete_sla_item', 0); $delete_general_item = get_parameter('delete_general_item', 0); $get_custom_sql = get_parameter('get_custom_sql', 0); @@ -248,7 +250,55 @@ if ($change_custom_fields_macros_report === true) { return; } +if ($get_agents === true) { + $agents_id = str_replace('"', '', $agents_id); + + try { + $agents_id = json_decode($agents_id, true); + } catch (Exception $e) { + $data['correct'] = 0; + echo json_encode($data); + return; + } + + $agents = agents_get_agents_selected($group); + + if (isset($agents) && is_array($agents)) { + foreach ($agents as $key => $value) { + $select_agents[$key] = $value; + } + } + + if ((empty($select_agents)) || $select_agents == -1) { + $agents = []; + } + + $agents_selected = []; + if (is_array($agents_id) === true || is_object($agents_id) === true) { + foreach ($select_agents as $key => $a) { + if (in_array((string) $key, $agents_id) === true) { + $agents_selected[$key] = $key; + } + } + } + + $data['select_agents'] = $select_agents; + $data['agents_selected'] = $agents_selected; + + $data['correct'] = 1; + + if ($result === false) { + $data['correct'] = 0; + } + + echo json_encode($data); + + return; +} + if ($get_log_agents === true) { + $agents_id = str_replace('"', '', $agents_id); + try { $agents_id = json_decode($agents_id, true); } catch (Exception $e) { @@ -259,15 +309,10 @@ if ($get_log_agents === true) { if ($source) { $sql_log_report = 'SELECT id_agente, alias - FROM tagente, tagent_module_log - WHERE tagente.id_agente = tagent_module_log.id_agent - AND tagente.disabled = 0 - AND tagent_module_log.source like "'.$source.'"'; + FROM tagente'; } else { $sql_log_report = 'SELECT id_agente, alias - FROM tagente, tagent_module_log - WHERE tagente.id_agente = tagent_module_log.id_agent - AND tagente.disabled = 0'; + FROM tagente'; } $all_agent_log = db_get_all_rows_sql($sql_log_report);