package main import ( "fmt" "os" "path/filepath" "nocternity.net/go-monitoring/cmd/sslcert" "nocternity.net/go-monitoring/cmd/zoneserial" "nocternity.net/go-monitoring/pkg/program" "nocternity.net/go-monitoring/pkg/version" ) var ( programs map[string]program.ProgramBuilder = map[string]program.ProgramBuilder{ "check_ssl_certificate": sslcert.NewProgram, "check_zone_serial": zoneserial.NewProgram, } ) func exitError(msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg+"\n", args...) os.Exit(1) } func main() { ownName := filepath.Base(os.Args[0]) var program program.Program if builder, ok := programs[ownName]; ok { program = builder() } else if len(os.Args) < 2 { exitError("Syntax: %s [arguments]\n %s programs", os.Args[0], os.Args[0]) } else if os.Args[1] == "programs" { fmt.Println("Available programs:") for name := range programs { fmt.Printf(" %s\n", name) } os.Exit(0) } else if os.Args[1] == "--version" || os.Args[1] == "-v" { fmt.Printf("%s %s\n", ownName, version.Version()) os.Exit(0) } else if builder, ok := programs[os.Args[1]]; ok { os.Args = os.Args[1:] program = builder() } else { exitError("Unknown program: %s", os.Args[1]) } defer program.Done() if program.CheckArguments() { program.RunCheck() } }