Log metric destination

This commit is contained in:
Orsiris de Jong 2023-05-29 19:33:17 +02:00
parent 60b5776b14
commit 3228f0fad3

View file

@ -99,11 +99,8 @@ def metric_writer(config_dict: dict, restic_result: bool, result_string: str):
) )
if errors or not restic_result: if errors or not restic_result:
logger.error("Restic finished with errors.") logger.error("Restic finished with errors.")
if destination.lower().startswith("file://"): if destination:
destination = destination[len("file://") :] logger.debug("Uploading metrics to {}".format(destination))
with open(destination, "w") as file_handle:
for metric in metrics:
file_handle.write(metric + "\n")
if destination.lower().startswith("http"): if destination.lower().startswith("http"):
try: try:
authentication = ( authentication = (
@ -114,6 +111,13 @@ def metric_writer(config_dict: dict, restic_result: bool, result_string: str):
logger.info("No metrics authentication present.") logger.info("No metrics authentication present.")
authentication = None authentication = None
upload_metrics(destination, authentication, no_cert_verify, metrics) upload_metrics(destination, authentication, no_cert_verify, metrics)
else:
try:
with open(destination, "w") as file_handle:
for metric in metrics:
file_handle.write(metric + "\n")
except OSError as exc:
logger.error("Cannot write metrics file {}: {}".format(destination, exc))
except KeyError as exc: except KeyError as exc:
logger.info("Metrics not configured: {}".format(exc)) logger.info("Metrics not configured: {}".format(exc))
except OSError as exc: except OSError as exc: