Skip to content

Commit efdccd9

Browse files
committed
Add -check flag for dry-run config validation
1 parent e1743bb commit efdccd9

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to Gjallar are documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
55

6+
## [0.6.0] - 2026-07-06
7+
8+
### Added
9+
10+
- `-check` flag: validate the configuration (monitors, rules, alert URLs)
11+
and exit without running any check or sending any alert.
12+
613
## [0.5.0] - 2026-07-05
714

815
### Added

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,24 @@ var version = "dev"
2828
func main() {
2929
configPath := flag.String("config", "gjallar.yaml", "path to YAML configuration")
3030
showVersion := flag.Bool("version", false, "print version and exit")
31+
checkOnly := flag.Bool("check", false, "validate the configuration (including checkers and alert URLs) and exit")
3132
flag.Parse()
3233
if *showVersion {
3334
fmt.Println("gjallar", version)
3435
return
3536
}
37+
if *checkOnly {
38+
cfg, err := config.Load(*configPath)
39+
if err == nil {
40+
_, err = prepare(cfg)
41+
}
42+
if err != nil {
43+
fmt.Fprintln(os.Stderr, "gjallar:", err)
44+
os.Exit(1)
45+
}
46+
fmt.Printf("config OK: %d monitors, %d alert channels\n", len(cfg.Monitors), len(cfg.Alerts))
47+
return
48+
}
3649
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
3750
slog.Info("starting gjallar", "version", version)
3851

0 commit comments

Comments
 (0)