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

* 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.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7097 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2012-10-25 18:34:53 +00:00
parent e33cebbd8e
commit cf971e3762
8 changed files with 253 additions and 38 deletions

View File

@ -1,3 +1,14 @@
2012-10-25 Ramon Novoa <rnovoa@artica.es>
* 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 <miguel.dedios@artica.es> 2012-10-25 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_extensions.php, extensions/pandora_logs.php, * include/functions_extensions.php, extensions/pandora_logs.php,

View File

@ -78,6 +78,9 @@ $sla_sorted_by = 0;
$id_agents = ''; $id_agents = '';
$inventory_modules = array(); $inventory_modules = array();
$date = null; $date = null;
$netflow_filter = 0;
$max_values = 0;
$resolution = 0;
switch ($action) { switch ($action) {
case 'new': case 'new':
@ -345,6 +348,18 @@ switch ($action) {
case 'group_configuration': case 'group_configuration':
$group = $item['id_group']; $group = $item['id_group'];
break; 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 //Restore db connection
@ -386,6 +401,24 @@ html_print_input_hidden('id_item', $idItem);
?> ?>
</td> </td>
</tr> </tr>
<tr id="row_netflow_filter" style="" class="datos">
<td><?php echo __('Filter');?></td>
<td><?php
$own_info = get_user_info ($config['id_user']);
// Get group list that user has access
$groups_user = users_get_groups ($config['id_user'], "IW", $own_info['is_admin'], true);
$groups_id = array();
foreach($groups_user as $key => $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);
?>
</td>
</tr>
<tr id="row_description" style="" class="datos"> <tr id="row_description" style="" class="datos">
<td style="vertical-align: top;"><?php echo __('Description'); ?></td> <td style="vertical-align: top;"><?php echo __('Description'); ?></td>
<td style=""> <td style="">
@ -405,6 +438,17 @@ html_print_input_hidden('id_item', $idItem);
html_print_extended_select_for_time ('period', $period, '', '', '0', 10); html_print_extended_select_for_time ('period', $period, '', '', '0', 10);
?></td> ?></td>
</tr> </tr>
<tr id="row_resolution" style="" class="datos">
<td style="vertical-align: top;">
<?php
echo __('Resolution');
?>
</td>
<td style="">
<?php
html_print_extended_select_for_time ('resolution', $resolution, '', '', '0', 10);
?></td>
</tr>
<tr id="row_period1" style="" class="datos"> <tr id="row_period1" style="" class="datos">
<td style="vertical-align: top;"> <td style="vertical-align: top;">
<?php <?php
@ -736,6 +780,10 @@ html_print_input_hidden('id_item', $idItem);
<td style="vertical-align: top;"><?php echo __('Quantity (n)'); ?></td> <td style="vertical-align: top;"><?php echo __('Quantity (n)'); ?></td>
<td style=""><?php html_print_input_text('quantity', $top_n_value, '', 5, 5); ?></td> <td style=""><?php html_print_input_text('quantity', $top_n_value, '', 5, 5); ?></td>
</tr> </tr>
<tr id="row_max_values" style="" class="datos">
<td style="vertical-align: top;"><?php echo __('Max. values'); ?></td>
<td style=""><?php html_print_input_text('max_values', $max_values, '', 5, 5); ?></td>
</tr>
<tr id="row_max_min_avg" style="" class="datos"> <tr id="row_max_min_avg" style="" class="datos">
<td><?php echo __('Display');?></td> <td><?php echo __('Display');?></td>
<td> <td>
@ -1513,6 +1561,9 @@ function chooseType() {
$("#row_date").hide(); $("#row_date").hide();
$("#row_agent_multi").hide(); $("#row_agent_multi").hide();
$("#row_module_multi").hide(); $("#row_module_multi").hide();
$("#row_netflow_filter").hide();
$("#row_max_values").hide();
$("#row_resolution").hide();
switch (type) { switch (type) {
case 'event_report_group': case 'event_report_group':
@ -1809,6 +1860,41 @@ function chooseType() {
case 'group_configuration': case 'group_configuration':
$("#row_group").show(); $("#row_group").show();
break; 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;
} }
} }
</script> </script>

View File

@ -815,6 +815,18 @@ switch ($action) {
$values['id_group'] = get_parameter('id_group'); $values['id_group'] = get_parameter('id_group');
$good_format = true; $good_format = true;
break; 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: default:
$values['period'] = get_parameter('period'); $values['period'] = get_parameter('period');
$values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0);

View File

@ -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 * @return bool true if all is ok, false if referer is not equal to current web page
*/ */
function check_referer() { //function check_referer() {
global $config; // global $config;
//
//If it is disabled the check referer security // //If it is disabled the check referer security
if (!$config["referer_security"]) // if (!$config["referer_security"])
return true; // return true;
//
$referer = ''; // $referer = '';
if (isset($_SERVER['HTTP_REFERER'])) { // if (isset($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER']; // $referer = $_SERVER['HTTP_REFERER'];
} // }
//
// If refresh is performed then dont't check referer // // If refresh is performed then dont't check referer
// This is done due to problems with HTTP_REFERER var when metarefresh is performed // // This is done due to problems with HTTP_REFERER var when metarefresh is performed
if ($config["refr"] > 0) // if ($config["refr"] > 0)
return true; // return true;
//
//Check if the referer have a port (for example when apache run in other port to 80) // //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) { // if (preg_match('/http(s?):\/\/.*:[0-9]*/', $referer) == 1) {
$url = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $config["homeurl"]; // $url = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $config["homeurl"];
} // }
else { // else {
$url = ui_get_full_url(); // $url = ui_get_full_url();
$url = preg_replace('/http(s?):\/\//','',$url); // $url = preg_replace('/http(s?):\/\//','',$url);
} // }
//
// Remove protocol from referer // // Remove protocol from referer
$referer = preg_replace('/http(s?):\/\//','',$referer); // $referer = preg_replace('/http(s?):\/\//','',$referer);
$referer = preg_replace('/\?.*/','',$referer); // $referer = preg_replace('/\?.*/','',$referer);
//
if (strpos($url, $referer) === 0) { // if (strpos($url, $referer) === 0) {
return true; // return true;
} // }
else { // else {
return false; // return false;
} // }
} //}
/** /**
* Cleans an object or an array and casts all values as integers * Cleans an object or an array and casts all values as integers

View File

@ -22,6 +22,7 @@ enterprise_include_once ($config['homedir'] . '/enterprise/include/pdf_translato
enterprise_include_once ($config['homedir'] . '/enterprise/include/functions_metaconsole.php'); enterprise_include_once ($config['homedir'] . '/enterprise/include/functions_metaconsole.php');
// Date format for nfdump // Date format for nfdump
global $nfdump_date_format;
$nfdump_date_format = 'Y/m/d.H:i:s'; $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); $end_date = date ($nfdump_date_format, $end_date);
$values = array(); $values = array();
$table->width = '50%'; $table->width = '50%';
$table->cellpadding = 0;
$table->cellspacing = 0;
$table->class = 'databox'; $table->class = 'databox';
$table->data = array(); $table->data = array();
$j = 0; $j = 0;
@ -273,6 +276,8 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
$values = array(); $values = array();
$table->size = array ('50%'); $table->size = array ('50%');
$table->class = 'databox'; $table->class = 'databox';
$table->cellpadding = 0;
$table->cellspacing = 0;
$table->data = array(); $table->data = array();
$table->head = array(); $table->head = array();
@ -317,6 +322,9 @@ function netflow_summary_table ($data) {
$values = array(); $values = array();
$table->size = array ('50%'); $table->size = array ('50%');
$table->border = 1;
$table->cellpadding = 0;
$table->cellspacing = 0;
$table->class = 'databox'; $table->class = 'databox';
$table->data = array(); $table->data = array();
@ -1028,6 +1036,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
// Process item // Process item
switch ($type) { switch ($type) {
case '0': case '0':
case 'netflow_area':
$data = netflow_get_data ($start_date, $end_date, $interval_length, $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') {
@ -1049,6 +1058,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
} }
break; break;
case '1': case '1':
case 'netflow_pie':
$data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name);
if ($output == 'HTML') { if ($output == 'HTML') {
return graph_netflow_aggregate_pie ($data, $aggregate); return graph_netflow_aggregate_pie ($data, $aggregate);
@ -1059,6 +1069,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
} }
break; break;
case '2': case '2':
case 'netflow_data':
$data = netflow_get_data ($start_date, $end_date, $interval_length, $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);
@ -1068,6 +1079,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
} }
break; break;
case '3': case '3':
case 'netflow_statistics':
$data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name);
if ($output == 'HTML' || $output == 'PDF') { if ($output == 'HTML' || $output == 'PDF') {
return netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); 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; break;
case '4': case '4':
case 'netflow_summary':
$data = netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $connection_name); $data = netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $connection_name);
if ($output == 'HTML' || $output == 'PDF') { if ($output == 'HTML' || $output == 'PDF') {
return netflow_summary_table ($data); return netflow_summary_table ($data);

View File

@ -35,6 +35,7 @@ enterprise_include_once ('include/functions_metaconsole.php');
enterprise_include_once ('include/functions_inventory.php'); enterprise_include_once ('include/functions_inventory.php');
include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_forecast.php");
include_once($config['homedir'] . "/include/functions_ui.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. * 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; 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] = '<h4>' . $description . ' (' . __($filter['aggregate']) . '/' . __($filter['output']) . ')</h4>';
}
else {
$table->data[0][0] = '<h4>' . $description . ' (' . __($filter['output']) . ')</h4>';
}
$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 //Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {

View File

@ -597,6 +597,17 @@ function reports_get_report_types ($template = false) {
$types['group_configuration'] = array('optgroup' => __('Configuration'), $types['group_configuration'] = array('optgroup' => __('Configuration'),
'name' => __('Group 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; return $types;
} }
?> ?>

View File

@ -16,6 +16,7 @@
include_once("include/functions_modules.php"); include_once("include/functions_modules.php");
include_once("include/functions_events.php"); include_once("include/functions_events.php");
include_once ('include/functions_groups.php'); include_once ('include/functions_groups.php');
include_once ('include/functions_netflow.php');
enterprise_include_once ('include/functions_metaconsole.php'); enterprise_include_once ('include/functions_metaconsole.php');
function xml_array ($array, $buffer_file = array()) { function xml_array ($array, $buffer_file = array()) {
@ -1497,6 +1498,46 @@ foreach ($contents as $content) {
/// ///
break; 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); xml_array ($data, $buffer_file);