From 42e70ea7960c3e6a9b55e55b72ed38730b8c3fae Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 26 Dec 2022 19:56:23 +0200 Subject: [PATCH] include reading summary inside try --- restic_exporter/restic_exporter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/restic_exporter/restic_exporter.py b/restic_exporter/restic_exporter.py index fd8cff8..e1e726c 100644 --- a/restic_exporter/restic_exporter.py +++ b/restic_exporter/restic_exporter.py @@ -71,13 +71,13 @@ class restic_exporter: for line in content: try: line_data = json.loads(line) + if 'message_type' in line_data: + if line_data['message_type'] == 'summary': + self.summary = line_data + if 'snapshot_id' in line_data: + self.labels["snapshot_id"] = line_data['snapshot_id'] except json.decoder.JSONDecodeError as error: self._log.error(f"Error decoding line '{line}'. {error}") - if 'message_type' in line_data: - if line_data['message_type'] == 'summary': - self.summary = line_data - if 'snapshot_id' in line_data: - self.labels["snapshot_id"] = line_data['snapshot_id'] file_stats = os.stat(json_file) self.summary['timestamp'] = round(file_stats.st_mtime * 1000) self._log.debug(f"Summary: {json.dumps(self.summary, indent=2)}")