config

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config loads and validates the exporter configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDotEnv added in v1.4.0

func LoadDotEnv(cfgPath string)

LoadDotEnv loads a .env file before config interpolation so the `cp .env.example .env` quickstart works for bare-metal runs too, not just docker compose (which reads .env natively). It tries the working directory first, then the config file's directory (covers systemd units whose WorkingDirectory is not the install dir). The first file found wins.

Already-set environment variables always take precedence: godotenv.Load only sets keys that are not present in the environment, so real env/secret injection can never be shadowed by a stray .env file.

func ParseWeekday added in v1.1.0

func ParseWeekday(s string) (time.Weekday, error)

ParseWeekday maps a 3-letter day abbreviation (case-insensitive) to a time.Weekday.

Types

type Collection

type Collection struct {
	Interval          time.Duration `yaml:"interval"`
	Timeout           time.Duration `yaml:"timeout"`
	Lookback          time.Duration `yaml:"lookback"`
	AssetAgeThreshold time.Duration `yaml:"assetAgeThreshold"`
	PerJobActivities  bool          `yaml:"perJobActivities"`
}

Collection holds loop timing. Lookback bounds the activities query window; AssetAgeThreshold gates per-asset last-copy-age emission; PerJobActivities opts into per-job activity metrics (higher cardinality — one series set per job in the window).

type Compliance

type Compliance struct {
	Grace     time.Duration        `yaml:"grace"`
	Defaults  ComplianceTarget     `yaml:"defaults"`
	Overrides []ComplianceOverride `yaml:"overrides"`
}

Compliance configures Phase 2 SLA target resolution: a lateness grace window, the per-tenant default target, and override rules that refine it.

type ComplianceOverride

type ComplianceOverride struct {
	Tenant           string `yaml:"tenant"`
	AssetType        string `yaml:"assetType"`
	PolicyName       string `yaml:"policyName"`
	ComplianceTarget `yaml:",inline"`
}

ComplianceOverride narrows a target to the assets it selects. Empty selector fields match any value; the most specific matching override wins (resolved in internal/report).

type ComplianceTarget

type ComplianceTarget struct {
	RPOHours      int `yaml:"rpoHours"`
	RetentionDays int `yaml:"retentionDays"`
	MinCopies     int `yaml:"minCopies"`
}

ComplianceTarget is an SLA target spec: backup-frequency (RPO), retention, and copy count.

type Config

type Config struct {
	Server     ServerHTTP `yaml:"server"`
	Collection Collection `yaml:"collection"`
	OTel       OTel       `yaml:"otel"`
	Servers    []Server   `yaml:"servers"`
}

Config is the whole file.

func Load

func Load(path string) (*Config, error)

Load reads, interpolates ${ENV} references, applies defaults, and validates.

type OTel

type OTel struct {
	Enabled  bool   `yaml:"enabled"`
	Endpoint string `yaml:"endpoint"`
	Insecure bool   `yaml:"insecure"`
	Interval string `yaml:"interval"`
}

OTel configures optional OTLP metric/trace export.

type ReportConfig

type ReportConfig struct {
	Database struct {
		DSN string `yaml:"dsn"`
	} `yaml:"database"`
	Capture struct {
		Interval      time.Duration `yaml:"interval"`
		Timeout       time.Duration `yaml:"timeout"`
		RetentionDays int           `yaml:"retentionDays"`
	} `yaml:"capture"`
	Servers    []ReportServer `yaml:"servers"`
	Compliance Compliance     `yaml:"compliance"`
	Retention  Retention      `yaml:"retention"`
	Report     ReportOutput   `yaml:"report"`
	SMTP       SMTP           `yaml:"smtp"`
	Schedules  []Schedule     `yaml:"schedules"`
}

ReportConfig is the cmd/report configuration.

func LoadReport

func LoadReport(path string) (*ReportConfig, error)

LoadReport reads, interpolates ${ENV} references, applies defaults, and validates.

type ReportOutput

type ReportOutput struct {
	Listen    string        `yaml:"listen"`    // empty = CLI-only (no HTTP endpoint)
	AuthToken string        `yaml:"authToken"` // optional bearer; empty = no auth (localhost posture)
	BrandName string        `yaml:"brandName"`
	Tokens    []ReportToken `yaml:"tokens"`
}

ReportOutput configures Phase 3 report generation: the optional HTTP endpoint and branding.

type ReportServer

type ReportServer struct {
	Name               string `yaml:"name"`
	Tenant             string `yaml:"tenant"`
	Host               string `yaml:"host"`
	Port               int    `yaml:"port"` // defaults to 8443
	Username           string `yaml:"username"`
	Password           string `yaml:"password"`
	PasswordFile       string `yaml:"passwordFile"`
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify"`
}

ReportServer is one PPDM server captured for backup history, tagged with a tenant.

func (ReportServer) BaseURL

func (s ReportServer) BaseURL() string

BaseURL returns the https://host:port root for the PPDM REST API.

type ReportToken added in v1.1.0

type ReportToken struct {
	Token   string   `yaml:"token"`
	Tenants []string `yaml:"tenants"`
}

ReportToken authorizes a bearer token to read the named tenants' reports ("*" = all).

type Retention added in v1.1.0

type Retention struct {
	DefaultDays int                 `yaml:"defaultDays"`
	Overrides   []RetentionOverride `yaml:"overrides"`
}

Retention configures how long captured history is kept per tenant. DefaultDays applies to any tenant without an override; it falls back to capture.retentionDays when unset.

func (Retention) DaysFor added in v1.1.0

func (r Retention) DaysFor(tenant string) int

DaysFor returns the retention window for a tenant: its override if present, else DefaultDays.

type RetentionOverride added in v1.1.0

type RetentionOverride struct {
	Tenant string `yaml:"tenant"`
	Days   int    `yaml:"days"`
}

RetentionOverride sets a per-tenant retention window (days) overriding the default.

type SMTP added in v1.1.0

type SMTP struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"` // defaults to 587
	From     string `yaml:"from"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	StartTLS bool   `yaml:"starttls"`
}

SMTP configures outbound email delivery for scheduled reports.

type Schedule added in v1.1.0

type Schedule struct {
	Tenant     string   `yaml:"tenant"`
	Cadence    string   `yaml:"cadence"` // daily | weekly | monthly
	Weekday    string   `yaml:"weekday"` // weekly only (Mon..Sun)
	Day        int      `yaml:"day"`     // monthly only (1..31, clamped to month length)
	Hour       int      `yaml:"hour"`    // 0..23
	Recipients []string `yaml:"recipients"`
}

Schedule is one per-tenant report cadence. Times are UTC.

type Server

type Server struct {
	Name               string `yaml:"name"`
	Host               string `yaml:"host"`
	Port               int    `yaml:"port"` // defaults to 8443
	Username           string `yaml:"username"`
	Password           string `yaml:"password"`
	PasswordFile       string `yaml:"passwordFile"`
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify"`
}

Server is one PPDM server to monitor.

func (Server) BaseURL

func (s Server) BaseURL() string

BaseURL returns the https://host:port root for the PPDM REST API.

type ServerHTTP

type ServerHTTP struct {
	Host    string `yaml:"host"`
	Port    string `yaml:"port"`
	URI     string `yaml:"uri"`
	LogName string `yaml:"logName"`
}

ServerHTTP holds the exporter's own HTTP-server settings. Named to avoid colliding with the PPDM target Server struct.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher reloads and revalidates the config on SIGHUP or file change, emitting the new *Config on Updates(). A bad reload is logged and dropped (the running config stays).

func NewWatcher

func NewWatcher(path string) (*Watcher, error)

NewWatcher starts watching path. Call Close to stop.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the watcher.

func (*Watcher) Trigger

func (w *Watcher) Trigger()

Trigger forces a reload (used by tests and callers that want a manual refresh).

func (*Watcher) Updates

func (w *Watcher) Updates() <-chan *Config

Updates is the channel of successfully reloaded configs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL