Fixed intervalFormat for Graphite Alerting

This commit is contained in:
utkarshcmu 2016-11-01 17:55:45 -07:00
parent 9b28bf25a4
commit 1e8beb8983

View File

@ -11,6 +11,7 @@ import (
"path" "path"
"strings" "strings"
"time" "time"
"regexp"
"golang.org/x/net/context/ctxhttp" "golang.org/x/net/context/ctxhttp"
@ -58,9 +59,9 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
for _, query := range queries { for _, query := range queries {
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil { if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
formData["target"] = []string{fullTarget} formData["target"] = []string{fixIntervalFormat(fullTarget)}
} else { } else {
formData["target"] = []string{query.Model.Get("target").MustString()} formData["target"] = []string{fixIntervalFormat(query.Model.Get("target").MustString())}
} }
} }
@ -150,3 +151,17 @@ func formatTimeRange(input string) string {
} }
return strings.Replace(strings.Replace(input, "m", "min", -1), "M", "mon", -1) return strings.Replace(strings.Replace(input, "m", "min", -1), "M", "mon", -1)
} }
func fixIntervalFormat(target string) string {
rMinute := regexp.MustCompile("'(\\d+)m'")
rMin := regexp.MustCompile("m")
target = rMinute.ReplaceAllStringFunc(target, func(m string) string {
return rMin.ReplaceAllString(m, "min")
})
rMonth := regexp.MustCompile("'(\\d+)M'")
rMon := regexp.MustCompile("M")
target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
return rMon.ReplaceAllString(M, "mon")
})
return target
}