// Copyright 2019 Yunion // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package templates import "yunion.io/x/onecloud/pkg/apis/monitor" type TemplateConfig struct { monitor.NotificationTemplateConfig } func NewTemplateConfig(c monitor.NotificationTemplateConfig) *TemplateConfig { return &TemplateConfig{ NotificationTemplateConfig: c, } } const DefaultMarkdownTemplate = ` ## {{.Title}} - 时间: {{.StartTime}} - 级别: {{.Level}} {{- if .Reason}} - 原因: {{.Reason}} {{- end}} {{ range .Matches}} - 指标: {{.Metric}} - 触发值: {{.ValueStr}} ### 触发条件: - {{ $.Description}} ### 标签 > 名称: {{ GetValFromMap .Tags "name" }} > ip: {{ GetValFromMap .Tags "ip" }} > 平台: {{ GetValFromMap .Tags "brand" }} ------ {{- end}} ` func (c TemplateConfig) GenerateMarkdown() (string, error) { return CompileTEmplateFromMapText(DefaultMarkdownTemplate, c) } func (c TemplateConfig) GenerateEmailMarkdown() (string, error) { return CompileTemplateFromMapHtml(EmailMarkdownTemplate, c) } const EmailMarkdownTemplate = `
| 报警信息 | |||
| 报警策略: | {{.Name}} | ||
| 报警级别: | {{.Level}} | ||
| 报警时间: | {{.StartTime}} | ||
| 策略详情: | {{.Description}} | ||
| 报警原因: | {{.Reason}} | ||
| 若要查看详情信息,请登录平台进行查看 |
| 报警资源 | |||||||||||||
|
|||||||||||||
本邮件由系统自动发送,请勿直接回复!
`