Files
karma/timer.go
Łukasz Mierzwa 5d4ae47888 Convert all packages to be internal
Internal packages are supported by Go 1.5+, any package in /internal/ dir is only importable from the same repo. This will cleanup main dir a bit and provide better namespace for unsee subpackages
2017-08-04 16:21:27 -07:00

48 lines
856 B
Go

package main
import (
"runtime"
"sync"
"github.com/cloudflare/unsee/internal/alertmanager"
log "github.com/sirupsen/logrus"
)
func pullFromAlertmanager() {
// always flush cache once we're done
defer apiCache.Flush()
log.Info("Pulling latest alerts and silences from Alertmanager")
upstreams := alertmanager.GetAlertmanagers()
wg := sync.WaitGroup{}
wg.Add(len(upstreams))
for _, upstream := range upstreams {
go func(am *alertmanager.Alertmanager) {
log.Infof("[%s] Collecting alerts and silences", am.Name)
err := am.Pull()
if err != nil {
log.Errorf("[%s] %s", am.Name, err)
}
wg.Done()
}(upstream)
}
wg.Wait()
log.Info("Pull completed")
runtime.GC()
}
// Tick is the background timer used to call PullFromAlertmanager
func Tick() {
for {
select {
case <-ticker.C:
pullFromAlertmanager()
}
}
}