alrm/config.go

51 lines
802 B
Go
Raw Normal View History

2020-08-15 17:16:52 -08:00
package main
type AlrmConfig struct {
2020-08-16 04:19:06 -08:00
Groups []*AlrmGroup
Interval int
2020-08-15 17:16:52 -08:00
}
func (ac *AlrmConfig) NewGroup() *AlrmGroup {
group := &AlrmGroup{}
ac.Groups = append(ac.Groups, group)
return group
}
type AlrmGroup struct {
Name string
Hosts []*AlrmHost
}
func (ag *AlrmGroup) NewHost() *AlrmHost {
host := &AlrmHost{}
ag.Hosts = append(ag.Hosts, host)
return host
}
type AlrmHost struct {
Name string
Address string
2020-08-20 08:44:56 -08:00
Checks []AlrmCheck
}
func (ah *AlrmHost) GetAddress() string {
if ah.Address != "" {
return ah.Address
}
return ah.Name
}
type AlrmCheck interface {
Parse(string) (bool, error)
Check() error
2020-08-15 17:16:52 -08:00
}
func ReadConfig(fn string) (*AlrmConfig, error) {
parser := &Parser{}
2020-08-20 04:34:22 -08:00
config, err := parser.Parse(fn)
if err != nil {
2020-08-15 17:16:52 -08:00
return nil, err
}
return config, nil
}