Emmanuel BENOîT
1a29325c34
A "program" was in fact a plugin, while a "plugin" represented the plugin's results.
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"nocternity.net/gomonop/cmd/sslcert"
|
|
"nocternity.net/gomonop/cmd/zoneserial"
|
|
"nocternity.net/gomonop/pkg/plugin"
|
|
"nocternity.net/gomonop/pkg/results"
|
|
"nocternity.net/gomonop/pkg/version"
|
|
)
|
|
|
|
var (
|
|
plugins map[string]plugin.Builder = map[string]plugin.Builder{
|
|
"check_ssl_certificate": sslcert.NewProgram,
|
|
"check_zone_serial": zoneserial.NewProgram,
|
|
}
|
|
)
|
|
|
|
func getPlugin() plugin.Plugin {
|
|
ownName := filepath.Base(os.Args[0])
|
|
|
|
if builder, ok := plugins[ownName]; ok {
|
|
return builder()
|
|
}
|
|
|
|
if len(os.Args) < 2 {
|
|
fmt.Printf("Syntax: %s <plugin> [arguments]\n", ownName)
|
|
fmt.Printf(" %s --plugin|-p\n", ownName)
|
|
fmt.Printf(" %s --version|-v", ownName)
|
|
}
|
|
|
|
switch os.Args[1] {
|
|
case "--plugins", "-p":
|
|
for name := range plugins {
|
|
fmt.Println(name)
|
|
}
|
|
os.Exit(0)
|
|
|
|
case "--version", "-v":
|
|
fmt.Printf("%s %s\n", ownName, version.Version())
|
|
os.Exit(0)
|
|
}
|
|
|
|
if builder, ok := plugins[os.Args[1]]; ok {
|
|
os.Args = os.Args[1:]
|
|
return builder()
|
|
}
|
|
|
|
fmt.Printf("Unknown plugin: %s\n", os.Args[1])
|
|
os.Exit(1)
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
runPlugin := getPlugin()
|
|
|
|
output := runPlugin.Results()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
output.SetState(results.StatusUnknown, "Internal error")
|
|
output.AddLinef("Error info: %v", r)
|
|
}
|
|
fmt.Println(output.String())
|
|
os.Exit(output.ExitCode())
|
|
}()
|
|
|
|
if runPlugin.CheckArguments() {
|
|
runPlugin.RunCheck()
|
|
}
|
|
}
|