2021-01-01 09:26:49 -09:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AlrmGroup struct {
|
|
|
|
Name string
|
|
|
|
Hosts map[string]*AlrmHost
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ag *AlrmGroup) NewHost(name string) (*AlrmHost, error) {
|
|
|
|
if ag.Hosts == nil {
|
|
|
|
ag.Hosts = make(map[string]*AlrmHost)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, exists := ag.Hosts[name]; exists {
|
|
|
|
return nil, fmt.Errorf("host %s already exists", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
host := &AlrmHost{Name: name}
|
|
|
|
ag.Hosts[name] = host
|
|
|
|
return host, nil
|
|
|
|
}
|
2021-01-01 15:43:28 -09:00
|
|
|
|
|
|
|
func (ag *AlrmGroup) Check() error {
|
|
|
|
for _, host := range ag.Hosts {
|
|
|
|
for _, chk := range host.Checks {
|
|
|
|
err := chk.Check()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|