Skip to content

Commit 617c385

Browse files
committed
sanitised null bytes from neighbor API strings, #326
1 parent 6a30b29 commit 617c385

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

mktxp/datasource/neighbor_ds.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def metric_records(router_entry, metric_labels, ipv6=False):
2626
router_records = router_entry.api_connection.router_api().get_resource(f'/ipv6/neighbor').get(status='reachable')
2727
else:
2828
router_records = router_entry.api_connection.router_api().get_resource(f'/ip/neighbor').get()
29+
30+
# Sanitize null bytes from all string fields (e.g. padded identity strings)
31+
for record in router_records:
32+
for key, value in record.items():
33+
if isinstance(value, str):
34+
record[key] = value.split('\x00', 1)[0].strip()
35+
2936
return BaseDSProcessor.trimmed_records(router_entry, router_records=router_records, metric_labels=metric_labels)
3037
except Exception as exc:
3138
print(f'Error getting Neighbors info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')

0 commit comments

Comments
 (0)