Skip to content

Commit ed33b8b

Browse files
committed
Netwatch centralized formatting
1 parent c865c75 commit ed33b8b

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

mktxp/datasource/netwatch_ds.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ def metric_records(router_entry, *, metric_labels=None, translation_table=None):
2929

3030
# since addition in ROS v7.14, name is supported natively
3131
for netwatch_record in netwatch_records:
32-
if not netwatch_record.get('name'):
33-
comment = netwatch_record.get('comment')
34-
host = netwatch_record.get('host')
35-
# Format name with comment using centralized function
36-
netwatch_record['name'] = BaseOutputProcessor.format_interface_name(
37-
host,
38-
comment,
39-
router_entry.config_entry.interface_name_format
40-
)
32+
# Determine the primary identifier: use 'name' if set, fallback to 'host'
33+
name = netwatch_record.get('name') or netwatch_record.get('host')
34+
comment = netwatch_record.get('comment')
4135

36+
# Apply the centralized formatting
37+
netwatch_record['name'] = BaseOutputProcessor.format_interface_name(
38+
name,
39+
comment,
40+
router_entry.config_entry.interface_name_format
41+
)
4242
return BaseDSProcessor.trimmed_records(router_entry, router_records = netwatch_records, translation_table = translation_table, metric_labels = metric_labels)
4343
except Exception as exc:
4444
print(f'Error getting Netwatch info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
4545
return None
46-

0 commit comments

Comments
 (0)