mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
adapt health datasource to RouterOS v7
This commit is contained in:
@@ -22,6 +22,17 @@ class HealthMetricsDataSource:
|
|||||||
def metric_records(router_entry, *, metric_labels = []):
|
def metric_records(router_entry, *, metric_labels = []):
|
||||||
try:
|
try:
|
||||||
health_records = router_entry.api_connection.router_api().get_resource('/system/health').get()
|
health_records = router_entry.api_connection.router_api().get_resource('/system/health').get()
|
||||||
|
|
||||||
|
for record in health_records:
|
||||||
|
if 'name' in record:
|
||||||
|
# Note: The API in RouterOS v7.X+ returns a response like this:
|
||||||
|
# [{'name': 'temperature', 'value': '33', 'type': 'C'}, ...]
|
||||||
|
# To make this work for both v6 and v7 add a <name>:<value> pair in v7
|
||||||
|
# Otherwise it is not possible to get the value by name (e.g. records['voltage'])
|
||||||
|
name = record['name']
|
||||||
|
val = record.get('value', None)
|
||||||
|
record[name] = val
|
||||||
|
|
||||||
return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records, metric_labels = metric_labels)
|
return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records, metric_labels = metric_labels)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f'Error getting system health info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
|
print(f'Error getting system health info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
|
||||||
|
|||||||
Reference in New Issue
Block a user