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
Branches
Tags
No related merge requests found
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment