diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8e907fa330..d9105c7c00 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2012-10-25 Ramon Novoa + + * include/functions_reporting.php, + include/functions_netflow.php, + include/functions.php, + include/functions_reports.php, + operation/reporting/reporting_xml.php, + godmode/reporting/reporting_builder.php, + godmode/reporting/reporting_builder.item_editor.php: Integrated + netflow reports into custom reports. + 2012-10-25 Miguel de Dios * include/functions_extensions.php, extensions/pandora_logs.php, diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 6667dbf9b5..e3fc6f5723 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -78,6 +78,9 @@ $sla_sorted_by = 0; $id_agents = ''; $inventory_modules = array(); $date = null; +$netflow_filter = 0; +$max_values = 0; +$resolution = 0; switch ($action) { case 'new': @@ -345,6 +348,18 @@ switch ($action) { case 'group_configuration': $group = $item['id_group']; break; + case 'netflow_area': + case 'netflow_pie': + case 'netflow_data': + case 'netflow_statistics': + case 'netflow_summary': + $netflow_filter = $item['text']; // Filter + $period = $item['period']; + $description = $item['description']; + $resolution = $item ['top_n']; // Interval resolution + $max_values = $item ['top_n_value']; // Max values + break; + } //Restore db connection @@ -386,6 +401,24 @@ html_print_input_hidden('id_item', $idItem); ?> + + + $groups){ + $groups_id[] = $groups['id_grupo']; + } + + $sql = "SELECT * FROM tnetflow_filter WHERE id_group IN (".implode(',',$groups_id).")"; + html_print_select_from_sql($sql, 'netflow_filter', $netflow_filter); + ?> + + @@ -405,6 +438,17 @@ html_print_input_hidden('id_item', $idItem); html_print_extended_select_for_time ('period', $period, '', '', '0', 10); ?> + + + + + + + + + + + @@ -1513,6 +1561,9 @@ function chooseType() { $("#row_date").hide(); $("#row_agent_multi").hide(); $("#row_module_multi").hide(); + $("#row_netflow_filter").hide(); + $("#row_max_values").hide(); + $("#row_resolution").hide(); switch (type) { case 'event_report_group': @@ -1809,6 +1860,41 @@ function chooseType() { case 'group_configuration': $("#row_group").show(); break; + case 'netflow_area': + $("#row_netflow_filter").show(); + $("#row_description").show(); + $("#row_period").show(); + $("#row_max_values").show(); + $("#row_resolution").show(); + break; + case 'netflow_pie': + $("#row_netflow_filter").show(); + $("#row_description").show(); + $("#row_period").show(); + $("#row_max_values").show(); + $("#row_resolution").show(); + break; + case 'netflow_data': + $("#row_netflow_filter").show(); + $("#row_description").show(); + $("#row_period").show(); + $("#row_max_values").show(); + $("#row_resolution").show(); + break; + case 'netflow_summary': + $("#row_netflow_filter").show(); + $("#row_description").show(); + $("#row_period").show(); + $("#row_max_values").show(); + $("#row_resolution").show(); + break; + case 'netflow_statistics': + $("#row_netflow_filter").show(); + $("#row_description").show(); + $("#row_period").show(); + $("#row_max_values").show(); + $("#row_resolution").show(); + break; } } diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 49d137c500..0663b1a8f0 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -815,6 +815,18 @@ switch ($action) { $values['id_group'] = get_parameter('id_group'); $good_format = true; break; + case 'netflow_area': + case 'netflow_pie': + case 'netflow_data': + case 'netflow_statistics': + case 'netflow_summary': + $values['text'] = get_parameter('netflow_filter'); + $values['description'] = get_parameter('description'); + $values['period'] = get_parameter('period'); + $values['top_n'] = get_parameter('resolution'); + $values['top_n_value'] = get_parameter('max_values'); + $good_format = true; + break; default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 1de5380218..c0da8f201e 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -30,43 +30,43 @@ require_once('functions_io.php'); * * @return bool true if all is ok, false if referer is not equal to current web page */ -function check_referer() { - global $config; - - //If it is disabled the check referer security - if (!$config["referer_security"]) - return true; - - $referer = ''; - if (isset($_SERVER['HTTP_REFERER'])) { - $referer = $_SERVER['HTTP_REFERER']; - } - - // If refresh is performed then dont't check referer - // This is done due to problems with HTTP_REFERER var when metarefresh is performed - if ($config["refr"] > 0) - return true; - - //Check if the referer have a port (for example when apache run in other port to 80) - if (preg_match('/http(s?):\/\/.*:[0-9]*/', $referer) == 1) { - $url = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $config["homeurl"]; - } - else { - $url = ui_get_full_url(); - $url = preg_replace('/http(s?):\/\//','',$url); - } - - // Remove protocol from referer - $referer = preg_replace('/http(s?):\/\//','',$referer); - $referer = preg_replace('/\?.*/','',$referer); - - if (strpos($url, $referer) === 0) { - return true; - } - else { - return false; - } -} +//function check_referer() { +// global $config; +// +// //If it is disabled the check referer security +// if (!$config["referer_security"]) +// return true; +// +// $referer = ''; +// if (isset($_SERVER['HTTP_REFERER'])) { +// $referer = $_SERVER['HTTP_REFERER']; +// } +// +// // If refresh is performed then dont't check referer +// // This is done due to problems with HTTP_REFERER var when metarefresh is performed +// if ($config["refr"] > 0) +// return true; +// +// //Check if the referer have a port (for example when apache run in other port to 80) +// if (preg_match('/http(s?):\/\/.*:[0-9]*/', $referer) == 1) { +// $url = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $config["homeurl"]; +// } +// else { +// $url = ui_get_full_url(); +// $url = preg_replace('/http(s?):\/\//','',$url); +// } +// +// // Remove protocol from referer +// $referer = preg_replace('/http(s?):\/\//','',$referer); +// $referer = preg_replace('/\?.*/','',$referer); +// +// if (strpos($url, $referer) === 0) { +// return true; +// } +// else { +// return false; +// } +//} /** * Cleans an object or an array and casts all values as integers @@ -1630,4 +1630,4 @@ function copy_dir($src, $dst) { } closedir($dir); } -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 91bf9ecce0..fa45bd491b 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -22,6 +22,7 @@ enterprise_include_once ($config['homedir'] . '/enterprise/include/pdf_translato enterprise_include_once ($config['homedir'] . '/enterprise/include/functions_metaconsole.php'); // Date format for nfdump +global $nfdump_date_format; $nfdump_date_format = 'Y/m/d.H:i:s'; /** @@ -208,6 +209,8 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){ $end_date = date ($nfdump_date_format, $end_date); $values = array(); $table->width = '50%'; + $table->cellpadding = 0; + $table->cellspacing = 0; $table->class = 'databox'; $table->data = array(); $j = 0; @@ -273,6 +276,8 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) { $values = array(); $table->size = array ('50%'); $table->class = 'databox'; + $table->cellpadding = 0; + $table->cellspacing = 0; $table->data = array(); $table->head = array(); @@ -317,6 +322,9 @@ function netflow_summary_table ($data) { $values = array(); $table->size = array ('50%'); + $table->border = 1; + $table->cellpadding = 0; + $table->cellspacing = 0; $table->class = 'databox'; $table->data = array(); @@ -1028,6 +1036,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi // Process item switch ($type) { case '0': + case 'netflow_area': $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') { @@ -1049,6 +1058,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } break; case '1': + case 'netflow_pie': $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); if ($output == 'HTML') { return graph_netflow_aggregate_pie ($data, $aggregate); @@ -1059,6 +1069,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } break; case '2': + case 'netflow_data': $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); @@ -1068,6 +1079,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } break; case '3': + case 'netflow_statistics': $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); if ($output == 'HTML' || $output == 'PDF') { return netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); @@ -1076,6 +1088,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi } break; case '4': + case 'netflow_summary': $data = netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $connection_name); if ($output == 'HTML' || $output == 'PDF') { return netflow_summary_table ($data); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ac3db3722d..2435a50bfa 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -35,6 +35,7 @@ enterprise_include_once ('include/functions_metaconsole.php'); enterprise_include_once ('include/functions_inventory.php'); include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); +include_once($config['homedir'] . "/include/functions_netflow.php"); /** * Get the average value of an agent module in a period of time. @@ -4742,6 +4743,46 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; + case 'netflow_area': + case 'netflow_pie': + case 'netflow_data': + case 'netflow_statistics': + case 'netflow_summary': + + // Read the report item + $report_id = $report['id_report']; + $content_id = $content['id_rc']; + $max_aggregates= $content['top_n_value']; + $type = $content['show_graph']; + $description = $content['description']; + $resolution = $content['top_n']; + $type = $content['type']; + $period = $content['period']; + + // Calculate the start and end dates + $end_date = $report['datetime']; + $start_date = $end_date - $period; + + // Get item filters + $filter = db_get_row_sql("SELECT * FROM tnetflow_filter WHERE id_sg = '" . (int)$content['text'] . "'", false, true); + if ($description == '') { + $description = $filter['id_name']; + } + + // Build a unique id for the cache + $unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); + + $table->colspan[0][0] = 4; + if ($filter['aggregate'] != 'none') { + $table->data[0][0] = '

' . $description . ' (' . __($filter['aggregate']) . '/' . __($filter['output']) . ')

'; + } + else { + $table->data[0][0] = '

' . $description . ' (' . __($filter['output']) . ')

'; + } + + $table->colspan[1][0] = 4; + $table->data[1][0] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $unique_id, '', 'HTML'); + break; } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 06c9056ca5..5dfeb541ec 100644 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -596,6 +596,17 @@ function reports_get_report_types ($template = false) { 'name' => __('Agent configuration')); $types['group_configuration'] = array('optgroup' => __('Configuration'), 'name' => __('Group configuration')); + + $types['netflow_area'] = array('optgroup' => __('Netflow'), + 'name' => __('Netflow area chart')); + $types['netflow_pie'] = array('optgroup' => __('Netflow'), + 'name' => __('Netflow pie chart')); + $types['netflow_data'] = array('optgroup' => __('Netflow'), + 'name' => __('Netflow data table')); + $types['netflow_statistics'] = array('optgroup' => __('Netflow'), + 'name' => __('Netflow statistics table')); + $types['netflow_summary'] = array('optgroup' => __('Netflow'), + 'name' => __('Netflow summary table')); return $types; } diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 861ea90d60..31d34ed252 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -16,6 +16,7 @@ include_once("include/functions_modules.php"); include_once("include/functions_events.php"); include_once ('include/functions_groups.php'); +include_once ('include/functions_netflow.php'); enterprise_include_once ('include/functions_metaconsole.php'); function xml_array ($array, $buffer_file = array()) { @@ -1497,6 +1498,46 @@ foreach ($contents as $content) { /// break; + case 'netflow_area': + case 'netflow_pie': + case 'netflow_data': + case 'netflow_statistics': + case 'netflow_summary': + + // Read the report item + $report_id = $report['id_report']; + $content_id = $content['id_rc']; + $max_aggregates= $content['top_n_value']; + $type = $content['show_graph']; + $description = io_safe_output ($content['description']); + $resolution = $content['top_n']; + $type = $content['type']; + $period = $content['period']; + + // Calculate the start and end dates + $end_date = $report['datetime']; + $start_date = $end_date - $period; + + // Get item filters + $filter = db_get_row_sql("SELECT * FROM tnetflow_filter WHERE id_sg = '" . (int)$content['text'] . "'", false, true); + if ($description == '') { + $description = io_safe_output ($filter['id_name']); + } + + // Build a unique id for the cache + $unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); + + $table->colspan[0][0] = 4; + if ($filter['aggregate'] != 'none') { + $data["title"] = $description . ' (' . __($filter['aggregate']) . '/' . __($filter['output']) . ')'; + } + else { + $data["title"] = $description . ' (' . __($filter['output']) . ')'; + } + + $data["objdata"]["netflow"] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $unique_id, '', 'XML'); + $buffer_file["objdata"] = $config['attachment_store'] . '/netflow_' . $time.'_'.$content['id_rc'] . '.tmp'; + break; } xml_array ($data, $buffer_file);