From e01f00ac3dbdc7c93f3f58ac47abe1f41ed6cea8 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 31 Oct 2017 11:51:19 +0100 Subject: [PATCH 1/5] code backup --- .../godmode/reporting/graph_builder.main.php | 13 +++++ .../godmode/reporting/graph_builder.php | 12 +++- .../include/functions_custom_graphs.php | 8 ++- pandora_console/include/functions_graph.php | 57 +++++++++++++++++-- .../include/graphs/functions_flot.php | 3 +- 5 files changed, 83 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_builder.main.php b/pandora_console/godmode/reporting/graph_builder.main.php index 9c95f2263b..53f8d47835 100644 --- a/pandora_console/godmode/reporting/graph_builder.main.php +++ b/pandora_console/godmode/reporting/graph_builder.main.php @@ -66,6 +66,8 @@ if ($edit_graph) { $height = $graphInTgraph['height']; $check = false; $percentil = $graphInTgraph['percentil']; + $summatory_series = $graphInTgraph['summatory_series']; + $average_series = $graphInTgraph['average_series']; if ($stacked == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD){ $stacked = CUSTOM_GRAPH_BULLET_CHART; @@ -84,6 +86,8 @@ else { $stacked = 4; $check = false; $percentil = 0; + $summatory_series = 0; + $average_series = 0; } @@ -174,6 +178,15 @@ echo ""; echo ""; +echo "".__('Add summatory series')."" . + ui_print_help_tip (__("This will add a synthetic series to the graph, + using all series to give a SUM or an average of all present series values + in each interval. This feature could be used instead synthetic modules + if you only want to see a graph"), true).""; +echo "" . html_print_checkbox ("summatory_series", 1, $summatory_series, true) . " +".__('Add average series').""; +echo "" . html_print_checkbox ("average_series", 1, $average_series, true) . ""; + echo "".__('Percentil').""; echo "" . html_print_checkbox ("percentil", 1, $percentil, true) . ""; diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 317f562e6f..0d4cdcc2f9 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -87,6 +87,8 @@ if ($add_graph) { $period = get_parameter_post ("period"); $threshold = get_parameter('threshold'); $percentil = get_parameter ("percentil", 0); + $summatory_series = get_parameter ("summatory_series", 0); + $average_series = get_parameter ("average_series", 0); if ($threshold == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD){ $stacked = $threshold; @@ -103,7 +105,9 @@ if ($add_graph) { 'private' => 0, 'id_group' => $idGroup, 'stacked' => $stacked, - 'percentil' => $percentil + 'percentil' => $percentil, + 'summatory_series' => $summatory_series, + 'average_series' => $average_series ); if (trim($name) != "") { @@ -131,6 +135,8 @@ if ($update_graph) { $period = get_parameter('period'); $stacked = get_parameter('stacked'); $percentil = get_parameter('percentil'); + $summatory_series = get_parameter ("summatory_series"); + $average_series = get_parameter ("average_series"); $alerts = get_parameter('alerts'); $threshold = get_parameter('threshold'); @@ -141,7 +147,9 @@ if ($update_graph) { if (trim($name) != "") { $success = db_process_sql_update('tgraph', - array('name' => $name, 'id_group' => $id_group, 'description' => $description, 'width' => $width, 'height' => $height, 'period' => $period, 'stacked' => $stacked, 'percentil' => $percentil ), + array('name' => $name, 'id_group' => $id_group, 'description' => $description, + 'width' => $width, 'height' => $height, 'period' => $period, 'stacked' => $stacked, + 'percentil' => $percentil, 'summatory_series' => $summatory_series, 'average_series' => $average_series), array('id_graph' => $id_graph)); if ($success !== false) db_pandora_audit("Report management", "Update graph #$id_graph"); diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index adf077ec6a..f61a7ee944 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -202,6 +202,10 @@ function custom_graphs_print($id_graph, $height, $width, $period, $sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph', $id_graph); + $series = db_get_all_rows_sql('SELECT summatory_series,average_series FROM tgraph WHERE id_graph = '.$id_graph); + $summatory = $series[0]['summatory_series']; + $average = $series[0]['average_series']; + $modules = array (); $weights = array (); $labels = array (); @@ -262,7 +266,9 @@ function custom_graphs_print($id_graph, $height, $width, $period, $percentil, $from_interface, $id_widget_dashboard, - $fullscale); + $fullscale, + $summatory, + $average); if ($return) return $output; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 88e67981e0..b17bd224e5 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1114,11 +1114,11 @@ function graphic_combined_module ($module_list, $weight_list, $period, $name_list = array(), $unit_list = array(), $show_last = true, $show_max = true, $show_min = true, $show_avg = true, $labels = array(), $dashboard = false, $vconsole = false, $percentil = null, $from_interface = false, - $id_widget_dashboard=false, $fullscale = false) { + $id_widget_dashboard=false, $fullscale = false, $summatory = 0, $average = 0) { global $config; global $graphic_type; - + if(!$fullscale){ $time_format_2 = ''; $temp_range = $period; @@ -1205,7 +1205,8 @@ function graphic_combined_module ($module_list, $weight_list, $period, $weight_list[$i] = 1; } } - + + $aux_array = array(); // Set data containers for ($i = 0; $i < $resolution; $i++) { $timestamp = $datelimit + ($interval * $i);/* @@ -1257,12 +1258,12 @@ function graphic_combined_module ($module_list, $weight_list, $period, // If its a projection graph, // first module will be data and second will be the projection + if ($projection != false && $i != 0) { if ($automatic_custom_graph_meta) $agent_module_id = $module_list[0]['module']; else $agent_module_id = $module_list[0]; - $id_module_type = modules_get_agentmodule_type ($agent_module_id); $module_type = modules_get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); @@ -1273,7 +1274,6 @@ function graphic_combined_module ($module_list, $weight_list, $period, else $agent_module_id = $module_list[$i]; - $id_module_type = modules_get_agentmodule_type ($agent_module_id); $module_type = modules_get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); @@ -1346,6 +1346,21 @@ function graphic_combined_module ($module_list, $weight_list, $period, continue; } + // if(empty($aux_array)){ + // foreach ($data as $key => $value) { + // $aux_array[$value['utimestamp']] = $value['datos']; + // } + // } else { + // foreach ($data as $key => $value) { + // if(array_key_exists($value['utimestamp'],$aux_array)){ + // $aux_array[$value['utimestamp']] = $aux_array[$value['utimestamp']] + $value['datos']; + // } else { + // $aux_array[$value['utimestamp']] = $value['datos']; + // } + // } + // } + + // html_debug($aux_array); if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) { if ($labels[$agent_module_id] != '') $module_name_list[$i] = $labels[$agent_module_id]; @@ -2114,7 +2129,37 @@ function graphic_combined_module ($module_list, $weight_list, $period, $threshold_data['red_inverse'] = (bool)$red_inverse; } } - + + //summatory and average series + if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE) { + if($summatory && $average){ + foreach ($graph_values as $key => $value) { + $cont = count($value); + $summ = array_sum($value); + array_push($value,$summ); + array_push($value,$summ/$cont); + $graph_values[$key] = $value; + } + array_push($module_name_list,'' . __('summatory'). ''); + array_push($module_name_list,'' . __('average'). ''); + + } elseif($summatory) { + foreach ($graph_values as $key => $value) { + array_push($value,array_sum($value)); + $graph_values[$key] = $value; + } + array_push($module_name_list,'' . __('summatory'). ''); + + } elseif($average) { + foreach ($graph_values as $key => $value) { + $summ = array_sum($value) / count($value); + array_push($value,$summ); + $graph_values[$key] = $value; + } + array_push($module_name_list,'' . __('average'). ''); + } + } + switch ($stacked) { case CUSTOM_GRAPH_AREA: return area_graph($flash_charts, $graph_values, $width, diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 75569c5922..54259ba6b0 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -185,7 +185,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, include_javascript_dependencies_flot_graph(); $menu = (int)$menu; - + html_debug($legend); // Get a unique identifier to graph $graph_id = uniqid('graph_'); @@ -500,6 +500,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $short_data = false; } + // Javascript code $return .= "'; ?> diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 0d4cdcc2f9..9a171e6cba 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -89,6 +89,7 @@ if ($add_graph) { $percentil = get_parameter ("percentil", 0); $summatory_series = get_parameter ("summatory_series", 0); $average_series = get_parameter ("average_series", 0); + $modules_series = get_parameter ("modules_series", 0); if ($threshold == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD){ $stacked = $threshold; @@ -107,7 +108,8 @@ if ($add_graph) { 'stacked' => $stacked, 'percentil' => $percentil, 'summatory_series' => $summatory_series, - 'average_series' => $average_series + 'average_series' => $average_series, + 'modules_series' => $modules_series ); if (trim($name) != "") { @@ -137,6 +139,7 @@ if ($update_graph) { $percentil = get_parameter('percentil'); $summatory_series = get_parameter ("summatory_series"); $average_series = get_parameter ("average_series"); + $modules_series = get_parameter ("modules_series"); $alerts = get_parameter('alerts'); $threshold = get_parameter('threshold'); @@ -149,7 +152,8 @@ if ($update_graph) { $success = db_process_sql_update('tgraph', array('name' => $name, 'id_group' => $id_group, 'description' => $description, 'width' => $width, 'height' => $height, 'period' => $period, 'stacked' => $stacked, - 'percentil' => $percentil, 'summatory_series' => $summatory_series, 'average_series' => $average_series), + 'percentil' => $percentil, 'summatory_series' => $summatory_series, + 'average_series' => $average_series, 'modules_series' => $modules_series), array('id_graph' => $id_graph)); if ($success !== false) db_pandora_audit("Report management", "Update graph #$id_graph"); diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index f61a7ee944..d037e773e7 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -202,9 +202,10 @@ function custom_graphs_print($id_graph, $height, $width, $period, $sources = db_get_all_rows_field_filter('tgraph_source', 'id_graph', $id_graph); - $series = db_get_all_rows_sql('SELECT summatory_series,average_series FROM tgraph WHERE 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 (); @@ -268,7 +269,8 @@ function custom_graphs_print($id_graph, $height, $width, $period, $id_widget_dashboard, $fullscale, $summatory, - $average); + $average, + $modules_series); if ($return) return $output; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index b17bd224e5..26dfe0a45f 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1114,7 +1114,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $name_list = array(), $unit_list = array(), $show_last = true, $show_max = true, $show_min = true, $show_avg = true, $labels = array(), $dashboard = false, $vconsole = false, $percentil = null, $from_interface = false, - $id_widget_dashboard=false, $fullscale = false, $summatory = 0, $average = 0) { + $id_widget_dashboard=false, $fullscale = false, $summatory = 0, $average = 0, $modules_series = 0) { global $config; global $graphic_type; @@ -2131,7 +2131,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, } //summatory and average series - if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE) { + if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE && $modules_series) { if($summatory && $average){ foreach ($graph_values as $key => $value) { $cont = count($value); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 2ebd99bd6f..efd3183810 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1192,6 +1192,7 @@ CREATE TABLE IF NOT EXISTS `tgraph` ( `percentil` tinyint(1) UNSIGNED NOT NULL default 0, `summatory_series` tinyint(1) UNSIGNED NOT NULL default 0, `average_series` tinyint(1) UNSIGNED NOT NULL default 0, + `modules_series` tinyint(1) UNSIGNED NOT NULL default 0, PRIMARY KEY(`id_graph`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; From 1d3efb9d9ebfd7cd61446e505d8bcc3f18fc5b02 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Mon, 11 Dec 2017 09:29:24 +0100 Subject: [PATCH 3/5] Updated functions_graph --- pandora_console/include/functions_graph.php | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 26dfe0a45f..431a248ed4 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2131,32 +2131,50 @@ function graphic_combined_module ($module_list, $weight_list, $period, } //summatory and average series - if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE && $modules_series) { - if($summatory && $average){ + if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE) { + if($summatory && $average) { foreach ($graph_values as $key => $value) { $cont = count($value); $summ = array_sum($value); array_push($value,$summ); array_push($value,$summ/$cont); $graph_values[$key] = $value; + if(!$modules_series) { + array_splice($graph_values[$key],0,count($graph_values[$key])-2); + } } array_push($module_name_list,'' . __('summatory'). ''); array_push($module_name_list,'' . __('average'). ''); + if(!$modules_series){ + array_splice($module_name_list,0,count($module_name_list)-2); + } } elseif($summatory) { foreach ($graph_values as $key => $value) { array_push($value,array_sum($value)); $graph_values[$key] = $value; + if(!$modules_series){ + array_splice($graph_values[$key],0,count($graph_values[$key])-1); + } } array_push($module_name_list,'' . __('summatory'). ''); + if(!$modules_series){ + array_splice($module_name_list,0,count($module_name_list)-1); + } } elseif($average) { foreach ($graph_values as $key => $value) { $summ = array_sum($value) / count($value); array_push($value,$summ); $graph_values[$key] = $value; + if(!$modules_series){ + array_splice($graph_values[$key],0,count($graph_values[$key])-1); + } } array_push($module_name_list,'' . __('average'). ''); + if(!$modules_series){ + array_splice($module_name_list,0,count($module_name_list)-1); + } } } From 85ac142c6ca68be3c2ac800db33e547c0d367fb1 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Wed, 13 Dec 2017 10:23:00 +0100 Subject: [PATCH 4/5] Updated functions_graph and fixed percentil issue --- pandora_console/include/functions_graph.php | 56 +++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 431a248ed4..76df8957cf 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2143,10 +2143,24 @@ function graphic_combined_module ($module_list, $weight_list, $period, array_splice($graph_values[$key],0,count($graph_values[$key])-2); } } - array_push($module_name_list,'' . __('summatory'). ''); - array_push($module_name_list,'' . __('average'). ''); - if(!$modules_series){ - array_splice($module_name_list,0,count($module_name_list)-2); + + if(!$modules_series) { + if(is_null($percentil)) { + array_splice($module_name_list,0,count($module_name_list)); + } else { + array_splice($module_name_list,0,count($module_name_list)-(count($module_name_list)/2)); + } + array_unshift($module_name_list,'' . __('summatory'). ''); + array_unshift($module_name_list,'' . __('average'). ''); + } else { + if(is_null($percentil)) { + array_push($module_name_list,'' . __('summatory'). ''); + array_push($module_name_list,'' . __('average'). ''); + } else { + array_splice($module_name_list,(count($module_name_list)/2),0,'' . __('average'). ''); + array_splice($module_name_list,(count($module_name_list)/2),0,'' . __('summatory'). ''); + } + } } elseif($summatory) { @@ -2157,9 +2171,20 @@ function graphic_combined_module ($module_list, $weight_list, $period, array_splice($graph_values[$key],0,count($graph_values[$key])-1); } } - array_push($module_name_list,'' . __('summatory'). ''); - if(!$modules_series){ - array_splice($module_name_list,0,count($module_name_list)-1); + + if(!$modules_series) { + if(is_null($percentil)) { + array_splice($module_name_list,0,count($module_name_list)); + } else { + array_splice($module_name_list,0,count($module_name_list)-(count($module_name_list)/2)); + } + array_unshift($module_name_list,'' . __('summatory'). ''); + } else { + if(is_null($percentil)) { + array_push($module_name_list,'' . __('summatory'). ''); + } else { + array_splice($module_name_list,(count($module_name_list)/2),0,'' . __('summatory'). ''); + } } } elseif($average) { @@ -2171,9 +2196,20 @@ function graphic_combined_module ($module_list, $weight_list, $period, array_splice($graph_values[$key],0,count($graph_values[$key])-1); } } - array_push($module_name_list,'' . __('average'). ''); - if(!$modules_series){ - array_splice($module_name_list,0,count($module_name_list)-1); + + if(!$modules_series) { + if(is_null($percentil)) { + array_splice($module_name_list,0,count($module_name_list)); + } else { + array_splice($module_name_list,0,count($module_name_list)-(count($module_name_list)/2)); + } + array_unshift($module_name_list,'' . __('average'). ''); + } else { + if(is_null($percentil)) { + array_push($module_name_list,'' . __('average'). ''); + } else { + array_splice($module_name_list,(count($module_name_list)/2),0,'' . __('average'). ''); + } } } } From 43e697a1cbaab1225c0d2744f1e10c2cc5aa8b27 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Wed, 13 Dec 2017 11:50:15 +0100 Subject: [PATCH 5/5] Added hint in field Add summatory series --- pandora_console/extras/mr/10.sql | 4 ++++ .../godmode/reporting/graph_builder.main.php | 12 ++++++------ pandora_console/include/ajax/snmp.ajax.php | 1 - pandora_console/include/graphs/functions_flot.php | 1 - 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pandora_console/extras/mr/10.sql b/pandora_console/extras/mr/10.sql index 2b58ce08c4..3333da3157 100644 --- a/pandora_console/extras/mr/10.sql +++ b/pandora_console/extras/mr/10.sql @@ -4,4 +4,8 @@ ALTER TABLE tsnmp_filter ADD unified_filters_id int(10) NOT NULL DEFAULT 0; ALTER TABLE treport_content_template ADD COLUMN hide_no_data tinyint(1) DEFAULT 0; ALTER TABLE tgraph_source ADD COLUMN `order` int(10) NOT NULL default 0; +ALTER TABLE tgraph ADD COLUMN `summatory_series` tinyint(1) UNSIGNED NOT NULL default '0'; +ALTER TABLE tgraph ADD COLUMN `average_series` tinyint(1) UNSIGNED NOT NULL default '0'; +ALTER TABLE tgraph ADD COLUMN `modules_series` tinyint(1) UNSIGNED NOT NULL default '0'; + COMMIT; \ No newline at end of file diff --git a/pandora_console/godmode/reporting/graph_builder.main.php b/pandora_console/godmode/reporting/graph_builder.main.php index 89a0917265..cb2c5f265c 100644 --- a/pandora_console/godmode/reporting/graph_builder.main.php +++ b/pandora_console/godmode/reporting/graph_builder.main.php @@ -180,18 +180,18 @@ echo ""; echo ""; -// echo "".__('Add summatory series')."" . -// ui_print_help_tip (__("This will add a synthetic series to the graph, -// using all series to give a SUM or an average of all present series values -// in each interval. This feature could be used instead synthetic modules -// if you only want to see a graph"), true).""; echo "".__('Percentil').""; echo "" . html_print_checkbox ("percentil", 1, $percentil, true) . ""; -echo "".__('Add summatory series').""; + +echo "".__('Add summatory series') . + ui_print_help_tip (__("Adds synthetic series to the graph, using all module + values to calculate the summation and/or average in each time interval. + This feature could be used instead of synthetic modules if you only want to see a graph."), true) . ""; echo "" . html_print_checkbox ("summatory_series", 1, $summatory_series, true) . " ".__('Add average series').""; echo "" . html_print_checkbox ("average_series", 1, $average_series, true) . ""; echo "".__('Modules and series').""; + echo "" . html_print_checkbox ("modules_series", 1, $modules_series, true) . ""; echo ""; diff --git a/pandora_console/include/ajax/snmp.ajax.php b/pandora_console/include/ajax/snmp.ajax.php index a372d50e11..29fefa026e 100644 --- a/pandora_console/include/ajax/snmp.ajax.php +++ b/pandora_console/include/ajax/snmp.ajax.php @@ -60,7 +60,6 @@ if ($update_snmp_translation) { if ($delete_snmp_filter) { $filter_id = get_parameter('filter_id'); -html_debug($filter_id, true); db_process_sql_delete('tsnmp_filter', array('id_snmp_filter' => $filter_id)); return; diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 54259ba6b0..897a11b093 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -185,7 +185,6 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, include_javascript_dependencies_flot_graph(); $menu = (int)$menu; - html_debug($legend); // Get a unique identifier to graph $graph_id = uniqid('graph_');