diff options
| author | Fuwn <[email protected]> | 2026-01-20 06:52:06 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 06:52:06 -0800 |
| commit | 121d67e9a7af2cf8d7718c96c5ae170aaf820385 (patch) | |
| tree | 3e3cf38fe66bbd5b0833dde74a6e17e8d4037820 /internal | |
| parent | fix: Support disable_uptime_tooltip in group defaults (diff) | |
| download | kaze-121d67e9a7af2cf8d7718c96c5ae170aaf820385.tar.xz kaze-121d67e9a7af2cf8d7718c96c5ae170aaf820385.zip | |
feat: Expand group-level defaults with more monitor options
Add support for setting these options at group level:
- hide_ssl_days, hide_ping, round_response_time, round_uptime
- method, user_agent, headers, expected_status
This allows configuring common settings once per group instead of
repeating them on every monitor.
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 0d9329d..5c485d9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -68,12 +68,20 @@ type GroupConfig struct { // 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"` - DisablePingTooltips *bool `yaml:"disable_ping_tooltips,omitempty"` - DisableUptimeTooltip *bool `yaml:"disable_uptime_tooltip,omitempty"` + Interval *Duration `yaml:"interval,omitempty"` + Timeout *Duration `yaml:"timeout,omitempty"` + Retries *int `yaml:"retries,omitempty"` + VerifySSL *bool `yaml:"verify_ssl,omitempty"` + HideSSLDays *bool `yaml:"hide_ssl_days,omitempty"` + HidePing *bool `yaml:"hide_ping,omitempty"` + RoundResponseTime *bool `yaml:"round_response_time,omitempty"` + RoundUptime *bool `yaml:"round_uptime,omitempty"` + DisablePingTooltips *bool `yaml:"disable_ping_tooltips,omitempty"` + DisableUptimeTooltip *bool `yaml:"disable_uptime_tooltip,omitempty"` + Method string `yaml:"method,omitempty"` + UserAgent string `yaml:"user_agent,omitempty"` + Headers map[string]string `yaml:"headers,omitempty"` + ExpectedStatus *int `yaml:"expected_status,omitempty"` } // MonitorConfig represents a single monitor @@ -287,13 +295,48 @@ func (c *Config) applyDefaults() { } } } - // Apply group-level disable_ping_tooltips default - if !m.DisablePingTooltips && grp.Defaults != nil && grp.Defaults.DisablePingTooltips != nil && *grp.Defaults.DisablePingTooltips { - m.DisablePingTooltips = true - } - // Apply group-level disable_uptime_tooltip default - if !m.DisableUptimeTooltip && grp.Defaults != nil && grp.Defaults.DisableUptimeTooltip != nil && *grp.Defaults.DisableUptimeTooltip { - m.DisableUptimeTooltip = true + // Apply group-level boolean defaults (only if not explicitly set on monitor) + if grp.Defaults != nil { + if !m.HideSSLDays && grp.Defaults.HideSSLDays != nil && *grp.Defaults.HideSSLDays { + m.HideSSLDays = true + } + if !m.HidePing && grp.Defaults.HidePing != nil && *grp.Defaults.HidePing { + m.HidePing = true + } + if !m.RoundResponseTime && grp.Defaults.RoundResponseTime != nil && *grp.Defaults.RoundResponseTime { + m.RoundResponseTime = true + } + if !m.RoundUptime && grp.Defaults.RoundUptime != nil && *grp.Defaults.RoundUptime { + m.RoundUptime = true + } + if !m.DisablePingTooltips && grp.Defaults.DisablePingTooltips != nil && *grp.Defaults.DisablePingTooltips { + m.DisablePingTooltips = true + } + if !m.DisableUptimeTooltip && grp.Defaults.DisableUptimeTooltip != nil && *grp.Defaults.DisableUptimeTooltip { + m.DisableUptimeTooltip = true + } + // Apply string defaults (only if not set on monitor) + if m.Method == "" && grp.Defaults.Method != "" { + m.Method = grp.Defaults.Method + } + if m.UserAgent == "" && grp.Defaults.UserAgent != "" { + m.UserAgent = grp.Defaults.UserAgent + } + // Apply headers (merge, monitor headers take precedence) + if len(grp.Defaults.Headers) > 0 { + if m.Headers == nil { + m.Headers = make(map[string]string) + } + for k, v := range grp.Defaults.Headers { + if _, exists := m.Headers[k]; !exists { + m.Headers[k] = v + } + } + } + // Apply expected_status default + if m.ExpectedStatus == 0 && grp.Defaults.ExpectedStatus != nil { + m.ExpectedStatus = *grp.Defaults.ExpectedStatus + } } } } |