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:
parent
dd7ebc8f0a
commit
8d46ff6ccf
|
@ -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>
|
||||
|
||||
* godmode/reporting/graph_builder.php: Fixed a problem
|
||||
|
|
|
@ -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) {
|
||||
|
||||
// Parse function parameters
|
||||
$start_date = $params['data'][0];
|
||||
$end_date = $params['data'][1];
|
||||
$filter = json_decode (base64_decode ($params['data'][2]), true);
|
||||
$unique_id = $params['data'][3];
|
||||
$aggregate = $params['data'][4];
|
||||
$max = $params['data'][5];
|
||||
$unit = $params['data'][6];
|
||||
$interval_length = $params['data'][2];
|
||||
$filter = json_decode (base64_decode ($params['data'][3]), true);
|
||||
$unique_id = $params['data'][4];
|
||||
$aggregate = $params['data'][5];
|
||||
$max = $params['data'][6];
|
||||
$unit = $params['data'][7];
|
||||
|
||||
// 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);
|
||||
return;
|
||||
|
|
|
@ -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",
|
||||
'url' => ui_get_full_url("/images/logo_vertical_water.png"));
|
||||
|
||||
return area_graph($flash_chart, $chart, $width, $height, $color, $legend,
|
||||
$long_index, "images/image_problem.opaque.png", "", $unit, $homeurl,
|
||||
return area_graph($flash_chart, $chart, $width, $height, array (), $sources,
|
||||
array (), "images/image_problem.opaque.png", "", $unit, $homeurl,
|
||||
$config['homedir'] . "/images/logo_vertical_water.png",
|
||||
$config['fontpath'], $config['font_size'], $unit, 2);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
|
||||
include_once($config['homedir'] . "/include/functions_users.php");
|
||||
include_once($config['homedir'] . "/include/functions_io.php");
|
||||
require_once($config['homedir'] . '/enterprise/include/pdf_translator.php');
|
||||
enterprise_include_once ($config['homedir'] . "/include/functions_io.php");
|
||||
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
|
||||
$nfdump_date_format = 'Y/m/d.H:i:s';
|
||||
|
@ -366,13 +367,13 @@ function netflow_is_net ($address) {
|
|||
* @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 $config;
|
||||
|
||||
// Requesting remote data
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -405,7 +406,7 @@ function netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggrega
|
|||
|
||||
// Load 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) {
|
||||
|
||||
$last_timestamp++;
|
||||
|
@ -417,7 +418,7 @@ function netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggrega
|
|||
|
||||
// Parse data file
|
||||
// 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);
|
||||
}
|
||||
|
@ -533,7 +534,7 @@ function netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $conn
|
|||
// Parse data file
|
||||
// We must parse from $start_date to avoid creating new intervals!
|
||||
$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);
|
||||
|
||||
return $values;
|
||||
|
@ -675,7 +676,7 @@ function netflow_get_filter_arguments ($filter) {
|
|||
* @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;
|
||||
|
||||
// Last timestamp read
|
||||
|
@ -688,7 +689,7 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
|
|||
}
|
||||
|
||||
// Calculate the number of intervals
|
||||
if ($interval_length > 0) {
|
||||
if ($interval_length <= 0) {
|
||||
$num_intervals = $config['graph_res'] * 50;
|
||||
$period = $end_date - $start_date;
|
||||
$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 start_date Period start 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.
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
// Open cache file
|
||||
|
@ -902,9 +904,14 @@ function netflow_load_cache (&$data, $cache_file, $start_date, $end_date, $aggre
|
|||
$cache_data = @unserialize ($cache_data);
|
||||
|
||||
// Calculate the number of intervals
|
||||
$num_intervals = $config['graph_res'] * 50;
|
||||
$period = $end_date - $start_date;
|
||||
$interval_length = (int) ($period / $num_intervals);
|
||||
if ($interval_length <= 0) {
|
||||
$num_intervals = $config['graph_res'] * 50;
|
||||
$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;
|
||||
|
||||
// Initializa chart data
|
||||
|
@ -1004,6 +1011,7 @@ function netflow_get_valid_intervals () {
|
|||
*
|
||||
* @param string start_date Period start 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 array filter Netflow filter.
|
||||
* @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.
|
||||
*/
|
||||
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'];
|
||||
$unit = $filter['output'];
|
||||
$interval = $end_date - $start_date;
|
||||
|
@ -1020,7 +1028,7 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggrega
|
|||
// Process item
|
||||
switch ($type) {
|
||||
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 ($output == 'HTML') {
|
||||
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;
|
||||
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') {
|
||||
return netflow_data_table ($data, $start_date, $end_date, $aggregate);
|
||||
} 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 string end_date Period start 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
|
||||
$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
|
||||
$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";
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ if ($draw != '') {
|
|||
$unique_id = 'live_view__' . ($end_date - $start_date);
|
||||
|
||||
// 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);
|
||||
}
|
||||
?>
|
||||
|
||||
|
|
|
@ -70,23 +70,25 @@ if ($id) {
|
|||
}
|
||||
|
||||
$period = get_parameter('period', '86400');
|
||||
$date = get_parameter_post ('date', date ("Y/m/d", get_system_time ()));
|
||||
$time = get_parameter_post ('time', date ("H:i:s", get_system_time ()));
|
||||
$date = get_parameter ('date', date ("Y/m/d", get_system_time ()));
|
||||
$time = get_parameter ('time', date ("H:i:s", get_system_time ()));
|
||||
|
||||
$end_date = strtotime ($date . " " . $time);
|
||||
$start_date = $end_date - $period;
|
||||
|
||||
// Generate an XML report
|
||||
if (isset ($_GET["xml"])) {
|
||||
$interval_length = get_parameter('interval_length', 0);
|
||||
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;
|
||||
}
|
||||
// Generate a PDF report
|
||||
else if (isset ($_GET["pdf"])) {
|
||||
$interval_length = get_parameter('interval_length', 0);
|
||||
enterprise_include_once ('include/functions_netflow_pdf.php');
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -180,6 +182,6 @@ foreach ($report_contents as $content_report) {
|
|||
$unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date);
|
||||
|
||||
// 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');
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue