add to_lower to_upper func

This commit is contained in:
liugq 2022-05-13 18:45:10 +08:00
parent a656326203
commit 8a0fa910da
3 changed files with 10 additions and 3 deletions

View File

@ -633,7 +633,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
period := time.Now().Sub(rule.LastNotificationTime.Local())
//log.Error(lastAlertItem.ID, period, periodDuration)
paramsCtx := newParameterCtx(rule, checkResults,alertItem.ID, alertItem.Created.Format(time.RFC3339))
paramsCtx := newParameterCtx(rule, checkResults,alertItem.ID, alertItem.Created.UnixNano()/1e6)
if lastAlertItem.ID == "" || period > periodDuration {
actionResults, errCount := performChannels(rule.Channels.Normal, paramsCtx)
@ -724,7 +724,7 @@ func (engine *Engine) Test(rule *alerting.Rule) ([]alerting.ActionExecutionResul
return nil, fmt.Errorf("check condition error:%w", err)
}
var actionResults []alerting.ActionExecutionResult
paramsCtx := newParameterCtx(rule, checkResults, util.GetUUID(), time.Now().Format(time.RFC3339))
paramsCtx := newParameterCtx(rule, checkResults, util.GetUUID(), time.Now().UnixNano()/1e6)
if len(rule.Channels.Normal) > 0 {
actionResults, _ = performChannels(rule.Channels.Normal, paramsCtx)
}else if len(rule.Channels.Escalation) > 0{

View File

@ -36,6 +36,8 @@ func dateInZone(fmt string, date interface{}, zone string) string {
t = time.Unix(int64(date), 0)
case int32:
t = time.Unix(int64(date), 0)
case string:
return date
}
loc, err := time.LoadLocation(zone)

View File

@ -4,7 +4,10 @@
package funcs
import "text/template"
import (
"strings"
"text/template"
)
func GenericFuncMap() template.FuncMap {
gfm := make(map[string]interface{}, len(genericMap))
@ -20,4 +23,6 @@ var genericMap = map[string]interface{}{
"to_fixed": toFixed,
"date": date,
"date_in_zone": dateInZone,
"to_upper": strings.ToUpper,
"to_lower": strings.ToLower,
}