Exemplo n.º 1
0
func startLeaderElection(addr, dc, acl string) *LeaderElection {
	config := consulapi.DefaultConfig()
	config.Address = addr
	config.Datacenter = dc
	config.Token = acl
	client, _ := consulapi.NewClient(config)
	lock, _ := client.LockKey(LockKey)

	leader := &LeaderElection{
		lock:           lock,
		cleanupChannel: make(chan struct{}, 1),
		stopChannel:    make(chan struct{}, 1),
	}

	go leader.start()

	return leader
}
Exemplo n.º 2
0
func NewClient(address, dc, aclToken string) (*ConsulAlertClient, error) {
	config := consulapi.DefaultConfig()
	config.Address = address
	config.Datacenter = dc
	config.Token = aclToken
	api, _ := consulapi.NewClient(config)
	alertConfig := DefaultAlertConfig()

	client := &ConsulAlertClient{
		api:    api,
		config: alertConfig,
	}

	log.Println("Checking consul agent connection...")
	if _, err := client.api.Status().Leader(); err != nil {
		return nil, err
	}

	client.LoadConfig()
	client.UpdateCheckData()
	return client, nil
}