Skip to content
Snippets Groups Projects
Commit a7a1d453 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Sort targets & panels for aggregate dashboards

parent 0e27124b
No related branches found
No related tags found
No related merge requests found
...@@ -490,7 +490,7 @@ def get_interface_data(interfaces): ...@@ -490,7 +490,7 @@ def get_interface_data(interfaces):
return result 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 Helper for grouping interface data to be used for generating
aggregate dashboards. aggregate dashboards.
...@@ -509,7 +509,7 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): ...@@ -509,7 +509,7 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field):
:return: dictionary of aggregate dashboards and their interface data :return: dictionary of aggregate dashboards and their interface data
""" """
result = [] targets = []
def get_reduce_func_for_field(field): def get_reduce_func_for_field(field):
def reduce_func(prev, curr): def reduce_func(prev, curr):
...@@ -532,15 +532,19 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field): ...@@ -532,15 +532,19 @@ def get_aggregate_interface_data(interfaces, agg_name, group_field):
for info in interface['dashboards_info']: for info in interface['dashboards_info']:
remote = info['name'] remote = info['name']
location = host.split('.')[1].upper() location = host.split('.')[1].upper()
result.append({ targets.append({
'type': agg_name,
'interface': interface_name, 'interface': interface_name,
'hostname': host, 'hostname': host,
'remote': remote, 'remote': remote,
'location': location, 'location': location,
'alias': f"{router} - {remote} - {interface_name}", '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): def get_aggregate_targets(targets):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment