2012-10-11 Ramon Novoa <rnovoa@artica.es>

* include/functions_graph.php,
	  include/functions_api.php,
	  include/functions_netflow.php,
	  operation/netflow/nf_live_view.php,
	  operation/netflow/nf_view.php: Small fixes to netflow reports.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7069 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2012-10-11 15:52:26 +00:00
parent dd7ebc8f0a
commit 8d46ff6ccf
6 changed files with 53 additions and 33 deletions

View File

@ -1,3 +1,11 @@
2012-10-11 Ramon Novoa <rnovoa@artica.es>
* include/functions_graph.php,
include/functions_api.php,
include/functions_netflow.php,
operation/netflow/nf_live_view.php,
operation/netflow/nf_view.php: Small fixes to netflow reports.
2012-10-11 Dario Rodriguez <dario.rodriguez@artica.es> 2012-10-11 Dario Rodriguez <dario.rodriguez@artica.es>
* godmode/reporting/graph_builder.php: Fixed a problem * godmode/reporting/graph_builder.php: Fixed a problem

View File

@ -5569,20 +5569,21 @@ function api_get_tactical_view($trash1, $trash2, $trash3, $returnType) {
} }
// http://localhost/pandora_console/include/api.php?op=get&op2=netflow_get_data&other=1348562410|1348648810|base64_encode(json_encode($filter))|_1_1234|none|50|bytes&other_mode=url_encode_separator_|&apipass=pandora&user=pandora&pass=pandora' // http://localhost/pandora_console/include/api.php?op=get&op2=netflow_get_data&other=1348562410|1348648810|0|base64_encode(json_encode($filter))|_1_1234|none|50|bytes&other_mode=url_encode_separator_|&apipass=pandora&user=pandora&pass=pandora'
function api_get_netflow_get_data ($discard_1, $discard_2, $params) { function api_get_netflow_get_data ($discard_1, $discard_2, $params) {
// Parse function parameters // Parse function parameters
$start_date = $params['data'][0]; $start_date = $params['data'][0];
$end_date = $params['data'][1]; $end_date = $params['data'][1];
$filter = json_decode (base64_decode ($params['data'][2]), true); $interval_length = $params['data'][2];
$unique_id = $params['data'][3]; $filter = json_decode (base64_decode ($params['data'][3]), true);
$aggregate = $params['data'][4]; $unique_id = $params['data'][4];
$max = $params['data'][5]; $aggregate = $params['data'][5];
$unit = $params['data'][6]; $max = $params['data'][6];
$unit = $params['data'][7];
// Get netflow data // Get netflow data
$data = netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max, $unit); $data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $unique_id, $aggregate, $max, $unit);
returnData('json', $data); returnData('json', $data);
return; return;

View File

@ -2723,8 +2723,8 @@ function graph_netflow_aggregate_area ($data, $period, $width, $height, $unit =
$water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", $water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("/images/logo_vertical_water.png")); 'url' => ui_get_full_url("/images/logo_vertical_water.png"));
return area_graph($flash_chart, $chart, $width, $height, $color, $legend, return area_graph($flash_chart, $chart, $width, $height, array (), $sources,
$long_index, "images/image_problem.opaque.png", "", $unit, $homeurl, array (), "images/image_problem.opaque.png", "", $unit, $homeurl,
$config['homedir'] . "/images/logo_vertical_water.png", $config['homedir'] . "/images/logo_vertical_water.png",
$config['fontpath'], $config['font_size'], $unit, 2); $config['fontpath'], $config['font_size'], $unit, 2);
} }

View File

@ -17,8 +17,9 @@
include_once($config['homedir'] . "/include/functions_users.php"); include_once($config['homedir'] . "/include/functions_users.php");
include_once($config['homedir'] . "/include/functions_io.php"); include_once($config['homedir'] . "/include/functions_io.php");
require_once($config['homedir'] . '/enterprise/include/pdf_translator.php'); include_once ($config['homedir'] . "/include/functions_io.php");
enterprise_include_once ($config['homedir'] . "/include/functions_io.php"); enterprise_include_once ($config['homedir'] . '/enterprise/include/pdf_translator.php');
enterprise_include_once ($config['homedir'] . '/enterprise/include/functions_metaconsole.php');
// Date format for nfdump // Date format for nfdump
$nfdump_date_format = 'Y/m/d.H:i:s'; $nfdump_date_format = 'Y/m/d.H:i:s';
@ -366,13 +367,13 @@ function netflow_is_net ($address) {
* @return An array with netflow stats. * @return An array with netflow stats.
* *
*/ */
function netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max, $unit, $connection_name = '') { function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $unique_id, $aggregate, $max, $unit, $connection_name = '') {
global $nfdump_date_format; global $nfdump_date_format;
global $config; global $config;
// Requesting remote data // Requesting remote data
if (defined ('METACONSOLE') && $connection_name != '') { if (defined ('METACONSOLE') && $connection_name != '') {
$data = metaconsole_call_remote_api ($connection_name, 'netflow_get_data', "$start_date|$end_date|" . base64_encode(json_encode($filter)) . "|$unique_id|$aggregate|$max|$unit"); $data = metaconsole_call_remote_api ($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|" . base64_encode(json_encode($filter)) . "|$unique_id|$aggregate|$max|$unit");
return json_decode ($data, true); return json_decode ($data, true);
} }
@ -405,7 +406,7 @@ function netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggrega
// Load cache // Load cache
$cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache'; $cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache';
$last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $aggregate); $last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $interval_length, $aggregate);
if ($last_timestamp < $end_date) { if ($last_timestamp < $end_date) {
$last_timestamp++; $last_timestamp++;
@ -417,7 +418,7 @@ function netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggrega
// Parse data file // Parse data file
// We must parse from $start_date to avoid creating new intervals! // We must parse from $start_date to avoid creating new intervals!
netflow_parse_file ($start_date, $end_date, $temp_file, $values, $aggregate, $unit); netflow_parse_file ($start_date, $end_date, $interval_length, $temp_file, $values, $aggregate, $unit);
unlink ($temp_file); unlink ($temp_file);
} }
@ -533,7 +534,7 @@ function netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $conn
// Parse data file // Parse data file
// We must parse from $start_date to avoid creating new intervals! // We must parse from $start_date to avoid creating new intervals!
$values = array (); $values = array ();
netflow_parse_file ($start_date, $end_date, $temp_file, $values); netflow_parse_file ($start_date, $end_date, 0, $temp_file, $values);
unlink ($temp_file); unlink ($temp_file);
return $values; return $values;
@ -675,7 +676,7 @@ function netflow_get_filter_arguments ($filter) {
* @return Timestamp of the last data read. * @return Timestamp of the last data read.
* *
*/ */
function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate = '', $unit = '', $interval_length = 0) { function netflow_parse_file ($start_date, $end_date, $interval_length, $file, &$values, $aggregate = '', $unit = '') {
global $config; global $config;
// Last timestamp read // Last timestamp read
@ -688,7 +689,7 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
} }
// Calculate the number of intervals // Calculate the number of intervals
if ($interval_length > 0) { if ($interval_length <= 0) {
$num_intervals = $config['graph_res'] * 50; $num_intervals = $config['graph_res'] * 50;
$period = $end_date - $start_date; $period = $end_date - $start_date;
$interval_length = (int) ($period / $num_intervals); $interval_length = (int) ($period / $num_intervals);
@ -890,11 +891,12 @@ function netflow_save_cache ($data, $cache_file) {
* @param string cache_file Cache file name. * @param string cache_file Cache file name.
* @param string start_date Period start date. * @param string start_date Period start date.
* @param string end_date Period end date. * @param string end_date Period end date.
* @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date).
* *
* @return Timestamp of the last data read from cache. * @return Timestamp of the last data read from cache.
* *
*/ */
function netflow_load_cache (&$data, $cache_file, $start_date, $end_date, $aggregate) { function netflow_load_cache (&$data, $cache_file, $start_date, $end_date, $interval_length, $aggregate) {
global $config; global $config;
// Open cache file // Open cache file
@ -902,9 +904,14 @@ function netflow_load_cache (&$data, $cache_file, $start_date, $end_date, $aggre
$cache_data = @unserialize ($cache_data); $cache_data = @unserialize ($cache_data);
// Calculate the number of intervals // Calculate the number of intervals
$num_intervals = $config['graph_res'] * 50; if ($interval_length <= 0) {
$period = $end_date - $start_date; $num_intervals = $config['graph_res'] * 50;
$interval_length = (int) ($period / $num_intervals); $period = $end_date - $start_date;
$interval_length = (int) ($period / $num_intervals);
} else {
$period = $end_date - $start_date;
$num_intervals = (int) ($period / $interval_length);
}
$last_timestamp = $start_date; $last_timestamp = $start_date;
// Initializa chart data // Initializa chart data
@ -1004,6 +1011,7 @@ function netflow_get_valid_intervals () {
* *
* @param string start_date Period start date. * @param string start_date Period start date.
* @param string end_date Period end date. * @param string end_date Period end date.
* @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date).
* @param string type Chart type. * @param string type Chart type.
* @param array filter Netflow filter. * @param array filter Netflow filter.
* @param int max_aggregates Maximum number of aggregates. * @param int max_aggregates Maximum number of aggregates.
@ -1012,7 +1020,7 @@ function netflow_get_valid_intervals () {
* *
* @return The netflow report in the appropriate format. * @return The netflow report in the appropriate format.
*/ */
function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name = '', $output = 'HTML', $only_image = false) { function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $unique_id, $connection_name = '', $output = 'HTML', $only_image = false) {
$aggregate = $filter['aggregate']; $aggregate = $filter['aggregate'];
$unit = $filter['output']; $unit = $filter['output'];
$interval = $end_date - $start_date; $interval = $end_date - $start_date;
@ -1020,7 +1028,7 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggrega
// Process item // Process item
switch ($type) { switch ($type) {
case '0': case '0':
$data = netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name); $data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name);
if ($aggregate != 'none') { if ($aggregate != 'none') {
if ($output == 'HTML') { if ($output == 'HTML') {
return graph_netflow_aggregate_area ($data, $interval, 660, 320, $unit); return graph_netflow_aggregate_area ($data, $interval, 660, 320, $unit);
@ -1051,7 +1059,7 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggrega
} }
break; break;
case '2': case '2':
$data = netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name); $data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name);
if ($output == 'HTML' || $output == 'PDF') { if ($output == 'HTML' || $output == 'PDF') {
return netflow_data_table ($data, $start_date, $end_date, $aggregate); return netflow_data_table ($data, $start_date, $end_date, $aggregate);
} else if ($output == 'XML') { } else if ($output == 'XML') {
@ -1089,9 +1097,10 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggrega
* @param int ID of the netflow report. * @param int ID of the netflow report.
* @param string end_date Period start date. * @param string end_date Period start date.
* @param string end_date Period end date. * @param string end_date Period end date.
* @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date).
* *
*/ */
function netflow_xml_report ($id, $start_date, $end_date) { function netflow_xml_report ($id, $start_date, $end_date, $interval_length = 0) {
// Get report data // Get report data
$report = db_get_row_sql ('SELECT * FROM tnetflow_report WHERE id_report =' . (int) $id); $report = db_get_row_sql ('SELECT * FROM tnetflow_report WHERE id_report =' . (int) $id);
@ -1143,7 +1152,7 @@ function netflow_xml_report ($id, $start_date, $end_date) {
// Build a unique id for the cache // Build a unique id for the cache
$unique_id = $report['id_report'] . '_' . $content['id_rc'] . '_' . ($end_date - $start_date); $unique_id = $report['id_report'] . '_' . $content['id_rc'] . '_' . ($end_date - $start_date);
echo netflow_draw_item ($start_date, $end_date, $content['show_graph'], $filter, $content['max'], $unique_id, $report['server_name'], 'XML'); echo netflow_draw_item ($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $unique_id, $report['server_name'], 'XML');
echo " </report_item>\n"; echo " </report_item>\n";
} }

View File

@ -253,7 +253,7 @@ if ($draw != '') {
$unique_id = 'live_view__' . ($end_date - $start_date); $unique_id = 'live_view__' . ($end_date - $start_date);
// Draw // Draw
echo netflow_draw_item ($start_date, $end_date, $chart_type, $filter, $max_aggregates, $unique_id, $connection_name); echo netflow_draw_item ($start_date, $end_date, 0, $chart_type, $filter, $max_aggregates, $unique_id, $connection_name);
} }
?> ?>

View File

@ -70,23 +70,25 @@ if ($id) {
} }
$period = get_parameter('period', '86400'); $period = get_parameter('period', '86400');
$date = get_parameter_post ('date', date ("Y/m/d", get_system_time ())); $date = get_parameter ('date', date ("Y/m/d", get_system_time ()));
$time = get_parameter_post ('time', date ("H:i:s", get_system_time ())); $time = get_parameter ('time', date ("H:i:s", get_system_time ()));
$end_date = strtotime ($date . " " . $time); $end_date = strtotime ($date . " " . $time);
$start_date = $end_date - $period; $start_date = $end_date - $period;
// Generate an XML report // Generate an XML report
if (isset ($_GET["xml"])) { if (isset ($_GET["xml"])) {
$interval_length = get_parameter('interval_length', 0);
header ('Content-type: application/xml; charset="utf-8"', true); header ('Content-type: application/xml; charset="utf-8"', true);
netflow_xml_report ($id, $start_date, $end_date); netflow_xml_report ($id, $start_date, $end_date, $interval_length);
return; return;
} }
// Generate a PDF report // Generate a PDF report
else if (isset ($_GET["pdf"])) { else if (isset ($_GET["pdf"])) {
$interval_length = get_parameter('interval_length', 0);
enterprise_include_once ('include/functions_netflow_pdf.php'); enterprise_include_once ('include/functions_netflow_pdf.php');
header ('Content-type: application/pdf', true); header ('Content-type: application/pdf', true);
netflow_pdf_report ($id, $start_date, $end_date); netflow_pdf_report ($id, $start_date, $end_date, $interval_length);
return; return;
} }
@ -180,6 +182,6 @@ foreach ($report_contents as $content_report) {
$unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); $unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date);
// Draw // Draw
echo netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name, 'HTML'); echo netflow_draw_item ($start_date, $end_date, 0, $type, $filter, $max_aggregates, $unique_id, $connection_name, 'HTML');
} }
?> ?>