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 | |
| 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.
| -rw-r--r-- | config.example.yaml | 37 | ||||
| -rw-r--r-- | internal/config/config.go | 69 |
2 files changed, 85 insertions, 21 deletions
diff --git a/config.example.yaml b/config.example.yaml index 3fe5fa8..b9d4ae1 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -61,13 +61,23 @@ groups: - name: "Web Services" # default_collapsed: false # Start collapsed (false = expanded by default) # show_group_uptime: true # Show aggregate uptime percentage (true by default) - # Group-level defaults (optional - apply to all monitors in this group unless overridden) - # defaults: - # interval: 30s - # timeout: 10s - # retries: 2 - # verify_ssl: true - # disable_ping_tooltips: false + # Group-level defaults (optional - apply to all monitors in this group unless overridden) + # defaults: + # interval: 30s + # timeout: 10s + # retries: 2 + # verify_ssl: true + # hide_ssl_days: false + # hide_ping: false + # round_response_time: false + # round_uptime: false + # disable_ping_tooltips: false + # disable_uptime_tooltip: false + # method: GET + # user_agent: "Custom-Agent/1.0" + # expected_status: 200 + # headers: + # Authorization: "Bearer token" monitors: - name: "Website" type: https @@ -219,7 +229,16 @@ incidents: # timeout: duration - Default timeout for all monitors in group # retries: int - Default retry attempts for all monitors in group # verify_ssl: bool - Default SSL verification for all monitors in group -# disable_ping_tooltips: bool - Default tooltip behavior for all monitors in group +# hide_ssl_days: bool - Hide SSL certificate days left (default: false) +# hide_ping: bool - Hide response time from display (default: false) +# round_response_time: bool - Round response time to nearest second (default: false) +# round_uptime: bool - Round uptime percentage (default: false) +# disable_ping_tooltips: bool - Disable hover tooltips on ping bars (default: false) +# disable_uptime_tooltip: bool - Disable uptime tooltip with last failure info (default: false) +# method: string - HTTP method for HTTP/HTTPS monitors (default: GET) +# user_agent: string - Custom User-Agent header +# expected_status: int - Expected HTTP status code (default: 200) +# headers: map[string]string - Custom headers to send # Note: Individual monitors can override these defaults # # Common fields for all monitor types: @@ -235,9 +254,11 @@ incidents: # reset_on_next_check: bool - When true, wipes all historical data for this monitor on next check # Automatically flips to false after reset completes # hide_ssl_days: bool - Hide SSL/TLS certificate days left from display (default: false) +# hide_ping: bool - Hide response time from display and tooltips (default: false) # round_response_time: bool - Round response time to nearest second (default: false) # round_uptime: bool - Round uptime percentage to whole number (e.g., 99.99% → 100%) (default: false) # disable_ping_tooltips: bool - Disable hover tooltips on ping history bars (default: false, or group default) +# disable_uptime_tooltip: bool - Disable uptime tooltip showing last failure info (default: false) # # HTTP/HTTPS specific fields: # expected_status: int - Expected HTTP status code (default: 200) 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 + } } } } |