diff options
| author | Fuwn <[email protected]> | 2026-01-19 16:53:39 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-19 16:53:39 -0800 |
| commit | b83baaae6735eccca31a94e630fdeb67919733a0 (patch) | |
| tree | 625deb2572ed2e8cefa607e88c764c7c21344802 /internal/config | |
| parent | feat: Add reset_on_next_check flag to wipe monitor history (diff) | |
| download | kaze-b83baaae6735eccca31a94e630fdeb67919733a0.tar.xz kaze-b83baaae6735eccca31a94e630fdeb67919733a0.zip | |
feat: Add group defaults, content checking, SSL tracking for Gemini, hide/round options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 8839906..13391e2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -59,22 +59,35 @@ type GroupConfig struct { Monitors []MonitorConfig `yaml:"monitors"` DefaultCollapsed *bool `yaml:"default_collapsed"` // nil = false (expanded by default) ShowGroupUptime *bool `yaml:"show_group_uptime"` // nil = true (show by default) + // Group-level defaults that apply to all monitors in the group (can be overridden per monitor) + Defaults *MonitorDefaults `yaml:"defaults,omitempty"` +} + +// MonitorDefaults contains default values that can be set at group level +type MonitorDefaults struct { + Interval *Duration `yaml:"interval,omitempty"` + Timeout *Duration `yaml:"timeout,omitempty"` + Retries *int `yaml:"retries,omitempty"` + VerifySSL *bool `yaml:"verify_ssl,omitempty"` } // MonitorConfig represents a single monitor type MonitorConfig struct { - Name string `yaml:"name"` - Type string `yaml:"type"` // http, https, tcp, gemini - Target string `yaml:"target"` - Interval Duration `yaml:"interval"` - Timeout Duration `yaml:"timeout"` - Retries int `yaml:"retries,omitempty"` // Number of retry attempts before marking as down - ResetOnNextCheck bool `yaml:"reset_on_next_check,omitempty"` // Wipe monitor data on next check and flip to false - ExpectedStatus int `yaml:"expected_status,omitempty"` - VerifySSL *bool `yaml:"verify_ssl,omitempty"` - Method string `yaml:"method,omitempty"` - Headers map[string]string `yaml:"headers,omitempty"` - Body string `yaml:"body,omitempty"` + Name string `yaml:"name"` + Type string `yaml:"type"` // http, https, tcp, gemini + Target string `yaml:"target"` + Interval Duration `yaml:"interval"` + Timeout Duration `yaml:"timeout"` + Retries int `yaml:"retries,omitempty"` // Number of retry attempts before marking as down + ResetOnNextCheck bool `yaml:"reset_on_next_check,omitempty"` // Wipe monitor data on next check and flip to false + ExpectedStatus int `yaml:"expected_status,omitempty"` + ExpectedContent string `yaml:"expected_content,omitempty"` // Expected text in response body + VerifySSL *bool `yaml:"verify_ssl,omitempty"` + HideSSLDays bool `yaml:"hide_ssl_days,omitempty"` // Hide SSL days left from display + RoundResponseTime bool `yaml:"round_response_time,omitempty"` // Round response time to nearest second + Method string `yaml:"method,omitempty"` + Headers map[string]string `yaml:"headers,omitempty"` + Body string `yaml:"body,omitempty"` } // IncidentConfig represents an incident or maintenance @@ -194,11 +207,25 @@ func (c *Config) applyDefaults() { for j := range c.Groups[i].Monitors { m := &c.Groups[i].Monitors[j] + + // Apply group-level defaults first, then monitor-level overrides if m.Interval.Duration == 0 { - m.Interval.Duration = 30 * time.Second + if grp.Defaults != nil && grp.Defaults.Interval != nil { + m.Interval = *grp.Defaults.Interval + } else { + m.Interval.Duration = 30 * time.Second + } } if m.Timeout.Duration == 0 { - m.Timeout.Duration = 10 * time.Second + if grp.Defaults != nil && grp.Defaults.Timeout != nil { + m.Timeout = *grp.Defaults.Timeout + } else { + m.Timeout.Duration = 10 * time.Second + } + } + // Apply group-level retries default + if m.Retries == 0 && grp.Defaults != nil && grp.Defaults.Retries != nil { + m.Retries = *grp.Defaults.Retries } // Retries default to 0 (no retries) if not specified if m.Retries < 0 { @@ -212,14 +239,24 @@ func (c *Config) applyDefaults() { m.Method = "GET" } if m.VerifySSL == nil { - defaultVerify := true - m.VerifySSL = &defaultVerify + // Apply group default if available + if grp.Defaults != nil && grp.Defaults.VerifySSL != nil { + m.VerifySSL = grp.Defaults.VerifySSL + } else { + defaultVerify := true + m.VerifySSL = &defaultVerify + } } } if m.Type == "gemini" { if m.VerifySSL == nil { - defaultVerify := true - m.VerifySSL = &defaultVerify + // Apply group default if available + if grp.Defaults != nil && grp.Defaults.VerifySSL != nil { + m.VerifySSL = grp.Defaults.VerifySSL + } else { + defaultVerify := true + m.VerifySSL = &defaultVerify + } } } } |