Data Processing Failure - Always Returns CSV Format
davinunes opened this issue · 1 comments
Description:
When clicking the "Process" button, the data is not being processed correctly. Regardless of the selected output format or any other parameters, the response always comes back in CSV format.
Steps to Reproduce:
Go to the relevant page or section where the "Process" button is located.
Fill in the necessary filters and options.
Click on the "Process" button.
Observe that the data returned is always in CSV format, even if a different format was selected.
Expected Behavior:
The application should process the data according to the selected output format and return the data in the specified format (e.g., JSON).
Actual Behavior:
The response is always in CSV format, irrespective of the format option selected or any other parameters provided.
Additional Information:
The issue appears to be with the processing logic or configuration as it does not honor the format selection.
The problem persists across different filters and settings, leading to incorrect data handling and display.
I solve this:
line 999 nfsen-ng.js:
/**
* Parses the provided data, converts it into a better suitable format and populates an HTML table
* @param data
* @param status
* @returns boolean
*/
function render_table(data, status) {
if (status !== 'success') {
setButtonLoading($('#filterCommands').find('.submit'), false);
return false;
}
footable_data = data;
// Print nfdump command
if (typeof data[0] === 'string') {
display_message('success', '<b>nfdump command:</b> ' + data[0].toString());
}
// Return if invalid data got returned
if (typeof data[1] !== 'string' || typeof data[2] !== 'string') {
display_message('warning', '<b>Something went wrong.</b> ' + data[1].toString());
return false;
}
// Generate table header
var tempcolumns = data[1].split(','),
columns = [];
// Generate column definitions
$.each(tempcolumns, function (i, val) {
// Todo optimize breakpoints
var title = (val === 'val') ? api_statistics_options.title : nfdump_translation[val] || val,
column = {
name: val,
title: title,
type: 'text',
breakpoints: 'xs sm'
};
// Add formatter for IP addresses
if (['srcAddr', 'dstAddr'].indexOf(val) !== -1) {
column['formatter'] = (ip) => "<a href='#' onclick='return ip_link_handler(this)'>" + ip + "</a>";
}
// Todo add date formatter for timestamps
if (['firstSeen', 'lastSeen'].indexOf(val) !== -1) {
column['type'] = 'date';
column['breakpoints'] = '';
}
// Add formatter for bytes
if (['bytes', 'inBytes', 'outBytes'].indexOf(val) !== -1) {
column['type'] = 'number';
column['formatter'] = (x) => filesize(x, {base: 10});
}
// Add formatter for big numbers
if (['packets', 'flows'].indexOf(val) !== -1) {
column['type'] = 'number';
column['formatter'] = numberWithCommas;
}
// Define rest of numbers
if (['srcPort', 'dstPort'].indexOf(val) !== -1) {
column['type'] = 'number';
}
// IP addresses, protocol, value should not be hidden on small screens
if (['srcAddr', 'dstAddr', 'proto'].indexOf(val) !== -1) {
column['breakpoints'] = '';
}
// Least important columns should be hidden on small screens
if (['flags', 'tos', 'inIf', 'outIf'].indexOf(val) !== -1) {
column['breakpoints'] = 'all';
}
// Add column to columns array
columns.push(column);
});
// Generate table data
var temprows = data.slice(2),
rows = [];
$.each(temprows, function (i, val) {
var row = {id: i},
colData = val.split(',');
$.each(colData, function (j, col) {
row[tempcolumns[j]] = col;
});
rows.push(row);
});
// Init FooTable
$('table.table:visible').footable({
columns: columns,
rows: rows
});
if (rows.length > 0) {
$('table.table:visible .footable-empty').remove();
}
// Remove errors (except success)
$('#error').find('div.alert:not(.alert-success)').fadeOut(1500, function () {
$(this).remove();
});
// Reset button label
setButtonLoading($('#filterCommands').find('.submit'), false);
}