Browse Source

added manual alarm triggering for testing

master
Christopher Ramey 3 years ago
parent
commit
bcf0e91d0b
  1. 3
      alarm/alarm_email.go
  2. 39
      main.go

3
alarm/alarm_email.go

@ -12,7 +12,6 @@ const (
TK_FROM
)
type AlarmEmail struct {
Type string
Name string
@ -29,7 +28,7 @@ func NewAlarmEmail(name string) *AlarmEmail {
}
func (a *AlarmEmail) Alarm() error {
fmt.Printf("email alarm")
fmt.Printf("email alarm\n")
return nil
}

39
main.go

@ -49,10 +49,36 @@ func main() {
fmt.Printf("config is OK\n")
case "alarm":
an := flag.Arg(1)
if an == "" {
fmt.Fprintf(os.Stderr, "alarm name required\n")
os.Exit(1)
}
cfg, err := config.ReadConfig(*cfgPath, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
al, exists := cfg.Alarms[an]
if !exists {
fmt.Fprintf(os.Stderr, "group or host is not defined\n")
os.Exit(1)
}
err = al.Alarm()
if err != nil {
fmt.Fprintf(os.Stderr, "alarm failed: %s\n", err.Error())
os.Exit(1)
}
fmt.Printf("alarm sounded successfully\n")
case "check":
tn := flag.Arg(1)
if tn == "" {
fmt.Fprintf(os.Stderr, "check requires a host or group\n")
cn := flag.Arg(1)
if cn == "" {
fmt.Fprintf(os.Stderr, "check host or group name required\n")
os.Exit(1)
}
@ -62,20 +88,20 @@ func main() {
os.Exit(1)
}
group, exists := cfg.Groups[tn]
gr, exists := cfg.Groups[cn]
if !exists {
fmt.Fprintf(os.Stderr, "group or host is not defined\n")
os.Exit(1)
}
err = group.Check(*debuglvl)
err = gr.Check(*debuglvl)
if err != nil {
fmt.Fprintf(os.Stderr, "check failed: %s\n", err.Error())
os.Exit(1)
}
fmt.Printf("check successful\n")
case "":
case "help", "":
printUsage()
default:
@ -92,4 +118,5 @@ func printUsage() {
fmt.Printf("Actions:\n")
fmt.Printf(" verify configuration: %s [args] config\n", os.Args[0])
fmt.Printf(" run a check manually: %s [args] check <host/group>\n", os.Args[0])
fmt.Printf(" test an alarm: %s [args] alarm <name>\n", os.Args[0])
}
Loading…
Cancel
Save