From 9f2ad523b58e580c0fe90db03092d748e2ce23ec Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 22 Mar 2023 14:42:46 +0100 Subject: [PATCH] Reporting/Health - sort interfaces by description. closes https://github.com/opnsense/core/issues/6434 As we rather don't want to change the api dataformat too much at the moment, we could sort by description in the controller for packets and traffic and move the interface mapping into the getRRDlistAction() response. This should keep all backwards compatible and offers improved sorting with limited impact. --- .../Api/SystemhealthController.php | 26 ++++++++++++++++--- .../views/OPNsense/Diagnostics/health.volt | 17 +++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemhealthController.php b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemhealthController.php index b7fc74b91..a7a8d85f6 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemhealthController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemhealthController.php @@ -495,16 +495,36 @@ class SystemhealthController extends ApiControllerBase $response = $backend->configdRun('health list'); $healthList = json_decode($response, true); + $interfaces = $this->getInterfacesAction(); + $result['data'] = array(); if (is_array($healthList)) { foreach ($healthList as $healthItem => $details) { if (!array_key_exists($details['topic'], $result['data'])) { - $result['data'][$details['topic']] = array(); + $result['data'][$details['topic']] = []; + } + if (in_array($details['topic'], ['packets', 'traffic'])) { + if (isset($interfaces[$details['itemName']])) { + $desc = $interfaces[$details['itemName']]['descr']; + } else { + $desc = $details['itemName']; + } + $result['data'][$details['topic']][$details['itemName']] = $desc; + } else { + $result['data'][$details['topic']][] = $details['itemName']; } - $result['data'][$details['topic']][] = $details['itemName']; } } + foreach (['packets', 'traffic'] as $key) { + if (isset($result['data'][$key])) { + natcasesort($result['data'][$key]); + $result['data'][$key] = array_keys($result['data'][$key]); + } + } + ksort($result['data']); + + $result["interfaces"] = $interfaces; $result["result"] = "ok"; // Category => Items @@ -603,7 +623,7 @@ class SystemhealthController extends ApiControllerBase $config = Config::getInstance()->object(); if ($config->interfaces->count() > 0) { foreach ($config->interfaces->children() as $key => $node) { - $intfmap[(string)$key] = array("descr" => !empty((string)$node->descr) ? (string)$node->descr : $key); + $intfmap[(string)$key] = ["descr" => !empty((string)$node->descr) ? (string)$node->descr : $key]; } } return $intfmap; diff --git a/src/opnsense/mvc/app/views/OPNsense/Diagnostics/health.volt b/src/opnsense/mvc/app/views/OPNsense/Diagnostics/health.volt index 5fa8a880a..0388075ff 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Diagnostics/health.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Diagnostics/health.volt @@ -187,16 +187,13 @@ $('#maintabs').html(tabs); $('#tab_1').toggleClass('active'); // map interface descriptions - ajaxGet("/api/diagnostics/systemhealth/getInterfaces" , {}, function (data, status) { - $(".rrd-item").each(function(){ - var rrd_item = $(this); - var rrd_item_name = $(this).attr('id').split('-')[0].toLowerCase(); - $.map(data, function(value, key){ - if (key.toLowerCase() == rrd_item_name) { - rrd_item.html(value['descr']); - } - - }); + $(".rrd-item").each(function(){ + var rrd_item = $(this); + var rrd_item_name = $(this).attr('id').split('-')[0].toLowerCase(); + $.map(data['interfaces'], function(value, key){ + if (key.toLowerCase() == rrd_item_name) { + rrd_item.html(value['descr']); + } }); }); } else {