diff options
| author | Fuwn <[email protected]> | 2026-01-20 06:54:27 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 06:54:27 -0800 |
| commit | d3094c19da8aa8aa111b19b1ba6a2c48fb18d15d (patch) | |
| tree | 006e2927ebccf1234ee4cf84c37c186735fd7ec5 | |
| parent | feat: Expand group-level defaults with more monitor options (diff) | |
| download | kaze-d3094c19da8aa8aa111b19b1ba6a2c48fb18d15d.tar.xz kaze-d3094c19da8aa8aa111b19b1ba6a2c48fb18d15d.zip | |
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).
| -rw-r--r-- | config.example.yaml | 57 | ||||
| -rw-r--r-- | internal/config/config.go | 50 |
2 files changed, 94 insertions, 13 deletions
diff --git a/config.example.yaml b/config.example.yaml index b9d4ae1..93236df 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -63,6 +63,7 @@ groups: # 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: + # # Common options # interval: 30s # timeout: 10s # retries: 2 @@ -73,11 +74,25 @@ groups: # round_uptime: false # disable_ping_tooltips: false # disable_uptime_tooltip: false + # # HTTP/HTTPS options # method: GET # user_agent: "Custom-Agent/1.0" # expected_status: 200 + # expected_content: "ok" + # body: '{"ping": true}' # headers: # Authorization: "Bearer token" + # # ICMP options + # ping_count: 4 + # # DNS options + # dns_server: "8.8.8.8:53" + # record_type: A + # # GraphQL options + # graphql_query: "query { health }" + # graphql_variables: + # key: "value" + # # Database options + # db_type: postgres monitors: - name: "Website" type: https @@ -224,22 +239,38 @@ incidents: # ================================ # # Group-level defaults (optional): +# All monitor options (except name, type, target, link, reset_on_next_check, +# expected_ips, expected_cname) can be set as group defaults. +# Individual monitors can override any default. # defaults: -# interval: duration - Default check interval for all monitors in group -# 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 -# 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) +# # Common options +# interval: duration - Default check interval +# timeout: duration - Default timeout +# retries: int - Default retry attempts +# verify_ssl: bool - Default SSL verification +# hide_ssl_days: bool - Hide SSL certificate days left +# hide_ping: bool - Hide response time from display +# round_response_time: bool - Round response time to nearest second +# round_uptime: bool - Round uptime percentage +# disable_ping_tooltips: bool - Disable hover tooltips on ping bars +# disable_uptime_tooltip: bool - Disable uptime tooltip with last failure info +# # HTTP/HTTPS options +# method: string - HTTP method (default: GET) # user_agent: string - Custom User-Agent header -# expected_status: int - Expected HTTP status code (default: 200) +# expected_status: int - Expected HTTP status code +# expected_content: string - Expected text in response body +# body: string - Request body for POST/PUT/PATCH # headers: map[string]string - Custom headers to send -# Note: Individual monitors can override these defaults +# # ICMP options +# ping_count: int - Number of ICMP packets to send +# # DNS options +# dns_server: string - DNS server to query +# record_type: string - DNS record type (A, AAAA, CNAME, MX, TXT) +# # GraphQL options +# graphql_query: string - GraphQL query to execute +# graphql_variables: map - GraphQL query variables +# # Database options +# db_type: string - Database type (postgres, mysql, redis, memcached, mongodb) # # Common fields for all monitor types: # name: string (required) - Display name for the monitor 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 + } } } } |