mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Promtool: add web config validation
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
2f54aa0604
commit
003d6451fc
|
@ -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 == "" {
|
||||
|
|
Loading…
Reference in a new issue