diff options
| author | Dennis Fink | 2026-09-06 23:22:26 +0200 |
|---|---|---|
| committer | Dennis Fink | 2026-09-06 23:22:26 +0200 |
| commit | 66d0fadd5e364eb8fceb39e8061cd93a01e9f210 (patch) | |
| tree | a71dcf1a433bcd7a30be711b9b80d997d1e7691a | |
| parent | 4172e92e4e4452a72c3a9d06492702d567d1c951 (diff) | |
| download | prometheus-borgmatic-exporter-66d0fadd5e364eb8fceb39e8061cd93a01e9f210.tar.gz prometheus-borgmatic-exporter-66d0fadd5e364eb8fceb39e8061cd93a01e9f210.zip | |
feat(cli): support multiple borgmatic config paths
Allow --borgmatic-config to be specified multiple times and pass each
configuration path through to borgmatic.
This also removes the hard-coded default configuration path, allowing
borgmatic's own configuration discovery to be used when no explicit
configuration is provided.
Diffstat (limited to '')
| -rw-r--r-- | prometheus_borgmatic_exporter/__init__.py | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/prometheus_borgmatic_exporter/__init__.py b/prometheus_borgmatic_exporter/__init__.py index ac2721e..fea8dbd 100644 --- a/prometheus_borgmatic_exporter/__init__.py +++ b/prometheus_borgmatic_exporter/__init__.py @@ -284,12 +284,9 @@ def extract_archive_counts( def fetch_repositories( - borgmatic_bin: Path, - borgmatic_config: Path, - all_archives: bool, + borgmatic_bin: Path, borgmatic_configs: tuple[Path, ...], all_archives: bool ) -> tuple[list[types.BorgInfoReturnType], list[types.ArchiveCount]]: - """ - Fetch repository and archive data from borgmatic. + """Fetch repository and archive data from borgmatic. When all_archives is False, runs `borgmatic info --archive latest` and `borgmatic list` in complementary intent: info provides per-repository @@ -314,7 +311,11 @@ def fetch_repositories( always populated regardless of the all_archives flag. """ verbose("Fetching repositories") - borgmatic_cmd = [str(borgmatic_bin), "--config", str(borgmatic_config)] + borgmatic_cmd = [str(borgmatic_bin)] + + for config in borgmatic_configs: + borgmatic_cmd.extend(["--config", str(config)]) + info_command = [*borgmatic_cmd, "info", "--json"] if all_archives: @@ -473,14 +474,16 @@ def collect_archive_metrics( ) @click.option( "--borgmatic-config", + "borgmatic_configs", + multiple=True, type=click.Path( - exists=True, - readable=True, - dir_okay=False, - allow_dash=False, - path_type=Path, + exists=True, readable=True, dir_okay=True, allow_dash=False, path_type=Path + ), + help=( + "Configuration file or directory. " + "Can be specified multiple times. " + "If not specified, borgmatic's default configuration discovery is used." ), - default="/etc/borgmatic/config.yaml", ) @click.option( "--textfile-collector-dir", @@ -510,7 +513,7 @@ def collect_archive_metrics( def prometheus_borgmatic_exporter( ctx: click.Context, borgmatic_bin: Path, - borgmatic_config: Path, + borgmatic_configs: tuple[Path, ...], textfile_collector_dir: Path, all_archives_flag: bool, quiet_flag: bool, @@ -537,16 +540,18 @@ def prometheus_borgmatic_exporter( debug("Effective configuration:") debug(" borgmatic_bin:", str(borgmatic_bin)) - debug(" borgmatic_config:", str(borgmatic_config)) + debug( + " borgmatic_configs:", + ", ".join(str(config) for config in borgmatic_configs) + or "<borgmatic defaults>", + ) debug(" textfile_collector_dir:", str(textfile_collector_dir)) debug(" all_archives:", str(all_archives_flag)) debug(" verbose:", str(verbose_flag)) debug(" quiet:", str(quiet_flag)) repositories, archive_counts = fetch_repositories( - borgmatic_bin, - borgmatic_config, - all_archives_flag, + borgmatic_bin, borgmatic_configs, all_archives_flag ) for repository in archive_counts: |
