示例#1
0
func (m *Monitor) Update(configs []*common.Config) error {
	all := map[string]MonitorTask{}
	for i, upd := range configs {
		config, err := common.MergeConfigs(m.config, upd)
		if err != nil {
			logp.Err("Failed merging monitor config with updates: %v", err)
			return err
		}

		shared := struct {
			Schedule *schedule.Schedule `config:"schedule" validate:"required"`
		}{}
		if err := config.Unpack(&shared); err != nil {
			logp.Err("Failed parsing job schedule: ", err)
			return err
		}

		jobs, err := m.factory(config)
		if err != nil {
			err = fmt.Errorf("%v when initializing monitor %v(%v)", err, m.name, i)
			return err
		}

		for _, job := range jobs {
			all[job.Name()] = MonitorTask{
				job:      job,
				schedule: shared.Schedule,
			}
		}
	}

	// stop all active jobs
	for _, job := range m.active {
		job.cancel()
	}
	m.active = map[string]MonitorTask{}

	// start new and reconfigured tasks
	for name, t := range all {
		job := createJob(m.manager.client, name, t.job)
		t.cancel = m.manager.jobControl.Add(t.schedule, name, job)
		m.active[name] = t
	}

	return nil
}
示例#2
0
// Load reads the configuration from a YAML file structure. If path is empty
// this method reads from the configuration file specified by the '-c' command
// line flag.
func Load(path string) (*common.Config, error) {
	var config *common.Config
	var err error

	if path == "" {
		config, err = common.LoadFiles(configfiles.list...)
	} else {
		config, err = common.LoadFile(path)
	}
	if err != nil {
		return nil, err
	}

	return common.MergeConfigs(
		defaults,
		config,
		overwrites,
	)
}
示例#3
0
// Load reads the configuration from a YAML file structure. If path is empty
// this method reads from the configuration file specified by the '-c' command
// line flag.
func Load(path string) (*common.Config, error) {
	var config *common.Config
	var err error

	cfgpath := ""
	if *configPath != "" {
		cfgpath = *configPath
	} else if *homePath != "" {
		cfgpath = *homePath
	}

	if path == "" {
		list := []string{}
		for _, cfg := range configfiles.list {
			if !filepath.IsAbs(cfg) {
				list = append(list, filepath.Join(cfgpath, cfg))
			} else {
				list = append(list, cfg)
			}
		}
		config, err = common.LoadFiles(list...)
	} else {
		if !filepath.IsAbs(path) {
			path = filepath.Join(cfgpath, path)
		}
		config, err = common.LoadFile(path)
	}
	if err != nil {
		return nil, err
	}

	return common.MergeConfigs(
		defaults,
		config,
		overwrites,
	)
}