Netflow monitoring filters forms

This commit is contained in:
Calvo 2023-03-22 14:22:17 +01:00
parent 784bd2dbcf
commit 96017090ce
2 changed files with 119 additions and 33 deletions

View File

@ -109,6 +109,7 @@ if ($id) {
$traffic_max = $filter['traffic_max'];
$traffic_critical = $filter['traffic_critical'];
$traffic_warning = $filter['traffic_warning'];
$netflow_monitoring_interval = $filter['netflow_monitoring_interval'];
} else {
$name = '';
$assign_group = '';
@ -118,10 +119,11 @@ if ($id) {
$src_port = '';
$aggregate = 'dstip';
$advanced_filter = '';
$netflow_monitoring = 0;
$netflow_monitoring = false;
$traffic_max = 0;
$traffic_critical = 0;
$traffic_warning = 0;
$netflow_monitoring_interval = 300;
}
if ($update) {
@ -137,24 +139,27 @@ if ($update) {
$traffic_max = get_parameter('traffic_max', 0);
$traffic_critical = get_parameter('traffic_critical', 0);
$traffic_warning = get_parameter('traffic_warning', 0);
$netflow_monitoring_interval = get_parameter('netflow_monitoring_interval', 300);
if ($name == '') {
ui_print_error_message(__('Not updated. Blank name'));
} else {
$values = [
'id_sg' => $id,
'id_name' => $name,
'id_group' => $assign_group,
'aggregate' => $aggregate,
'ip_dst' => $ip_dst,
'ip_src' => $ip_src,
'dst_port' => $dst_port,
'src_port' => $src_port,
'advanced_filter' => $advanced_filter,
'netflow_monitoring' => $netflow_monitoring,
'traffic_max' => $traffic_max,
'traffic_critical' => $traffic_critical,
'traffic_warning' => $traffic_warning,
'id_sg' => $id,
'id_name' => $name,
'id_group' => $assign_group,
'aggregate' => $aggregate,
'ip_dst' => $ip_dst,
'ip_src' => $ip_src,
'dst_port' => $dst_port,
'src_port' => $src_port,
'advanced_filter' => $advanced_filter,
'netflow_monitoring' => $netflow_monitoring,
'traffic_max' => $traffic_max,
'traffic_critical' => $traffic_critical,
'traffic_warning' => $traffic_warning,
'netflow_monitoring_interval' => $netflow_monitoring_interval,
];
// Save filter args.
@ -183,16 +188,23 @@ if ($create) {
$traffic_max = get_parameter('traffic_max', 0);
$traffic_critical = get_parameter('traffic_critical', 0);
$traffic_warning = get_parameter('traffic_warning', 0);
$netflow_monitoring_interval = get_parameter('netflow_monitoring_interval', 300);
$values = [
'id_name' => $name,
'id_group' => $assign_group,
'ip_dst' => $ip_dst,
'ip_src' => $ip_src,
'dst_port' => $dst_port,
'src_port' => $src_port,
'aggregate' => $aggregate,
'advanced_filter' => $advanced_filter,
'id_name' => $name,
'id_group' => $assign_group,
'ip_dst' => $ip_dst,
'ip_src' => $ip_src,
'dst_port' => $dst_port,
'src_port' => $src_port,
'aggregate' => $aggregate,
'advanced_filter' => $advanced_filter,
'netflow_monitoring' => $netflow_monitoring,
'traffic_max' => $traffic_max,
'traffic_critical' => $traffic_critical,
'traffic_warning' => $traffic_warning,
'netflow_monitoring_interval' => $netflow_monitoring_interval,
];
// Save filter args
@ -234,6 +246,8 @@ $table->data['first_line'][] = html_print_label_input_block(
false,
20,
80,
true,
false,
true
)
);
@ -361,8 +375,8 @@ $table->data['advanced_filters'][] = html_print_label_input_block(
// Netflow server options.
$table->colspan['netflow_monitoring'][] = 1;
$table->data['netflow_server_filters'][] = html_print_label_input_block(
$table->colspan['netflow_monitoring'][] = 2;
$table->data['netflow_monitoring'][] = html_print_label_input_block(
__('Enable Netflow monitoring'),
html_print_checkbox_switch(
'netflow_monitoring',
@ -370,12 +384,25 @@ $table->data['netflow_server_filters'][] = html_print_label_input_block(
(bool) $netflow_monitoring,
true,
false,
'displayMonitoringFilter()'
).ui_print_input_placeholder(
__('Allows you to create an agent that monitors the traffic volume of this filter. It also creates a module that measures if the traffic of any IP of this filter exceeds a certain threshold. A text type module will be created with the traffic rate for each IP within this filter every five minutes (the 10 IP\'s with the most traffic). Only available for Enterprise version.'),
true
)
);
$table->data['netflow_server_filters'][] = html_print_label_input_block(
__('Netflow monitoring interval'),
html_print_input_number(
[
'step' => 1,
'name' => 'netflow_monitoring_interval',
'id' => 'netflow_monitoring_interval',
'value' => $netflow_monitoring_interval,
]
).ui_print_input_placeholder(__('Netflow monitoring interval in secs.'), true)
);
$table->data['netflow_server_filters'][] = html_print_label_input_block(
__('Maximum traffic value of the filter'),
html_print_input_number(
@ -389,11 +416,12 @@ $table->data['netflow_server_filters'][] = html_print_label_input_block(
);
$table->colspan['netflow_thresholds'][] = 1;
$table->data['netflow_thresholds'][] = html_print_label_input_block(
__('CRITICAL threshold for the maximum % of traffic for an IP.'),
html_print_input_number(
[
'step' => 0.1,
'step' => 0.01,
'name' => 'traffic_critical',
'id' => 'traffic_critical',
'value' => $traffic_critical,
@ -407,7 +435,7 @@ $table->data['netflow_thresholds'][] = html_print_label_input_block(
__('WARNING threshold for the maximum % of traffic for an IP.'),
html_print_input_number(
[
'step' => 0.1,
'step' => 0.01,
'name' => 'traffic_warning',
'id' => 'traffic_warning',
'value' => $traffic_warning,
@ -456,6 +484,7 @@ html_print_action_buttons(
else {
displayAdvancedFilter ();
}
displayMonitoringFilter();
});
function displayAdvancedFilter () {
@ -494,4 +523,24 @@ html_print_action_buttons(
document.getElementById("table1-6").style.display = '';
*/
};
function displayMonitoringFilter () {
var checked = $('#checkbox-netflow_monitoring').prop('checked');
if(checked == false) {
// Reset values.
$("#netflow_monitoring_interval").val(300);
$("#traffic_max").val(0);
$("#traffic_critical").val(0);
$("#traffic_warning").val(0);
// Hide filters.
$("#table1-netflow_server_filters").hide();
$("#table1-netflow_thresholds").hide();
} else {
// Show filters.
$("#table1-netflow_server_filters").show();
$("#table1-netflow_thresholds").show();
}
};
</script>

View File

@ -94,6 +94,7 @@ $filter['dst_port'] = get_parameter('dst_port', '');
$filter['src_port'] = get_parameter('src_port', '');
$filter['advanced_filter'] = get_parameter('advanced_filter', '');
$filter['netflow_monitoring'] = (bool) get_parameter('netflow_monitoring');
$filter['netflow_monitoring_interval'] = (int) get_parameter('netflow_monitoring_interval', 300);
$filter['traffic_max'] = get_parameter('traffic_max', 0);
$filter['traffic_critical'] = get_parameter('traffic_critical', 0);
$filter['traffic_warning'] = get_parameter('traffic_warning', 0);
@ -373,9 +374,21 @@ $advanced_toggle .= "<td style='font-weight:bold;'>".__('Enable Netflow monitori
$advanced_toggle .= '<td colspan="2">'.html_print_checkbox_switch(
'netflow_monitoring',
1,
(bool) $netflow_monitoring,
(bool) $filter['netflow_monitoring'],
true,
false,
'displayMonitoringFilter()',
).'</td>';
$advanced_toggle .= '<tr id="netlofw_monitoring_filters">';
$advanced_toggle .= "<td style='font-weight:bold;'>".__('Netflow monitoring interval').ui_print_help_tip(__('Netflow monitoring interval in secs.'), true).'</td>';
$advanced_toggle .= '<td colspan="2">'.html_print_input_number(
[
'step' => 1,
'name' => 'netflow_monitoring_interval',
'id' => 'netflow_monitoring_interval',
'value' => $filter['netflow_monitoring_interval'],
]
).'</td>';
$advanced_toggle .= "<td style='font-weight:bold;'>".__('Maximum traffic value of the filter').ui_print_help_tip(__('Specifies the maximum rate (in bytes/sec) of traffic in the filter. It is then used to calculate the % of maximum traffic per IP.'), true).'</td>';
@ -390,12 +403,12 @@ $advanced_toggle .= '<td colspan="2">'.html_print_input_number(
$advanced_toggle .= '</tr>';
$advanced_toggle .= '<tr>';
$advanced_toggle .= '<tr id="netlofw_monitoring_thresholds">';
$advanced_toggle .= "<td style='font-weight:bold;'>".__('CRITICAL threshold for the maximum % of traffic for an IP.').ui_print_help_tip(__('If this % is exceeded by any IP within the filter, a CRITICAL status will be generated.'), true).'</td>';
$advanced_toggle .= '<td colspan="2">'.html_print_input_number(
[
'step' => 1,
'step' => 0.01,
'name' => 'traffic_critical',
'id' => 'traffic_critical',
'value' => $filter['traffic_critical'],
@ -405,7 +418,7 @@ $advanced_toggle .= '<td colspan="2">'.html_print_input_number(
$advanced_toggle .= "<td style='font-weight:bold;'>".__('WARNING threshold for the maximum % of traffic of an IP.').ui_print_help_tip(__('If this % is exceeded by any IP within the filter, a WARNING status will be generated.'), true).'</td>';
$advanced_toggle .= '<td colspan="2">'.html_print_input_number(
[
'step' => 1,
'step' => 0.01,
'name' => 'traffic_warning',
'id' => 'traffic_warning',
'value' => $filter['traffic_warning'],
@ -766,6 +779,26 @@ ui_include_time_picker();
// Show the normal filter
$(".filter_normal").show();
};
function displayMonitoringFilter () {
var checked = $('#checkbox-netflow_monitoring').prop('checked');
if(checked == false) {
// Reset values.
$("#netflow_monitoring_interval").val(300);
$("#traffic_max").val(0);
$("#traffic_critical").val(0);
$("#traffic_warning").val(0);
// Hide filters.
$("#netlofw_monitoring_filters").hide();
$("#netlofw_monitoring_thresholds").hide();
} else {
// Show filters.
$("#netlofw_monitoring_filters").show();
$("#netlofw_monitoring_thresholds").show();
}
}
// Ask the user to define a name for the filter in order to save it
function defineFilterName () {
@ -789,7 +822,6 @@ ui_include_time_picker();
$("#filter_id").change(function () {
var filter_type;
// Hide information and name/group row
$(".filter_save").hide();
@ -811,6 +843,7 @@ ui_include_time_picker();
$("#traffic_max").val('');
$("#traffic_critical").val('');
$("#traffic_warning").val('');
$("#netflow_monitoring_interval").val(300);
$('#checkbox-netflow_monitoring').prop('checked', false);
@ -884,25 +917,29 @@ ui_include_time_picker();
$("#aggregate").val(val);
if (i == 'netflow_monitoring')
$("#checkbox-netflow_monitoring").prop('checked', val == "0" ? false : true);
// Hide or show monitoring filters.
displayMonitoringFilter();
if (i == 'netflow_monitoring_interval')
$("#netflow_monitoring_interval").val(val);
if (i == 'traffic_max')
$("#traffic_max").val(val);
if (i == 'traffic_critical')
$("#traffic_critical").val(val);
if (i == 'traffic_warning')
$("#traffic_warning").val(val);
});
}
<?php echo ', "json");'; ?>
// Shows update filter button
$("#submit-update_button").show();
}
});
$(document).ready( function() {
displayMonitoringFilter();
// Update visibility of controls.
nf_view_click_period();
// Hide update filter button