fixed errors in graph

This commit is contained in:
daniel 2018-06-01 13:58:29 +02:00
parent a8b8f309e6
commit 47a287b6f6
11 changed files with 1116 additions and 1043 deletions

View File

@ -45,31 +45,37 @@ if ($save_custom_graph) {
if ($print_custom_graph) {
ob_clean();
$id_graph = (int) get_parameter('id_graph');
$height = (int) get_parameter('height', CHART_DEFAULT_HEIGHT);
$width = (int) get_parameter('width', CHART_DEFAULT_WIDTH);
$period = (int) get_parameter('period', SECONDS_5MINUTES);
$stacked = (int) get_parameter('stacked', CUSTOM_GRAPH_LINE);
$date = (int) get_parameter('date', time());
$only_image = (bool) get_parameter('only_image');
$background_color = (string) get_parameter('background_color', 'white');
$modules_param = get_parameter('modules_param', array());
$homeurl = (string) get_parameter('homeurl');
$name_list = get_parameter('name_list', array());
$unit_list = get_parameter('unit_list', array());
$show_last = (bool) get_parameter('show_last', true);
$show_max = (bool) get_parameter('show_max', true);
$show_min = (bool) get_parameter('show_min', true);
$show_avg = (bool) get_parameter('show_avg', true);
$ttl = (int) get_parameter('ttl', 1);
$dashboard = (bool) get_parameter('dashboard');
$vconsole = (bool) get_parameter('vconsole');
$fullscale = (bool) get_parameter('fullscale');
$params =array(
'period' => (int) get_parameter('period', SECONDS_5MINUTES),
'width' => (int) get_parameter('width', CHART_DEFAULT_WIDTH),
'height' => (int) get_parameter('height', CHART_DEFAULT_HEIGHT),
'unit_name' => get_parameter('unit_list', array()),
'date' => (int) get_parameter('date', time()),
'only_image' => (bool) get_parameter('only_image', false),
'homeurl' => (string) get_parameter('homeurl', ''),
'ttl' => (int) get_parameter('ttl', 1),
'dashboard' => (bool) get_parameter('dashboard', false),
'vconsole' => (bool) get_parameter('vconsole', false),
'fullscale' => (bool) get_parameter('fullscale', false),
'backgroundColor' => (string) get_parameter('background_color', 'white'),
'show_alerts' => (bool) get_parameter('show_alerts'),
'show_events' => (bool) get_parameter('show_events'),
'type_graph' => get_parameter('type_g', $config['type_module_charts']),
);
echo custom_graphs_print($id_graph, $height, $width, $period, $stacked,
true, $date, $only_image, $background_color, $modules_param,
$homeurl, $name_list, $unit_list, $show_last, $show_max,
$show_min, $show_avg, $ttl, $dashboard, $vconsole);
$params_combined = array(
'stacked' => (int) get_parameter('stacked', CUSTOM_GRAPH_LINE),
'labels' => get_parameter('name_list', array()),
'modules_series' => get_parameter('modules_param', array()),
'id_graph' => (int) get_parameter('id_graph', 0),
'return' => 1
);
echo graphic_combined_module(
get_parameter('modules_param', array()),
$params,
$params_combined
);
return;
}
@ -184,24 +190,6 @@ if ($get_graphs){
break;
case 'custom_graph':
if ($contador > 0) {
$graph = db_get_all_rows_field_filter('tgraph', 'id_graph',$value['id_graph']);
$sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph',$value['id_graph']);
$modules = array ();
$weights = array ();
$labels = array ();
foreach ($sources as $source) {
array_push ($modules, $source['id_agent_module']);
array_push ($weights, $source['weight']);
if ($source['label'] != ''){
$item['type'] = 'custom_graph';
$item['id_agent'] = agents_get_module_id($source['id_agent_module']);
$item['id_agent_module'] = $source['id_agent_module'];
$labels[$source['id_agent_module']] = reporting_label_macro($item, $source['label']);
}
}
$homeurl = ui_get_full_url(false, false, false, false);
$graph_conf = db_get_row('tgraph', 'id_graph', $value['id_graph']);
if($graph_conf['stacked'] == 4 || $graph_conf['stacked'] == 9){
@ -211,40 +199,28 @@ if ($get_graphs){
} else {
$height = 300;
}
$table .= "<div style='width: 90%'><h4>".$graph[0]['name']."</h4><hr></div>";
$table .= graphic_combined_module(
$modules,
$weights,
$value['time_lapse'],
1000,
$height,
'',
'',
0,
0,
0,
$graph_conf['stacked'],
0,
false,
$homeurl,
1,
false,
false,
'white',
array(),
array(),
1,
1,
1,
1,
$labels,
false,
false,
$graph_conf['percentil'] == 1,
false,
false,
$value['fullscale']
$params =array(
'period' => $value['time_lapse'],
'width' => 1000,
'height' => $height,
'percentil' => $graph_conf['percentil'] == 1,
'fullscale' => $value['fullscale']
);
$params_combined = array(
'stacked' => $graph_conf['stacked'],
'id_graph' => $value['id_graph']
);
$table .= graphic_combined_module(
false,
$params,
$params_combined
);
$contador --;
}
break;

View File

@ -252,10 +252,24 @@ switch ($action) {
}
}
$params =array(
'period' => $period,
'width' => $width,
'height' => $height,
'vconsole' => true,
'backgroundColor'=> $background_color
);
$params_combined = array(
'id_graph' => $id_custom_graph
);
if ($id_custom_graph != 0) {
$img = custom_graphs_print(
$id_custom_graph, $height, $width, $period,
null, true, 0, true, $background_color);
$img = graphic_combined_module(
false,
$params,
$params_combined
);
}
else {
$params =array(
@ -264,8 +278,6 @@ switch ($action) {
'show_events' => false,
'width' => $width,
'height' => $height,
//'only_image' => true,
//'homeurl' => '',
'menu' => false,
'backgroundColor' => $background_color,
'vconsole' => true,

View File

@ -94,15 +94,32 @@ if (file_exists ('languages/'.$user_language.'.mo')) {
<body bgcolor="#ffffff" style='background:#ffffff;'>
<?php
$params = json_decode($_GET['data'], true);
$params = json_decode($_GET['data'], true);
//XXXXXX
$params['only_image'] = false;
$params['width'] = '1048';
$params['width'] = '1048';
echo '<p> Grafica molona para ' . $params['agent_module_id'] . '</p>';
echo '<div>';
echo grafico_modulo_sparse ($params);
echo '</div>';
//cominadasssss
$params_combined = json_decode($_GET['data_combined'], true);
$module_list = json_decode($_GET['data_module_list'], true);
$type_graph_pdf = $_GET['type_graph_pdf'];
if($type_graph_pdf == 'combined'){
echo '<p> Grafica molona para combinadaaaaaaaaaaaaa</p>';
echo '<div>';
echo graphic_combined_module(
$module_list,
$params,
$params_combined
);
echo '</div>';
}
elseif($type_graph_pdf == 'sparse'){
echo '<p> Grafica molona para ' . $params['agent_module_id'] . '</p>';
echo '<div>';
echo grafico_modulo_sparse ($params);
echo '</div>';
}
?>
</body>
</html>

View File

@ -3117,23 +3117,32 @@ function series_type_graph_array($data, $show_elements_graph){
return false;
}
function generator_chart_to_pdf($params){
function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = false, $module_list = false){
global $config;
$params_encode_json = urlencode(json_encode($params));
$file_js = $config["homedir"] . "/include/web2image.js";
$url = $config["homeurl"] . "/include/chart_generator.php";
$img_file = "img_". uniqid() . $params['agent_module_id'] .".png";
$file_js = $config["homedir"] . "/include/web2image.js";
$url = $config["homeurl"] . "/include/chart_generator.php";
$img_file = "img_". uniqid() .".png";
$img_path = $config["homedir"] . "/attachment/" . $img_file;
$img_url = $config["homeurl"] . "/attachment/" . $img_file;
error_log($img_url);
$width_img = 500;
$height_img = 450;
//html_debug_print('entrando en llamada a phantom.js.......', true);
$result = exec("phantomjs " . $file_js . " " . $url . " '" . $params_encode_json . "' " . $img_path . " " . $width_img . " " . $height_img);
$params_encode_json = urlencode(json_encode($params));
if($params_combined){
$params_combined = urlencode(json_encode($params_combined));
}
if($module_list){
$module_list = urlencode(json_encode($module_list));
}
$result = exec("phantomjs " . $file_js . " " . $url . " '" . $type_graph_pdf . "' '" . $params_encode_json . "' '" . $params_combined . "' '" . $module_list . "' " . $img_path . " " . $width_img . " " . $height_img);
return '<img src="' . $img_url . '" />';
//html_debug_print('entrando en llamada a phantom.js.......', true);
//header('Content-Type: image/png;');
//return '<img src="data:image/jpg;base64, '.$result.'" />';
//return "<img src='/var/www/html/pandora_console/attachment/imagen_". $params['agent_module_id'] .".png' alt='la imagen bonica'>";

View File

@ -21,7 +21,7 @@
/**
* @global array Contents all var configs for the local instalation.
* @global array Contents all var configs for the local instalation.
*/
global $config;
@ -32,13 +32,13 @@ function custom_graphs_create($id_modules = array(), $name = "",
$description = "", $stacked = CUSTOM_GRAPH_AREA, $width = 0,
$height = 0, $events = 0 , $period = 0, $private = 0, $id_group = 0,
$user = false, $fullscale = 0) {
global $config;
if ($user === false) {
$user = $config['id_user'];
}
$id_graph = db_process_sql_insert('tgraph',
array(
'id_user' => $user,
@ -54,7 +54,7 @@ function custom_graphs_create($id_modules = array(), $name = "",
'id_graph_template' => 0,
'fullscale' => $fullscale,
));
if (empty($id_graph)) {
return false;
}
@ -67,22 +67,22 @@ function custom_graphs_create($id_modules = array(), $name = "",
'id_agent_module' => $id_module,
'weight' => 1
));
if (empty($result))
break;
}
if (empty($result)) {
//Not it is a complete insert the modules. Delete all
db_process_sql_delete('tgraph_source',
array('id_graph' => $id_graph));
db_process_sql_delete('tgraph',
array('id_graph' => $id_graph));
return false;
}
return $id_graph;
}
}
@ -100,30 +100,30 @@ function custom_graphs_create($id_modules = array(), $name = "",
*/
function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') {
global $config;
if (!$id_user) {
$id_user = $config['id_user'];
}
$groups = users_get_groups ($id_user, $privileges, $returnAllGroup);
$all_graphs = db_get_all_rows_in_table ('tgraph', 'name');
if ($all_graphs === false)
return array ();
$graphs = array ();
foreach ($all_graphs as $graph) {
if (!in_array($graph['id_group'], array_keys($groups)))
continue;
if ($graph["id_user"] != $id_user && $graph['private'])
continue;
if ($graph["id_group"] > 0)
if (!isset($groups[$graph["id_group"]])) {
continue;
}
if ($only_names) {
$graphs[$graph['id_graph']] = $graph['name'];
}
@ -135,149 +135,7 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr
$graphs[$graph['id_graph']]['graphs_count'] = $graphsCount;
}
}
return $graphs;
}
/**
* Print a custom graph image.
*
* @param $id_graph Graph id to print.
* @param $height Height of the returning image.
* @param $width Width of the returning image.
* @param $period Period of time to get data in seconds.
* @param $stacked Whether the graph is stacked or not.
* @param $return Whether to return an output string or echo now (optional, echo by default).
* @param $date Date to start printing the graph
* @param bool Wether to show an image instead a interactive chart or not
* @param string Background color
* @param array List of names for the items. Should have the same size as the module list.
* @param bool Show the last value of the item on the list.
* @param bool Show the max value of the item on the list.
* @param bool Show the min value of the item on the list.
* @param bool Show the average value of the item on the list.
*
* @return Mixed
*/
function custom_graphs_print($id_graph, $height, $width, $period,
$stacked = null, $return = false, $date = 0, $only_image = false,
$background_color = 'white', $modules_param = array(), $homeurl = '',
$name_list = array(), $unit_list = array(), $show_last = true,
$show_max = true, $show_min = true, $show_avg = true, $ttl = 1,
$dashboard = false, $vconsole = false, $percentil = null,
$from_interface = false,$id_widget_dashboard=false, $fullscale = false) {
global $config;
if ($from_interface) {
if ($config["type_interface_charts"] == 'line') {
$graph_conf['stacked'] = CUSTOM_GRAPH_LINE;
}
else {
$graph_conf['stacked'] = CUSTOM_GRAPH_AREA;
}
}
else {
if ($id_graph == 0) {
$graph_conf['stacked'] = CUSTOM_GRAPH_LINE;
}
else {
$graph_conf = db_get_row('tgraph', 'id_graph', $id_graph);
}
}
if ($stacked === null) {
$stacked = $graph_conf['stacked'];
}
$sources = false;
if ($id_graph == 0) {
$modules = $modules_param;
$count_modules = count($modules);
$weights = array_fill(0, $count_modules, 1);
if ($count_modules > 0)
$sources = true;
}
else {
$sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph',
$id_graph);
$series = db_get_all_rows_sql('SELECT summatory_series,average_series,modules_series FROM tgraph WHERE id_graph = '.$id_graph);
$summatory = $series[0]['summatory_series'];
$average = $series[0]['average_series'];
$modules_series = $series[0]['modules_series'];
$modules = array ();
$weights = array ();
$labels = array ();
foreach ($sources as $source) {
array_push ($modules, $source['id_agent_module']);
array_push ($weights, $source['weight']);
if ($source['label'] != ''){
$item['type'] = 'custom_graph';
$item['id_agent'] = agents_get_module_id($source['id_agent_module']);
$item['id_agent_module'] = $source['id_agent_module'];
$labels[$source['id_agent_module']] = reporting_label_macro($item, $source['label']);
}
}
}
if ($sources === false) {
if ($return){
return false;
}
else{
ui_print_info_message ( array ( 'no_close' => true, 'message' => __('No items.') ) );
return;
}
}
if (empty($homeurl)) {
$homeurl = ui_get_full_url(false, false, false, false);
}
$output = graphic_combined_module(
$modules,
$weights,
$period,
$width,
$height,
'',
'',
0,
0,
0,
$stacked,
$date,
$only_image,
$homeurl,
$ttl,
false,
false,
$background_color,
$name_list,
array(),
$show_last,
$show_max,
$show_min,
$show_avg,
$labels,
$dashboard,
$vconsole,
$percentil,
$from_interface,
$id_widget_dashboard,
$fullscale,
$summatory,
$average,
$modules_series
);
if ($return)
return $output;
echo $output;
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -288,7 +288,10 @@ function reporting_make_reporting_data($report = null, $id_report,
$content,
$type,
$force_width_chart,
$force_height_chart, 'custom_graph');
$force_height_chart,
'custom_graph',
$pdf
);
break;
case 'automatic_graph':
$report['contents'][] =
@ -297,7 +300,10 @@ function reporting_make_reporting_data($report = null, $id_report,
$content,
$type,
$force_width_chart,
$force_height_chart, 'automatic_graph');
$force_height_chart,
'automatic_graph',
$pdf
);
break;
case 'text':
$report['contents'][] = reporting_text(
@ -374,7 +380,9 @@ function reporting_make_reporting_data($report = null, $id_report,
$content,
$type,
$force_width_chart,
$force_height_chart);
$force_height_chart,
$pdf
);
break;
case 'prediction_date':
$report['contents'][] = reporting_prediction_date(
@ -490,7 +498,9 @@ function reporting_make_reporting_data($report = null, $id_report,
$report['contents'][] = reporting_network_interfaces_report(
$report,
$content,
$type);
$type,
$pdf
);
break;
case 'group_configuration':
$report['contents'][] = reporting_group_configuration(
@ -2702,13 +2712,12 @@ function reporting_group_configuration($report, $content) {
return reporting_check_structure_content($return);
}
function reporting_network_interfaces_report($report, $content, $type = 'dinamic') {
function reporting_network_interfaces_report($report, $content, $type = 'dinamic', $pdf = 0) {
global $config;
$return['type'] = 'network_interfaces_report';
if (empty($content['name'])) {
$content['name'] = __('Network interfaces report');
}
@ -2716,16 +2725,16 @@ function reporting_network_interfaces_report($report, $content, $type = 'dinamic
if (isset($content['style']['fullscale'])) {
$fullscale = (bool) $content['style']['fullscale'];
}
$group_name = groups_get_name($content['id_group']);
$return['title'] = $content['name'];
$return['subtitle'] = $group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
include_once($config['homedir'] . "/include/functions_custom_graphs.php");
$filter = array(
'id_grupo' => $content['id_group'],
'disabled' => 0);
@ -2744,7 +2753,15 @@ function reporting_network_interfaces_report($report, $content, $type = 'dinamic
}
else{
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
$return = agents_get_network_interfaces_array($network_interfaces_by_agents, $return, $type, $content, $report, $fullscale);
$return = agents_get_network_interfaces_array(
$network_interfaces_by_agents,
$return,
$type,
$content,
$report,
$fullscale,
$pdf
);
metaconsole_restore_db();
}
}
@ -2752,13 +2769,24 @@ function reporting_network_interfaces_report($report, $content, $type = 'dinamic
}
else{
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
$return = agents_get_network_interfaces_array($network_interfaces_by_agents, $return, $type, $content, $report, $fullscale);
$return = agents_get_network_interfaces_array(
$network_interfaces_by_agents,
$return,
$type,
$content,
$report,
$fullscale,
$pdf
);
}
return reporting_check_structure_content($return);
}
function agents_get_network_interfaces_array($network_interfaces_by_agents, $return, $type, $content, $report, $fullscale){
function agents_get_network_interfaces_array(
$network_interfaces_by_agents, $return,
$type, $content, $report, $fullscale, $pdf
){
if (empty($network_interfaces_by_agents)) {
$return['failed'] =
__('The group has no agents or none of the agents has any network interface');
@ -2777,7 +2805,9 @@ function agents_get_network_interfaces_array($network_interfaces_by_agents, $ret
$row_interface['status'] = $interface['status_image'];
$row_interface['chart'] = null;
//XXXX ancho y largo
// Get chart
/*
reporting_set_conf_charts($width, $height, $only_image,
$type, $content, $ttl);
@ -2788,64 +2818,47 @@ function agents_get_network_interfaces_array($network_interfaces_by_agents, $ret
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
*/
$width = null;
$height = null;
$params =array(
'period' => $content['period'],
'width' => $width,
'height' => $height,
'unit_name' => array_fill(0, count($interface['traffic']), __("bytes/s")),
'date' => $report["datetime"],
'only_image'=> $pdf,
'homeurl' => $config['homeurl'],
'fullscale' => $fullscale
);
$params_combined = array(
'labels' => array_keys($interface['traffic']),
'modules_series' => array_values($interface['traffic'])
);
switch ($type) {
case 'dinamic':
if (!empty($interface['traffic'])) {
$row_interface['chart'] = custom_graphs_print(0,
$height,
$width,
$content['period'],
null,
true,
$report["datetime"],
$only_image,
'white',
array_values($interface['traffic']),
$config['homeurl'],
array_keys($interface['traffic']),
array_fill(0, count($interface['traffic']), __("bytes/s")),
false,
true,
true,
true,
1,
false,
false,
null,
false,
false,
$fullscale);
}
break;
case 'data':
case 'static':
if (!empty($interface['traffic'])) {
$row_interface['chart'] = custom_graphs_print(0,
$height,
$width,
$content['period'],
null,
true,
$report["datetime"],
true,
'white',
$row_interface['chart'] = graphic_combined_module(
array_values($interface['traffic']),
$config['homeurl'],
array_keys($interface['traffic']),
array_fill(0, count($interface['traffic']), __("bytes/s")),
false,
true,
true,
true,
2,
false,
false,
null,
false,
false,
$fullscale);
}
$params,
$params_combined
);
}
break;
case 'data':
if (!empty($interface['traffic'])) {
$params['return_data'] = true;
$row_interface['chart'] = graphic_combined_module(
array_values($interface['traffic']),
$params,
$params_combined
);
}
break;
}
$row_data['interfaces'][] = $row_interface;
@ -3589,85 +3602,75 @@ function reporting_prediction_date($report, $content) {
function reporting_projection_graph($report, $content,
$type = 'dinamic', $force_width_chart = null,
$force_height_chart = null) {
$force_height_chart = null, $pdf = false) {
global $config;
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['type'] = 'projection_graph';
if (empty($content['name'])) {
$content['name'] = __('Projection Graph');
}
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_alias ($content['id_agent_module']));
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name . " - " . $module_name;
$module_name = io_safe_output(modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(modules_get_agentmodule_agent_alias ($content['id_agent_module']));
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name . " - " . $module_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['agent_name'] = $agent_name;
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
set_time_limit(500);
$output_projection = forecast_projection_graph(
$content['id_agent_module'], $content['period'], $content['top_n_value']);
// If projection doesn't have data then don't draw graph
if ($output_projection == NULL) {
$output_projection = false;
}
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
//reporting_set_conf_charts($width, $height, $only_image, $type,
// $content, $ttl);
//XXXX width y height
switch ($type) {
case 'dinamic':
case 'static':
$output_projection = forecast_projection_graph(
$content['id_agent_module'],
$content['period'],
$content['top_n_value']
);
// If projection doesn't have data then don't draw graph
if ($output_projection == NULL) {
$output_projection = false;
}
$params =array(
'period' => $content['period'],
'width' => $width,
'height' => $height,
'date' => $report["datetime"],
'unit' => '',
'only_image' => $pdf,
'homeurl' => ui_get_full_url(false, false, false, false) . '/',
'ttl' => $ttl
);
$params_combined = array(
'projection' => $output_projection
);
$return['chart'] = graphic_combined_module(
array($content['id_agent_module']),
array(),
$content['period'],
$width,
$height,
'',
'',
0,
0,
0,
0,
$report["datetime"],
$only_image,
ui_get_full_url(false, false, false, false) . '/',
$ttl,
// Important parameter, this tell to graphic_combined_module function that is a projection graph
$output_projection,
$content['top_n_value']
);
$params,
$params_combined
);
break;
case 'data':
$return['data'] = forecast_projection_graph(
@ -3677,11 +3680,11 @@ function reporting_projection_graph($report, $content,
false, false, true);
break;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
@ -6285,16 +6288,17 @@ function reporting_general($report, $content) {
}
function reporting_custom_graph($report, $content, $type = 'dinamic',
$force_width_chart = null, $force_height_chart = null, $type_report = "custom_graph") {
$force_width_chart = null, $force_height_chart = null,
$type_report = "custom_graph", $pdf = false) {
global $config;
require_once ($config["homedir"] . '/include/functions_graph.php');
$graph = db_get_row ("tgraph", "id_graph", $content['id_gs']);
$return = array();
$return['type'] = 'custom_graph';
if (empty($content['name'])) {
if ($type_report == "custom_graph") {
$content['name'] = __('Custom graph');
@ -6303,21 +6307,21 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
$content['name'] = __('Simple graph');
}
}
$return['title'] = $content['name'];
$return['subtitle'] = io_safe_output($graph['name']);
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text(
$report,
$content);
$graphs = db_get_all_rows_field_filter ("tgraph_source",
"id_graph", $content['id_gs']);
$modules = array ();
$weights = array ();
if ($graphs === false)
$graphs = array();
$labels = array();
foreach ($graphs as $graph_item) {
if ($type_report == 'automatic_graph') {
@ -6328,7 +6332,7 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
else {
array_push ($modules, $graph_item['id_agent_module']);
}
if (in_array('label',$content['style'])) {
if (defined('METACONSOLE')) {
$server_name = $content['server_name'];
@ -6346,7 +6350,7 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
'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;
@ -6358,19 +6362,21 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
array_push ($weights, $graph_item["weight"]);
}
if ($config['metaconsole'] && $type_report != 'automatic_graph') {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$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,
$content, $ttl);
//reporting_set_conf_charts($width, $height, $only_image, $type,
// $content, $ttl);
$width =null;
$height =null;
//height for bullet chart
/*
if($graph['stacked'] != 4){
$height += count($modules) * REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE;
}
@ -6379,50 +6385,44 @@ function reporting_custom_graph($report, $content, $type = 'dinamic',
$height = 50;
}
}
*/
switch ($type) {
case 'dinamic':
case 'static':
$params =array(
'period' => $content['period'],
'width' => $width,
'height' => $height,
'date' => $report["datetime"],
'only_image' => $pdf,
'homeurl' => ui_get_full_url(false, false, false, false),
'ttl' => $ttl,
'percentil' => $graph["percentil"],
'fullscale' => $graph["fullscale"],
);
$params_combined = array(
'weight_list' => $weights,
'stacked' => $graph["stacked"],
'labels' => $labels,
'summatory' => $graph["summatory_series"],
'average' => $graph["average_series"],
'modules_series' => $graph["modules_series"]
);
$return['chart'] = graphic_combined_module(
$modules,
$weights,
$content['period'],
$width, $height,
'',
'',
0,
0,
0,
$graph["stacked"],
$report["datetime"],
$only_image,
ui_get_full_url(false, false, false, false),
$ttl,
false,
false,
'white',
array(),
array(),
true,
true,
true,
true,
$labels,
false,
false,
$graph["percentil"],
false,
false,
$graph["fullscale"],
$graph["summatory_series"],
$graph["average_series"],
$graph["modules_series"]
$params,
$params_combined
);
break;
case 'data':
break;
}
if ($config['metaconsole'] && $type_report != 'automatic_graph') {
metaconsole_restore_db();
}

View File

@ -944,9 +944,9 @@ function visual_map_print_item($mode = "read", $layoutData,
continue;
}
}
$only_image = !$graph_javascript && $isExternalLink;
if ($layoutData['id_custom_graph'] != 0) {
// Show only avg on the visual console
if (get_parameter('action') == 'edit') {
@ -955,59 +955,54 @@ function visual_map_print_item($mode = "read", $layoutData,
}
else {
$img = '<img src="images/console/signes/custom_graph.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
}
}
else {
if ($width == 0 || $height == 0) {
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], 180, 480,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
elseif ($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], 180, 480,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else {
$img = custom_graphs_print(
$layoutData['id_custom_graph'], 180, 480,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
}
if ($width == 0 ) {
$width = 180;
}
if($height == 0) {
$height = 480;
}
$params =array(
'period' => $period,
'width' => $width,
'height' => $height,
'title' => '',
'unit_name' => null,
'show_alerts' => false,
'only_image' => $only_image,
'vconsole' => true,
'backgroundColor' => $layoutData['image']
);
$params_combined = array(
'id_graph' => $layoutData['id_custom_graph']
);
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">'.
graphic_combined_module(
false,
$params,
$params_combined
).'</div>';
}
elseif ($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">'.
graphic_combined_module(
false,
$params,
$params_combined
).'</div>';
}
else {
if ($width < 480){
$img = '<div class="error">'._("Could not draw pie with labels contained inside canvas. Resize widget to 500px width minimum").'</div>';
}
else {
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
elseif($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else {
$img = custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
}
}
$img = graphic_combined_module(
false,
$params,
$params_combined
);
}
}
}
@ -1016,7 +1011,7 @@ function visual_map_print_item($mode = "read", $layoutData,
$homeurl = $config['homeurl'];
else
$homeurl = '';
if ( (get_parameter('action') == 'edit') || (get_parameter('operation') == 'edit_visualmap') ) {
if($width == 0 || $height == 0){
if ($layoutData['id_metaconsole'] != 0) {

View File

@ -1,16 +1,19 @@
var system = require('system');
if (system.args.length < 2 || system.args.length > 6) {
if (system.args.length < 3 || system.args.length > 9) {
phantom.exit(1);
}
var webPage = require('webpage');
var page = webPage.create();
var url = system.args[1];
var url_params = system.args[2];
var output_filename = system.args[3];
var _width = system.args[4];
var _height = system.args[5];
var type_graph_pdf = system.args[2];
var url_params = system.args[3];
var url_params_comb = system.args[4];
var url_module_list = system.args[5];
var output_filename = system.args[6];
var _width = system.args[7];
var _height = system.args[8];
if (!_width) {
_width = 750;
@ -20,13 +23,21 @@ if (!_height) {
_height = 350;
}
if(type_graph_pdf == 'combined'){
finish_url = url + "?" + "data=" + url_params +
"&data_combined=" + url_params_comb +
"&data_module_list=" + url_module_list +
"&type_graph_pdf=" + type_graph_pdf;
}
else{
finish_url = url + "?" + "data=" + url_params +
"&type_graph_pdf=" + type_graph_pdf;
}
page.viewportSize = { width: _width, height: _height };
//page.zoomFactor = 1.75;
//console.log("Pagina: " + url);
//console.log("parametros: " + url_params);
//console.log("Archivo salida: " + output_filename);
page.open(url + "?" + "data=" + url_params, function start(status) {
page.open(finish_url, function start(status) {
page.render(output_filename, {format: 'png'});
//var base64 = page.renderBase64('JPG');
//console.log(base64);

View File

@ -192,34 +192,34 @@ $interface_traffic_modules = array(
else
echo '<div style="margin-left: 50px; padding-top: 10px;">';
//XXXXXXX width and height
$height = 400;
$width = '90%';
custom_graphs_print(
0,
$height,
$width,
$period,
null,
false,
$date,
false,
'white',
$params =array(
'period' => $period,
'width' => $width,
'height' => $height,
'unit_name' => array_fill(0, count($interface_traffic_modules), $config["interface_unit"]),
'date' => $date,
'homeurl' => $config['homeurl'],
'percentil' => (($show_percentil)? $config['percentil'] : null),
'fullscale' => $fullscale
);
$params_combined = array(
'weight_list' => array(),
'projection' => false,
'labels' => array_keys($interface_traffic_modules),
'from_interface' => true,
'modules_series' => array_values($interface_traffic_modules),
'return' => 0
);
graphic_combined_module(
array_values($interface_traffic_modules),
$config['homeurl'],
array_keys($interface_traffic_modules),
array_fill(0, count($interface_traffic_modules), $config["interface_unit"]),
false,
true,
true,
true,
1,
false,
false,
(($show_percentil)? $config['percentil'] : null),
true,
false,
$fullscale
$params,
$params_combined
);
echo '</div>';

View File

@ -63,7 +63,7 @@ if ($delete_graph) {
if ($view_graph) {
$sql="SELECT * FROM tgraph_source WHERE id_graph = $id_graph";
$sources = db_get_all_rows_sql($sql);
$sql="SELECT * FROM tgraph WHERE id_graph = $id_graph";
$graph = db_get_row_sql($sql);
@ -71,7 +71,7 @@ if ($view_graph) {
$private = $graph["private"];
$width = $graph["width"];
$height = $graph["height"] + count($sources) * 10;
$zoom = (int) get_parameter ('zoom', 0);
//Increase the height to fix the leyend rise
if ($zoom > 0) {
@ -154,12 +154,12 @@ if ($view_graph) {
html_print_image("images/builder.png", true, array ("title" => __('Graph editor'))) .'</a>')
);
}
$options['view']['text'] = '<a href="index.php?sec=reporting&sec2=operation/reporting/graph_viewer&view_graph=1&id=' . $id_graph . '">' .
html_print_image("images/operation.png", true,
array ("title" => __('View graph'))) .'</a>';
$options['view']['active'] = true;
if ($config["pure"] == 0) {
$options['screen']['text'] = "<a href='$url&pure=1'>"
. html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode')))
@ -169,18 +169,44 @@ if ($view_graph) {
$options['screen']['text'] = "<a href='$url&pure=0'>"
. html_print_image ("images/normal_screen.png", true, array ("title" => __('Back to normal mode')))
. "</a>";
// In full screen, the manage options are not available
$options = array('view' => $options['view'], 'screen' => $options['screen']);
}
// Header
ui_print_page_header ($graph['name'],
"images/chart.png", false, "", false, $options);
$graph_return = custom_graphs_print($id_graph, $height, $width, $period, $stacked, true, $unixdate, false, 'white',
array(), '', array(), array(), true, true, true, true, 1, false, false, $percentil, false, false, $fullscale);
ui_print_page_header (
$graph['name'],
"images/chart.png",
false,
"",
false,
$options
);
//XXXX el width y height
$width = null;
$height = null;
$params =array(
'period' => $period,
'width' => $width,
'height' => $height,
'date' => $unixdate,
'percentil' => $percentil,
'fullscale' => $fullscale
);
$params_combined = array(
'stacked' => $stacked,
'id_graph' => $id_graph
);
$graph_return = graphic_combined_module(
false,
$params,
$params_combined
);
if ($graph_return){
echo "<table class='databox filters' cellpadding='0' cellspacing='0' width='100%'>";