diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index 988af14e1..1a13c537e 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -37,6 +37,7 @@ import ( config_util "github.com/prometheus/common/config" "github.com/prometheus/common/model" "github.com/prometheus/common/version" + "github.com/prometheus/exporter-toolkit/https" "gopkg.in/alecthomas/kingpin.v2" "github.com/prometheus/prometheus/config" @@ -59,6 +60,12 @@ func main() { "The config files to check.", ).Required().ExistingFiles() + checkWebConfigCmd := checkCmd.Command("web-config", "Check if the web config files are valid or not.") + webConfigFiles := checkWebConfigCmd.Arg( + "web-config-files", + "The config files to check.", + ).Required().ExistingFiles() + checkRulesCmd := checkCmd.Command("rules", "Check if the rule files are valid or not.") ruleFiles := checkRulesCmd.Arg( "rule-files", @@ -154,6 +161,9 @@ func main() { case checkConfigCmd.FullCommand(): os.Exit(CheckConfig(*configFiles...)) + case checkWebConfigCmd.FullCommand(): + os.Exit(CheckWebConfig(*webConfigFiles...)) + case checkRulesCmd.FullCommand(): os.Exit(CheckRules(*ruleFiles...)) @@ -234,6 +244,24 @@ func CheckConfig(files ...string) int { return 0 } +// CheckWebConfig validates web configuration files. +func CheckWebConfig(files ...string) int { + failed := false + + for _, f := range files { + if err := https.Validate(f); err != nil { + fmt.Fprintln(os.Stderr, f, "FAILED:", err) + failed = true + continue + } + fmt.Fprintln(os.Stderr, f, "SUCCESS") + } + if failed { + return 1 + } + return 0 +} + func checkFileExists(fn string) error { // Nothing set, nothing to error on. if fn == "" {