Files
karma/alertmanager/silences.go
Łukasz Mierzwa 3de3a9c481 Generate flag for each environment key
This allows to set config keys via flags, in additions to current env variable only configuration. Flags are autogenerated from supported env keys.
2017-03-26 13:38:37 -07:00

50 lines
1.1 KiB
Go

package alertmanager
import (
"errors"
"fmt"
"math"
"time"
"github.com/cloudflare/unsee/config"
"github.com/cloudflare/unsee/models"
log "github.com/Sirupsen/logrus"
)
type silencesData struct {
Silences []models.AlertmanagerSilence `json:"silences"`
TotalSilences int `json:"totalSilences"`
}
// SilenceAPIResponse is what Alertmanager API returns
type SilenceAPIResponse struct {
Status string `json:"status"`
Data silencesData `json:"data"`
ErrorType string `json:"errorType"`
Error string `json:"error"`
}
// Get will return fresh data from Alertmanager API
func (response *SilenceAPIResponse) Get() error {
start := time.Now()
url, err := joinURL(config.Config.AlertmanagerURI, "api/v1/silences")
if err != nil {
return err
}
url = fmt.Sprintf("%s?limit=%d", url, math.MaxUint32)
err = getJSONFromURL(url, config.Config.AlertmanagerTimeout, response)
if err != nil {
return err
}
if response.Status != "success" {
return errors.New(response.Error)
}
log.Infof("Got %d silences(s) in %s", len(response.Data.Silences), time.Since(start))
return nil
}