Files
karma/alerts.go
Łukasz Mierzwa fd0eb46adf Sanitize Alertmanager URI before putting it in /alerts.json reponse
Alertmanager URI might contain basic auth username & password, we should replace password with 'xxx' in logs and and error messages.
Go will still print it in HTTP request errors, but that will be fixed in the next Go release - https://go-review.googlesource.com/c/go/+/102855
Fixes #259
2018-04-27 09:36:12 -07:00

58 lines
1.3 KiB
Go

package main
import (
"strings"
"github.com/cloudflare/unsee/internal/alertmanager"
"github.com/cloudflare/unsee/internal/filters"
"github.com/cloudflare/unsee/internal/models"
)
func getFiltersFromQuery(filterString string) ([]filters.FilterT, bool) {
validFilters := false
matchFilters := []filters.FilterT{}
qList := strings.Split(filterString, ",")
for _, filterExpression := range qList {
f := filters.NewFilter(filterExpression)
if f.GetIsValid() {
validFilters = true
}
matchFilters = append(matchFilters, f)
}
return matchFilters, validFilters
}
func countLabel(countStore models.LabelsCountMap, key string, val string) {
if _, found := countStore[key]; !found {
countStore[key] = make(map[string]int)
}
if _, found := countStore[key][val]; found {
countStore[key][val]++
} else {
countStore[key][val] = 1
}
}
func getUpstreams() models.AlertmanagerAPISummary {
summary := models.AlertmanagerAPISummary{}
upstreams := alertmanager.GetAlertmanagers()
for _, upstream := range upstreams {
u := models.AlertmanagerAPIStatus{
Name: upstream.Name,
URI: upstream.SanitizedURI(),
Error: upstream.Error(),
}
summary.Instances = append(summary.Instances, u)
summary.Counters.Total++
if u.Error == "" {
summary.Counters.Healthy++
} else {
summary.Counters.Failed++
}
}
return summary
}