mirror of
https://github.com/prymitive/karma
synced 2026-05-09 03:36:44 +00:00
This allows to set config keys via flags, in additions to current env variable only configuration. Flags are autogenerated from supported env keys.
50 lines
1.1 KiB
Go
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
|
|
}
|