diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 66b36f98f1..0baeb463f7 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -122,6 +122,8 @@ function reporting_make_reporting_data($report = null, $id_report, if (empty($contents)) { return reporting_check_structure_report($report); } + + $metaconsole_on = is_metaconsole(); foreach ($contents as $content) { if (!empty($period)) { @@ -136,20 +138,27 @@ function reporting_make_reporting_data($report = null, $id_report, if ($graphs_to_macro === false) $graphs_to_macro = array(); - $modules_to_macro = array (); + $modules_to_macro = 0; $agents_to_macro = array(); foreach ($graphs_to_macro as $graph_item) { - if ($type == 'automatic_graph') { - array_push ($modules_to_macro, array( - 'module' => $graph_item['id_agent_module'], - 'server' => $graph_item['id_server'])); - } - else { - array_push ($modules_to_macro, $graph_item['id_agent_module']); - } + $modules_to_macro++; if (in_array('label', $content['style'])) { - array_push ($agents_to_macro, modules_get_agentmodule_agent($graph_item['id_agent_module'])); + if ($content['id_agent'] == 0) { + //Metaconsole connection + if ($metaconsole_on && $server_name != '') { + $connection = metaconsole_get_connection($server_name); + if (!metaconsole_load_external_db($connection)) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + array_push ($agents_to_macro, modules_get_agentmodule_agent($graph_item['id_agent_module'])); + if ($metaconsole_on) { + //Restore db connection + metaconsole_restore_db(); + } + } } } @@ -169,7 +178,6 @@ function reporting_make_reporting_data($report = null, $id_report, $items_label['id_agent_module'] = $content['id_agent_module']; $items_label['modules'] = $modules_to_macro; $items_label['agents'] = $agents_to_macro; - $metaconsole_on = is_metaconsole(); $server_name = $content['server_name']; //Metaconsole connection @@ -181,7 +189,6 @@ function reporting_make_reporting_data($report = null, $id_report, } } - if(sizeof($content['id_agent']) != 1){ $content['style']['name_label'] = str_replace("_agent_",sizeof($content['id_agent']).__(' agents'),$content['style']['name_label']); } @@ -5834,12 +5841,6 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', require_once ($config["homedir"] . '/include/functions_graph.php'); - if ($config['metaconsole'] && $type_report != 'automatic_graph') { - $id_meta = metaconsole_get_id_server($content["server_name"]); - $server = metaconsole_get_connection_by_id ($id_meta); - metaconsole_connect($server); - } - $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); $return = array(); $return['type'] = 'custom_graph'; @@ -5878,18 +5879,42 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', array_push ($modules, $graph_item['id_agent_module']); } - array_push ($weights, $graph_item["weight"]); if (in_array('label',$content['style'])) { - $item = array('type' => 'custom_graph', + if (defined('METACONSOLE')) { + $server_name = $content['server_name']; + $connection = metaconsole_get_connection($server_name); + if (!metaconsole_load_external_db($connection)) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + $item = array('type' => 'custom_graph', 'id_agent' =>modules_get_agentmodule_agent($graph_item['id_agent_module']), 'id_agent_module'=>$graph_item['id_agent_module']); + } + else { + $item = array('type' => 'custom_graph', + 'id_agent' =>modules_get_agentmodule_agent($graph_item['id_agent_module']), + 'id_agent_module'=>$graph_item['id_agent_module']); + } - //html_debug($item); $label = reporting_label_macro($item, $content['style']['label']); + $labels[$graph_item['id_agent_module']] = $label; + if (defined('METACONSOLE')) { + //Restore db connection + metaconsole_restore_db(); + } } + + array_push ($weights, $graph_item["weight"]); } + if ($config['metaconsole'] && $type_report != 'automatic_graph') { + $id_meta = metaconsole_get_id_server($content["server_name"]); + $server = metaconsole_get_connection_by_id ($id_meta); + metaconsole_connect($server); + } + $return['chart'] = ''; // Get chart reporting_set_conf_charts($width, $height, $only_image, $type, @@ -10383,8 +10408,8 @@ function reporting_label_macro ($item, $label) { } if (preg_match("/_module_/", $label)) { - if (count($item['modules']) > 1) { - $module_name = count($item['modules']) . __(' modules'); + if ($item['modules'] > 1) { + $module_name = $item['modules'] . __(' modules'); } else { $module_name = modules_get_agentmodule_name($item['id_agent_module']); @@ -10394,7 +10419,7 @@ function reporting_label_macro ($item, $label) { } if (preg_match("/_moduledescription_/", $label)) { - if (count($item['modules']) > 1) { + if ($item['modules'] > 1) { $module_description = ""; } else {