From e70f18bdf9bc1b68f8a4fcc429bdd26370838d91 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Mon, 5 Jan 2026 18:21:12 +0100 Subject: [PATCH] fix(luci-app-secubox-netifyd): Fix empty metrics in dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed critical bug in get_top_applications() and get_top_protocols() RPC methods where data was extracted with jq but never added to the JSON output. The functions were using jshn arrays but only echoing data instead of adding it to the array. Changes: - Rewrote get_top_applications() to output complete JSON via jq - Rewrote get_top_protocols() to output complete JSON via jq - Removed broken jshn array manipulation - Added proper fallback to empty arrays when no data available This fixes the "metrics vides" (empty metrics) issue in LuCI dashboard. The dashboard will now properly display: - Top applications with traffic stats - Top protocols with bandwidth usage - Flow counts and bytes transferred 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../usr/libexec/rpcd/luci.secubox-netifyd | 75 +++++++++---------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/package/secubox/luci-app-secubox-netifyd/root/usr/libexec/rpcd/luci.secubox-netifyd b/package/secubox/luci-app-secubox-netifyd/root/usr/libexec/rpcd/luci.secubox-netifyd index 73670cc7..471867ee 100755 --- a/package/secubox/luci-app-secubox-netifyd/root/usr/libexec/rpcd/luci.secubox-netifyd +++ b/package/secubox/luci-app-secubox-netifyd/root/usr/libexec/rpcd/luci.secubox-netifyd @@ -273,10 +273,9 @@ get_flow_statistics() { # Get top applications get_top_applications() { - json_init - json_add_array "applications" - if ! check_netifyd_running; then + json_init + json_add_array "applications" json_close_array json_add_boolean "error" 1 json_add_string "message" "Netifyd is not running" @@ -296,33 +295,30 @@ get_top_applications() { local jq_query='.flows[]?' echo "$source_file" | grep -q "status.json" || jq_query='.[]' - # Extract application names and aggregate bytes - jq -r "[$jq_query] | - group_by(.application // \"Unknown\") | - map({ - name: .[0].application // \"Unknown\", - flows: length, - bytes: map(.bytes_orig // 0 | tonumber) | add, - packets: map(.packets_orig // 0 | tonumber) | add - }) | - sort_by(-.bytes) | - limit($limit; .[]) - " "$source_file" 2>/dev/null | while read -r app; do - echo "$app" - done + # Extract application names and aggregate bytes - output complete JSON + jq -c "{ + applications: ([$jq_query] | + group_by(.application // \"Unknown\") | + map({ + name: .[0].application // \"Unknown\", + flows: length, + bytes: (map(.bytes_orig // 0 | tonumber) | add), + packets: (map(.packets_orig // 0 | tonumber) | add) + }) | + sort_by(-.bytes) | + limit($limit; .[])), + timestamp: now | floor + }" "$source_file" 2>/dev/null || echo '{"applications":[],"timestamp":0}' + else + echo '{"applications":[],"timestamp":0}' fi - - json_close_array - json_add_int "timestamp" "$(date +%s)" - json_dump } # Get top protocols get_top_protocols() { - json_init - json_add_array "protocols" - if ! check_netifyd_running; then + json_init + json_add_array "protocols" json_close_array json_add_boolean "error" 1 json_add_string "message" "Netifyd is not running" @@ -341,23 +337,22 @@ get_top_protocols() { local jq_query='.flows[]?' echo "$source_file" | grep -q "status.json" || jq_query='.[]' - jq -r "[$jq_query] | - group_by(.protocol // \"Unknown\") | - map({ - name: .[0].protocol // \"Unknown\", - flows: length, - bytes: map(.bytes_orig // 0 | tonumber) | add - }) | - sort_by(-.bytes) | - limit($limit; .[]) - " "$source_file" 2>/dev/null | while read -r proto; do - echo "$proto" - done + # Extract protocols and aggregate bytes - output complete JSON + jq -c "{ + protocols: ([$jq_query] | + group_by(.protocol // \"Unknown\") | + map({ + name: .[0].protocol // \"Unknown\", + flows: length, + bytes: (map(.bytes_orig // 0 | tonumber) | add) + }) | + sort_by(-.bytes) | + limit($limit; .[])), + timestamp: now | floor + }" "$source_file" 2>/dev/null || echo '{"protocols":[],"timestamp":0}' + else + echo '{"protocols":[],"timestamp":0}' fi - - json_close_array - json_add_int "timestamp" "$(date +%s)" - json_dump } # Get detected devices