started on framework for running recurring checks
This commit is contained in:
@ -3,6 +3,8 @@ package config
|
||||
import (
|
||||
"alrm/alarm"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -10,12 +12,15 @@ type Config struct {
|
||||
Groups map[string]*Group
|
||||
Alarms map[string]alarm.Alarm
|
||||
Interval time.Duration
|
||||
Threads int
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
// Default check interval, 30 seconds
|
||||
Interval: time.Second * 30,
|
||||
// Default number of threads, use local CPU count
|
||||
Threads: runtime.NumCPU(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +66,16 @@ func (c *Config) SetInterval(val string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) SetThreads(val string) error {
|
||||
threads, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Threads = threads
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadConfig(fn string, debuglvl int) (*Config, error) {
|
||||
parser := &Parser{DebugLevel: debuglvl}
|
||||
config, err := parser.Parse(fn)
|
||||
|
@ -63,6 +63,14 @@ func (p *Parser) Parse(fn string) (*Config, error) {
|
||||
switch key {
|
||||
case "interval":
|
||||
err := config.SetInterval(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"invalid duration for interval in %s, line %d: \"%s\"",
|
||||
fn, tok.Line(), value,
|
||||
)
|
||||
}
|
||||
case "threads":
|
||||
err := config.SetThreads(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"invalid number for interval in %s, line %d: \"%s\"",
|
||||
|
Reference in New Issue
Block a user