|
|
|
@ -11,9 +11,10 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CheckCommand struct {
|
|
|
|
|
Servers ServersCommand `command:"servers" description:"checks on servers"`
|
|
|
|
|
Snapshots SnapshotsCommand `command:"snapshots" description:"checks on snapshots"`
|
|
|
|
|
Storages StoragesCommand `command:"storages" description:"checks on storages"`
|
|
|
|
|
ConfigFile string `short:"f" long:"config-file" description:"Name of config file" value-name:"FILE"`
|
|
|
|
|
Servers ServersCommand `command:"servers" description:"checks on servers"`
|
|
|
|
|
Snapshots SnapshotsCommand `command:"snapshots" description:"checks on snapshots"`
|
|
|
|
|
Storages StoragesCommand `command:"storages" description:"checks on storages"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Checker CheckCommand
|
|
|
|
@ -25,6 +26,23 @@ type CheckConfig struct {
|
|
|
|
|
Token string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func config(configFile string) {
|
|
|
|
|
|
|
|
|
|
if configFile == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
viper.SetConfigFile(configFile)
|
|
|
|
|
|
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Config file not found or error parsing: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Config.UserId = viper.GetString("gridscale.userid")
|
|
|
|
|
Config.Token = viper.GetString("gridscale.token")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
|
|
var parser = flags.NewParser(&Checker, flags.Default)
|
|
|
|
@ -33,17 +51,9 @@ func main() {
|
|
|
|
|
Config.UserId = os.Getenv("GRIDSCALE_USER")
|
|
|
|
|
Config.Token = os.Getenv("GRIDSCALE_TOKEN")
|
|
|
|
|
} else {
|
|
|
|
|
// look in check.toml for the config
|
|
|
|
|
viper.SetConfigName("check")
|
|
|
|
|
viper.AddConfigPath("config")
|
|
|
|
|
|
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Config file not found or error parsing: %v", err)
|
|
|
|
|
if checkFileExistance("config/check.toml") {
|
|
|
|
|
config("config/check.toml")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Config.UserId = viper.GetString("gridscale.userid")
|
|
|
|
|
Config.Token = viper.GetString("gridscale.token")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := parser.Parse(); err != nil {
|
|
|
|
@ -57,22 +67,42 @@ func main() {
|
|
|
|
|
Unknown("no subcommands specificed.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PrintMsg(msg string) {
|
|
|
|
|
if msg != "" {
|
|
|
|
|
fmt.Println(" - " + msg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Ok(msg string) {
|
|
|
|
|
fmt.Println("OK - " + msg)
|
|
|
|
|
fmt.Print("OK")
|
|
|
|
|
PrintMsg(msg)
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Warning(msg string) {
|
|
|
|
|
fmt.Println("WARNING - " + msg)
|
|
|
|
|
fmt.Print("WARNING")
|
|
|
|
|
PrintMsg(msg)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Critical(msg string) {
|
|
|
|
|
fmt.Println("CRITICAL - " + msg)
|
|
|
|
|
fmt.Print("CRITICAL")
|
|
|
|
|
PrintMsg(msg)
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Unknown(msg string) {
|
|
|
|
|
fmt.Println("UNKNOWN - " + msg)
|
|
|
|
|
fmt.Print("UNKNOWN")
|
|
|
|
|
PrintMsg(msg)
|
|
|
|
|
os.Exit(3)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkFileExistance(fileName string) bool {
|
|
|
|
|
if _, err := os.Stat(fileName); err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|