diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d462929cff..0ed7a91dd9 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1275,9 +1275,22 @@ function graphic_combined_module( } if ($count_modules > 0) { - $sources = true; + foreach ($module_list as $key => $value) { + $sources[$key]['id_server'] = $value['server']; + $sources[$key]['id_agent_module'] = $value['module']; + $sources[$key]['weight'] = $weights[$key]; + $sources[$key]['label'] = $params_combined['labels']; + } } } else { + if (is_metaconsole()) { + metaconsole_restore_db(); + $server = metaconsole_get_connection_by_id($params['server_id']); + if (metaconsole_connect($server) != NOERR) { + return false; + } + } + $sources = db_get_all_rows_field_filter( 'tgraph_source', 'id_graph', @@ -1285,8 +1298,18 @@ function graphic_combined_module( 'field_order' ); + if (is_metaconsole()) { + if (isset($sources) && is_array($sources)) { + foreach ($sources as $key => $value) { + $sources[$key]['id_server'] = $params['server_id']; + } + } + } + $series = db_get_all_rows_sql( - 'SELECT summatory_series,average_series, modules_series + 'SELECT summatory_series, + average_series, + modules_series FROM tgraph WHERE id_graph = '.$params_combined['id_graph'] ); @@ -1295,45 +1318,76 @@ function graphic_combined_module( $average = $series[0]['average_series']; $modules_series = $series[0]['modules_series']; + if (is_metaconsole()) { + metaconsole_restore_db(); + } + } + + if (isset($sources) && is_array($sources)) { $weights = []; $labels = []; $modules = []; - - if (isset($sources) && is_array($sources)) { - foreach ($sources as $source) { - array_push($modules, $source['id_agent_module']); - array_push($weights, $source['weight']); - if ($source['label'] != '' || $params_combined['labels']) { - $id_agent = agents_get_module_id( - $source['id_agent_module'] - ); - $agent_description = agents_get_description($id_agent); - $agent_group = agents_get_agent_group($id_agent); - $agent_address = agents_get_address($id_agent); - $agent_alias = agents_get_alias($id_agent); - $module_name = modules_get_agentmodule_name( - $source['id_agent_module'] - ); - - $module_description = modules_get_agentmodule_descripcion( - $source['id_agent_module'] - ); - - $items_label = [ - 'type' => 'custom_graph', - 'id_agent' => $id_agent, - 'id_agent_module' => $source['id_agent_module'], - 'agent_description' => $agent_description, - 'agent_group' => $agent_group, - 'agent_address' => $agent_address, - 'agent_alias' => $agent_alias, - 'module_name' => $module_name, - 'module_description' => $module_description, - ]; - - $labels[$source['id_agent_module']] = ($source['label'] != '') ? reporting_label_macro($items_label, $source['label']) : reporting_label_macro($item, $params_combined['labels']); + foreach ($sources as $source) { + if (is_metaconsole() === true) { + $server = metaconsole_get_connection_by_id($source['id_server']); + if (metaconsole_connect($server) != NOERR) { + continue; } } + + $modulepush = [ + 'server' => (isset($source['id_server']) === true) ? $source['id_server'] : 0, + 'module' => $source['id_agent_module'], + ]; + + array_push($modules, $modulepush); + array_push($weights, $source['weight']); + if ($source['label'] != '' || $params_combined['labels']) { + $id_agent = agents_get_module_id( + $source['id_agent_module'] + ); + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $source['id_agent_module'] + ); + + $module_description = modules_get_agentmodule_descripcion( + $source['id_agent_module'] + ); + + $items_label = [ + 'type' => 'custom_graph', + 'id_agent' => $id_agent, + 'id_agent_module' => $source['id_agent_module'], + 'agent_description' => $agent_description, + 'agent_group' => $agent_group, + 'agent_address' => $agent_address, + 'agent_alias' => $agent_alias, + 'module_name' => $module_name, + 'module_description' => $module_description, + ]; + + if ($source['label'] != '') { + $lab = reporting_label_macro( + $items_label, + $source['label'] + ); + } else { + $lab = reporting_label_macro( + $items_label, + $params_combined['labels'] + ); + } + + $labels[$source['id_agent_module']] = $lab; + } + + if (is_metaconsole() === true) { + metaconsole_restore_db(); + } } } @@ -1429,15 +1483,17 @@ function graphic_combined_module( continue; } - if (is_metaconsole() && $params_combined['type_report'] == 'automatic_graph') { - $server = metaconsole_get_connection_by_id($agent_module_id['server']); + if (is_metaconsole()) { + $server = metaconsole_get_connection_by_id( + $agent_module_id['server'] + ); if (metaconsole_connect($server) != NOERR) { continue; } - - $agent_module_id = $agent_module_id['module']; } + $agent_module_id = $agent_module_id['module']; + $module_data = db_get_row_sql( 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = '.$agent_module_id @@ -1516,7 +1572,12 @@ function graphic_combined_module( if ($config['fixed_graph'] == false) { $water_mark = [ 'file' => $config['homedir'].'/images/logo_vertical_water.png', - 'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false), + 'url' => ui_get_full_url( + 'images/logo_vertical_water.png', + false, + false, + false + ), ]; } @@ -1525,9 +1586,7 @@ function graphic_combined_module( $i++; - if (is_metaconsole() - && $params_combined['type_report'] == 'automatic_graph' - ) { + if (is_metaconsole()) { metaconsole_restore_db(); } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 65724000f2..5e11cf7aba 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -7766,18 +7766,6 @@ function reporting_custom_graph( include_once $config['homedir'].'/include/functions_graph.php'; - if ($type_report == 'custom_graph') { - if (is_metaconsole()) { - $id_meta = metaconsole_get_id_server($content['server_name']); - $server = metaconsole_get_connection_by_id($id_meta); - if (metaconsole_connect($server) != NOERR) { - return false; - } - } - } - - $graph = db_get_row('tgraph', 'id_graph', $content['id_gs']); - $return = []; $return['type'] = 'custom_graph'; @@ -7791,10 +7779,47 @@ function reporting_custom_graph( } } + $id_meta = 0; if ($type_report == 'custom_graph') { - $graphs = db_get_all_rows_field_filter('tgraph', 'id_graph', $content['id_gs']); $id_graph = $content['id_gs']; + if (is_metaconsole()) { + $id_meta = metaconsole_get_id_server($content['server_name']); + $server = metaconsole_get_connection_by_id($id_meta); + if (metaconsole_connect($server) != NOERR) { + return false; + } + } + + $graphs = db_get_all_rows_field_filter( + 'tgraph', + 'id_graph', + $content['id_gs'] + ); + + $module_source = db_get_all_rows_sql( + 'SELECT id_agent_module + FROM tgraph_source + WHERE id_graph = '.$content['id_gs'] + ); + + if (isset($module_source) && is_array($module_source)) { + $modules = []; + foreach ($module_source as $key => $value) { + $modules[$key]['module'] = $value['id_agent_module']; + $modules[$key]['server'] = $id_meta; + } + } + + if (is_metaconsole()) { + metaconsole_restore_db(); + } } else if ($type_report == 'automatic_graph') { + $graphs = db_get_all_rows_field_filter( + 'tgraph', + 'id_graph', + $content['id_gs'] + ); + $graphs[0]['stacked'] = ''; $graphs[0]['summatory_series'] = ''; $graphs[0]['average_series'] = ''; @@ -7805,8 +7830,8 @@ function reporting_custom_graph( if (is_metaconsole()) { $module_source = db_get_all_rows_sql( 'SELECT id_agent_module, id_server - FROM tgraph_source - WHERE id_graph = '.$content['id_gs'] + FROM tgraph_source + WHERE id_graph = '.$content['id_gs'] ); if (isset($module_source) && is_array($module_source)) { @@ -7823,21 +7848,6 @@ function reporting_custom_graph( $content['name'] = __('Simple graph'); } - if ($type_report != 'automatic_graph') { - $module_source = db_get_all_rows_sql( - 'SELECT id_agent_module - FROM tgraph_source - WHERE id_graph = '.$content['id_gs'] - ); - - if (isset($module_source) && is_array($module_source)) { - $modules = []; - foreach ($module_source as $key => $value) { - $modules[$key] = $value['id_agent_module']; - } - } - } - $agent_description = agents_get_description($id_agent); $agent_group = agents_get_agent_group($id_agent); $agent_address = agents_get_address($id_agent); @@ -7853,7 +7863,7 @@ function reporting_custom_graph( $return['title'] = $content['name']; $return['landscape'] = $content['landscape']; $return['pagebreak'] = $content['pagebreak']; - $return['subtitle'] = $graph['name']; + $return['subtitle'] = $graphs[0]['name']; $return['agent_name'] = $agent_alias; $return['module_name'] = $module_name; $return['description'] = $content['description']; @@ -7933,12 +7943,6 @@ function reporting_custom_graph( break; } - if ($type_report == 'custom_graph') { - if (is_metaconsole()) { - metaconsole_restore_db(); - } - } - return reporting_check_structure_content($return); }