Merge branch '1217-error-in-report-template-label-in-meta-dev' into 'develop'

Added some changes to label and name macros in custom graphs

See merge request !830
This commit is contained in:
vgilc 2017-09-20 10:59:40 +02:00
commit a16827e788
1 changed files with 49 additions and 24 deletions

View File

@ -123,6 +123,8 @@ function reporting_make_reporting_data($report = null, $id_report,
return reporting_check_structure_report($report); return reporting_check_structure_report($report);
} }
$metaconsole_on = is_metaconsole();
foreach ($contents as $content) { foreach ($contents as $content) {
if (!empty($period)) { if (!empty($period)) {
$content['period'] = $period; $content['period'] = $period;
@ -136,20 +138,27 @@ function reporting_make_reporting_data($report = null, $id_report,
if ($graphs_to_macro === false) if ($graphs_to_macro === false)
$graphs_to_macro = array(); $graphs_to_macro = array();
$modules_to_macro = array (); $modules_to_macro = 0;
$agents_to_macro = array(); $agents_to_macro = array();
foreach ($graphs_to_macro as $graph_item) { foreach ($graphs_to_macro as $graph_item) {
if ($type == 'automatic_graph') { $modules_to_macro++;
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']);
}
if (in_array('label', $content['style'])) { if (in_array('label', $content['style'])) {
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'])); 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['id_agent_module'] = $content['id_agent_module'];
$items_label['modules'] = $modules_to_macro; $items_label['modules'] = $modules_to_macro;
$items_label['agents'] = $agents_to_macro; $items_label['agents'] = $agents_to_macro;
$metaconsole_on = is_metaconsole();
$server_name = $content['server_name']; $server_name = $content['server_name'];
//Metaconsole connection //Metaconsole connection
@ -181,7 +189,6 @@ function reporting_make_reporting_data($report = null, $id_report,
} }
} }
if(sizeof($content['id_agent']) != 1){ if(sizeof($content['id_agent']) != 1){
$content['style']['name_label'] = str_replace("_agent_",sizeof($content['id_agent']).__(' agents'),$content['style']['name_label']); $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'); 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']); $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']);
$return = array(); $return = array();
$return['type'] = 'custom_graph'; $return['type'] = 'custom_graph';
@ -5878,16 +5879,40 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
array_push ($modules, $graph_item['id_agent_module']); array_push ($modules, $graph_item['id_agent_module']);
} }
array_push ($weights, $graph_item["weight"]);
if (in_array('label',$content['style'])) { if (in_array('label',$content['style'])) {
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', $item = array('type' => 'custom_graph',
'id_agent' =>modules_get_agentmodule_agent($graph_item['id_agent_module']), 'id_agent' =>modules_get_agentmodule_agent($graph_item['id_agent_module']),
'id_agent_module'=>$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;
} }
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']);
}
$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'] = ''; $return['chart'] = '';
@ -10383,8 +10408,8 @@ function reporting_label_macro ($item, $label) {
} }
if (preg_match("/_module_/", $label)) { if (preg_match("/_module_/", $label)) {
if (count($item['modules']) > 1) { if ($item['modules'] > 1) {
$module_name = count($item['modules']) . __(' modules'); $module_name = $item['modules'] . __(' modules');
} }
else { else {
$module_name = modules_get_agentmodule_name($item['id_agent_module']); $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 (preg_match("/_moduledescription_/", $label)) {
if (count($item['modules']) > 1) { if ($item['modules'] > 1) {
$module_description = ""; $module_description = "";
} }
else { else {