diff --git a/mktxp/datasource/base_ds.py b/mktxp/datasource/base_ds.py index bd48021..989a4c2 100644 --- a/mktxp/datasource/base_ds.py +++ b/mktxp/datasource/base_ds.py @@ -17,7 +17,7 @@ class BaseDSProcessor: ''' @staticmethod - def trimmed_records(router_entry, *, router_records = None, metric_labels = None, add_router_id = True, translation_table = None): + def trimmed_records(router_entry, *, router_records = None, metric_labels = None, add_router_id = True, translation_table = None, translate_if_no_value = True): metric_labels = metric_labels or [] router_records = router_records or [] translation_table = translation_table or {} @@ -36,7 +36,8 @@ def trimmed_records(router_entry, *, router_records = None, metric_labels = None # translate fields if needed for key, func in translation_table.items(): - translated_record[key] = func(translated_record.get(key)) + if translate_if_no_value or translated_record.get(key) is not None: + translated_record[key] = func(translated_record.get(key)) labeled_records.append(translated_record) return labeled_records diff --git a/mktxp/datasource/health_ds.py b/mktxp/datasource/health_ds.py index a943432..f107df4 100644 --- a/mktxp/datasource/health_ds.py +++ b/mktxp/datasource/health_ds.py @@ -19,7 +19,7 @@ class HealthMetricsDataSource: ''' Health Metrics data provider ''' @staticmethod - def metric_records(router_entry, *, metric_labels = None, translation_table = None): + def metric_records(router_entry, *, metric_labels = None, translation_table = None, translate_if_no_value = False): if metric_labels is None: metric_labels = [] try: @@ -34,8 +34,8 @@ def metric_records(router_entry, *, metric_labels = None, translation_table = No val = record.get('value', None) record[name] = val - return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records, - metric_labels = metric_labels, translation_table = translation_table) + return BaseDSProcessor.trimmed_records(router_entry, router_records = health_records, metric_labels = metric_labels, + translation_table = translation_table, translate_if_no_value = translate_if_no_value) except Exception as exc: print(f'Error getting system health info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') return None