Skip to content

Commit e836e99

Browse files
willzgliwillzgli
andauthored
feat(notify): optimize content of message (#2192)
1. change alert time to local time 2. avoid using htlm escape charactors in message Co-authored-by: willzgli <[email protected]>
1 parent ac90ab2 commit e836e99

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

cmd/tke-installer/app/installer/manifests/tke-notify-api/tke-notify-api.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ spec:
6363
mountPath: /app/certs
6464
- name: tke-notify-api-volume
6565
mountPath: /app/conf
66+
- name: timezone
67+
mountPath: /etc/localtime
6668
ports:
6769
- containerPort: 9457
6870
readinessProbe:
@@ -86,14 +88,17 @@ spec:
8688
requests:
8789
cpu: 50m
8890
memory: 128Mi
89-
9091
volumes:
9192
- name: certs-volume
9293
configMap:
9394
name: certs
9495
- name: tke-notify-api-volume
9596
configMap:
9697
name: tke-notify-api
98+
- name: timezone
99+
hostPath:
100+
path: /etc/localtime
101+
97102
---
98103
kind: ConfigMap
99104
apiVersion: v1

pkg/notify/apiserver/handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func getVariables(alert Alert) map[string]string {
231231

232232
evaluateValue, ok := annotations[evaluateValueKey]
233233
if ok {
234-
summary = fmt.Sprintf("%s %s", summary, evaluateValue)
234+
summary = fmt.Sprintf("%s %s%s", summary, evaluateValue, unitValue)
235235
}
236236

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

315315
func processStartTime(t time.Time) string {
316-
return t.Format("2006-01-02T15:04:05Z")
316+
localTime := t.Local()
317+
return localTime.Format(time.RFC3339)
317318
}

pkg/notify/controller/messagerequest/util/util.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"crypto/tls"
2424
"encoding/json"
2525
"fmt"
26+
"html"
2627
htmlTemplate "html/template"
28+
2729
"io/ioutil"
2830
"net/http"
2931
"time"
@@ -93,7 +95,7 @@ func ParseTemplate(name string, template string, variables map[string]string) (s
9395
if err != nil {
9496
return "", err
9597
}
96-
return buffer.String(), nil
98+
return html.UnescapeString(buffer.String()), nil
9799
}
98100

99101
// GetCurrentTime returns current timestamp

0 commit comments

Comments
 (0)