diff --git a/npbackup/restic_metrics/__init__.py b/npbackup/restic_metrics/__init__.py index 2aed421..394091c 100644 --- a/npbackup/restic_metrics/__init__.py +++ b/npbackup/restic_metrics/__init__.py @@ -478,7 +478,9 @@ def restic_output_2_metrics(restic_result, output, labels_string=None): metrics.append( 'restic_backup_failure{{{},timestamp="{}"}} {}'.format( - labels_string, int(datetime.now(timezone.utc).timestamp()), 1 if errors else 0 + labels_string, + int(datetime.now(timezone.utc).timestamp()), + 1 if errors else 0, ) ) return errors, metrics @@ -590,14 +592,16 @@ if __name__ == "__main__": logger.error("Output directory {} does not exist.".format(destination_dir)) sys.exit(2) - labels_string = 'action="backup",backup_job="{}",instance="{}"'.format(instance, backup_job) + labels_string = 'action="backup",backup_job="{}",instance="{}"'.format( + instance, backup_job + ) if args.labels: labels_string += ",{}".format(args.labels) destination_file = os.path.join(destination_dir, output_filename) try: with open(log_file, "r", encoding="utf-8") as file_handle: errors, metrics = restic_output_2_metrics( - True, output=file_handle.readlines(), labels=labels_string + True, output=file_handle.readlines(), labels_string=labels_string ) if errors: logger.error("Script finished with errors.") diff --git a/tests/test_npbackup-cli.py b/tests/test_npbackup-cli.py index eba9160..4052077 100644 --- a/tests/test_npbackup-cli.py +++ b/tests/test_npbackup-cli.py @@ -113,8 +113,9 @@ def test_npbackup_cli_wrong_config_path(): __main__.main() except SystemExit: print(str(logs)) - assert "Config file npbackup-non-existent.conf cannot be read or does not exist" in str( - logs + assert ( + "Config file npbackup-non-existent.conf cannot be read or does not exist" + in str(logs) ), "There should be a critical error when config file is not given" diff --git a/tests/test_restic_metrics.py b/tests/test_restic_metrics.py index 142dccf..f4fbecb 100644 --- a/tests/test_restic_metrics.py +++ b/tests/test_restic_metrics.py @@ -114,7 +114,7 @@ def test_restic_str_output_2_metrics(): instance = "test" backup_job = "some_nas" labels_string = f'action="backup",backup_job="{backup_job}",instance="{instance}"' - + for version, output in restic_str_outputs.items(): print(f"Testing V1 parser restic str output from version {version}") errors, prom_metrics = restic_output_2_metrics(True, output, labels_string)