mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fixed intervalFormat for Graphite Alerting
This commit is contained in:
parent
9b28bf25a4
commit
1e8beb8983
@ -11,6 +11,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
@ -58,9 +59,9 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
|
||||
|
||||
for _, query := range queries {
|
||||
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
|
||||
formData["target"] = []string{fullTarget}
|
||||
formData["target"] = []string{fixIntervalFormat(fullTarget)}
|
||||
} 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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user