예제 #1
0
func NewConsulPager(client *consulapi.Client) *ConsulPager {
	cp := &ConsulPager{client: client}
	cp.kvlock = apixtra.NewLock(client, "Pager")
	if cp.kvlock == nil {
		return nil
	}
	cp.alerts = make(map[string]*Alert, 10)
	cp.Channels = make(map[string]Channel, 10)
	cp.Events = make(map[string]*consulapi.UserEvent, 10)
	cp.DefaultMaturity = "3s"
	return cp
}
예제 #2
0
func LoadPagerFromYAML(fileName string, client *consulapi.Client) *ConsulPager {
	vals, err := ioutil.ReadFile(fileName)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	var cp ConsulPager
	err = yaml.Unmarshal(vals, &cp)
	cp.kvlock = apixtra.NewLock(client, "Pager")
	if cp.kvlock == nil {
		return nil
	}
	cp.alerts = make(map[string]*Alert, 10)
	cp.Events = make(map[string]*consulapi.UserEvent, 10)
	cp.client = client
	if cp.DefaultMaturity == "" {
		cp.DefaultMaturity = "3s"
	}
	for k, v := range cp.Channels {
		v.SetId(k)
	}
	return &cp
}