From a7a1d453f4af14b67329a0653119a6a110755be1 Mon Sep 17 00:00:00 2001 From: Bjarke Madsen <bjarke@nordu.net> Date: Mon, 6 Jan 2025 15:59:52 +0100 Subject: [PATCH] Sort targets & panels for aggregate dashboards --- brian_dashboard_manager/templating/helpers.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/brian_dashboard_manager/templating/helpers.py b/brian_dashboard_manager/templating/helpers.py index aad2a31..00b5946 100644 --- a/brian_dashboard_manager/templating/helpers.py +++ b/brian_dashboard_manager/templating/helpers.py @@ -490,7 +490,7 @@ def get_interface_data(interfaces): return result -def get_aggregate_interface_data(interfaces, agg_name, group_field): +def get_aggregate_interface_data(interfaces, group_field): """ Helper for grouping interface data to be used for generating aggregate dashboards. @@ -509,7 +509,7 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): :return: dictionary of aggregate dashboards and their interface data """ - result = [] + targets = [] def get_reduce_func_for_field(field): def reduce_func(prev, curr): @@ -532,15 +532,19 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): for info in interface['dashboards_info']: remote = info['name'] location = host.split('.')[1].upper() - result.append({ - 'type': agg_name, + targets.append({ 'interface': interface_name, 'hostname': host, 'remote': remote, 'location': location, 'alias': f"{router} - {remote} - {interface_name}", }) - return reduce(get_reduce_func_for_field(group_field), result, {}) + targets = sorted(targets, key=lambda x: x[group_field]) + result = reduce(get_reduce_func_for_field(group_field), targets, {}) + + for key in result: + result[key] = sorted(result[key], key=lambda x: x[group_field]) + return result def get_aggregate_targets(targets): -- GitLab