Skip to content

Commit

Permalink
feat(notify): optimize content of message (#2191)
Browse files Browse the repository at this point in the history
1. change alert time to local time
2. avoid using htlm escape charactors in message

Co-authored-by: willzgli <willzgli@tencent.com>
  • Loading branch information
willzgli and willzgli committed Dec 1, 2022
1 parent 6dac2a0 commit a89b67b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Expand Up @@ -63,6 +63,8 @@ spec:
mountPath: /app/certs
- name: tke-notify-api-volume
mountPath: /app/conf
- name: timezone
mountPath: /etc/localtime
ports:
- containerPort: 9457
readinessProbe:
Expand All @@ -86,14 +88,17 @@ spec:
requests:
cpu: 50m
memory: 128Mi

volumes:
- name: certs-volume
configMap:
name: certs
- name: tke-notify-api-volume
configMap:
name: tke-notify-api
- name: timezone
hostPath:
path: /etc/localtime

---
kind: ConfigMap
apiVersion: v1
Expand Down
5 changes: 3 additions & 2 deletions pkg/notify/apiserver/handler.go
Expand Up @@ -231,7 +231,7 @@ func getVariables(alert Alert) map[string]string {

evaluateValue, ok := annotations[evaluateValueKey]
if ok {
summary = fmt.Sprintf("%s %s", summary, evaluateValue)
summary = fmt.Sprintf("%s %s%s", summary, evaluateValue, unitValue)
}

alarmPolicyNameValue, ok := labels["alarmPolicyName"]
Expand Down Expand Up @@ -313,5 +313,6 @@ func getVariables(alert Alert) map[string]string {
}

func processStartTime(t time.Time) string {
return t.Format("2006-01-02T15:04:05Z")
localTime := t.Local()
return localTime.Format(time.RFC3339)
}
4 changes: 3 additions & 1 deletion pkg/notify/controller/messagerequest/util/util.go
Expand Up @@ -23,7 +23,9 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"html"
htmlTemplate "html/template"

"io/ioutil"
"net/http"
"time"
Expand Down Expand Up @@ -93,7 +95,7 @@ func ParseTemplate(name string, template string, variables map[string]string) (s
if err != nil {
return "", err
}
return buffer.String(), nil
return html.UnescapeString(buffer.String()), nil
}

// GetCurrentTime returns current timestamp
Expand Down

0 comments on commit a89b67b

Please sign in to comment.