diff options
| author | Fuwn <[email protected]> | 2026-01-19 04:38:08 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-19 04:38:08 -0800 |
| commit | 2f2549d6df7300b04a4550dc060a3d7f684a0b41 (patch) | |
| tree | 0e58a578a7113569b9f0464bd094e9164903c560 /internal/config/config.go | |
| parent | docs: Add TOFU certificate tracking to future ideas (diff) | |
| download | kaze-2f2549d6df7300b04a4550dc060a3d7f684a0b41.tar.xz kaze-2f2549d6df7300b04a4550dc060a3d7f684a0b41.zip | |
feat: Add reset_on_next_check flag to wipe monitor history
Diffstat (limited to 'internal/config/config.go')
| -rw-r--r-- | internal/config/config.go | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 1c033e1..8839906 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -63,17 +63,18 @@ type GroupConfig struct { // MonitorConfig represents a single monitor type MonitorConfig struct { - Name string `yaml:"name"` - Type string `yaml:"type"` // http, https, tcp - 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 - 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"` + VerifySSL *bool `yaml:"verify_ssl,omitempty"` + Method string `yaml:"method,omitempty"` + Headers map[string]string `yaml:"headers,omitempty"` + Body string `yaml:"body,omitempty"` } // IncidentConfig represents an incident or maintenance @@ -308,3 +309,50 @@ type MonitorWithGroup struct { GroupName string Monitor MonitorConfig } + +// UpdateResetFlag updates the reset_on_next_check flag for a specific monitor in the config file +func UpdateResetFlag(configPath string, monitorName string, value bool) error { + // Read the config file + data, err := os.ReadFile(configPath) + if err != nil { + return fmt.Errorf("failed to read config file: %w", err) + } + + // Parse as YAML + var cfg Config + if err := yaml.Unmarshal(data, &cfg); err != nil { + return fmt.Errorf("failed to parse config file: %w", err) + } + + // Find and update the monitor + found := false + for i := range cfg.Groups { + for j := range cfg.Groups[i].Monitors { + if cfg.Groups[i].Monitors[j].Name == monitorName { + cfg.Groups[i].Monitors[j].ResetOnNextCheck = value + found = true + break + } + } + if found { + break + } + } + + if !found { + return fmt.Errorf("monitor %q not found in config", monitorName) + } + + // Marshal back to YAML + newData, err := yaml.Marshal(&cfg) + if err != nil { + return fmt.Errorf("failed to marshal config: %w", err) + } + + // Write back to file + if err := os.WriteFile(configPath, newData, 0644); err != nil { + return fmt.Errorf("failed to write config file: %w", err) + } + + return nil +} |