-
Notifications
You must be signed in to change notification settings - Fork 53
/
message.go
37 lines (30 loc) · 1.11 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package templates
import (
"fmt"
"github.com/rancher/opni/pkg/alerting/shared"
alertingv1 "github.com/rancher/opni/pkg/apis/alerting/v1"
)
func iterateAlerts(innerTemplate string) string {
return fmt.Sprintf("{{ $renderItem := len .Alerts | ne 1 }}{{ range $i, $val := .Alerts }}%s{{ end }}", innerTemplate)
}
func messageHeader() string {
return fmt.Sprintf(
`{{ if $renderItem }}({{$i}}) : {{ end }}{{if .Annotations.%s}}Alarm "{{ .Annotations.%s }}" [{{ .Status }}]{{else}}Notification "{{ .Annotations.%s }}" {{end}}`,
shared.OpniAlarmNameAnnotation,
shared.OpniAlarmNameAnnotation,
shared.OpniHeaderAnnotations,
)
}
func genericMessageTitle() string {
return fmt.Sprintf(
"[{{ .Labels.%s }}] -- {{ .StartsAt | formatTime }}\n",
alertingv1.NotificationPropertySeverity,
// time.RFC822,
)
}
func HeaderTemplate() string {
return iterateAlerts(messageHeader() + " " + genericMessageTitle())
}
func BodyTemplate() string {
return iterateAlerts(fmt.Sprintf("{{ if $renderItem }}({{$i}}) : {{ end }}{{ .Annotations.%s }} : {{ .Annotations.%s }}\n", shared.OpniHeaderAnnotations, shared.OpniBodyAnnotations))
}