Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Processing Failure - Always Returns CSV Format #109

Open
davinunes opened this issue Jul 27, 2024 · 1 comment
Open

Data Processing Failure - Always Returns CSV Format #109

davinunes opened this issue Jul 27, 2024 · 1 comment
Assignees

Comments

@davinunes
Copy link

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.

image

@mbolli mbolli self-assigned this Jul 29, 2024
@davinunes
Copy link
Author

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants