From d3094c19da8aa8aa111b19b1ba6a2c48fb18d15d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 20 Jan 2026 06:54:27 -0800 Subject: feat: Add all remaining monitor options to group defaults Support defaulting any monitor option at group level: - expected_content, body (HTTP/HTTPS) - ping_count (ICMP) - dns_server, record_type (DNS) - graphql_query, graphql_variables (GraphQL) - db_type (Database) Only name, type, target, link, reset_on_next_check, expected_ips, and expected_cname remain monitor-specific (not defaultable). --- internal/config/config.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'internal') diff --git a/internal/config/config.go b/internal/config/config.go index 5c485d9..d82fee0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -82,6 +82,18 @@ type MonitorDefaults struct { UserAgent string `yaml:"user_agent,omitempty"` Headers map[string]string `yaml:"headers,omitempty"` ExpectedStatus *int `yaml:"expected_status,omitempty"` + ExpectedContent string `yaml:"expected_content,omitempty"` + Body string `yaml:"body,omitempty"` + // ICMP specific + PingCount *int `yaml:"ping_count,omitempty"` + // DNS specific + DNSServer string `yaml:"dns_server,omitempty"` + RecordType string `yaml:"record_type,omitempty"` + // GraphQL specific + GraphQLQuery string `yaml:"graphql_query,omitempty"` + GraphQLVariables map[string]string `yaml:"graphql_variables,omitempty"` + // Database specific + DBType string `yaml:"db_type,omitempty"` } // MonitorConfig represents a single monitor @@ -337,6 +349,44 @@ func (c *Config) applyDefaults() { if m.ExpectedStatus == 0 && grp.Defaults.ExpectedStatus != nil { m.ExpectedStatus = *grp.Defaults.ExpectedStatus } + // Apply expected_content default + if m.ExpectedContent == "" && grp.Defaults.ExpectedContent != "" { + m.ExpectedContent = grp.Defaults.ExpectedContent + } + // Apply body default + if m.Body == "" && grp.Defaults.Body != "" { + m.Body = grp.Defaults.Body + } + // Apply ICMP ping_count default + if m.PingCount == 0 && grp.Defaults.PingCount != nil { + m.PingCount = *grp.Defaults.PingCount + } + // Apply DNS defaults + if m.DNSServer == "" && grp.Defaults.DNSServer != "" { + m.DNSServer = grp.Defaults.DNSServer + } + if m.RecordType == "" && grp.Defaults.RecordType != "" { + m.RecordType = grp.Defaults.RecordType + } + // Apply GraphQL defaults + if m.GraphQLQuery == "" && grp.Defaults.GraphQLQuery != "" { + m.GraphQLQuery = grp.Defaults.GraphQLQuery + } + // Apply GraphQL variables (merge, monitor variables take precedence) + if len(grp.Defaults.GraphQLVariables) > 0 { + if m.GraphQLVariables == nil { + m.GraphQLVariables = make(map[string]string) + } + for k, v := range grp.Defaults.GraphQLVariables { + if _, exists := m.GraphQLVariables[k]; !exists { + m.GraphQLVariables[k] = v + } + } + } + // Apply database type default + if m.DBType == "" && grp.Defaults.DBType != "" { + m.DBType = grp.Defaults.DBType + } } } } -- cgit v1.2.3