Documentation
¶
Index ¶
- Variables
- type Alert
- type Alerts
- type Config
- type Data
- type KV
- type Option
- type Pair
- type Pairs
- type Template
- func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)
- func (t *Template) AppendTempParams(data *Data)
- func (t *Template) Data(recv string, groupLabels label.LabelSet, alerts ...*alert.Alert) *Data
- func (t *Template) EnableAttachFile(attachments []string, tenantID int) error
- func (t *Template) EnableTplFile(tpl string, tenantID int) error
- func (t *Template) ExecuteHTMLString(html string, data interface{}) (string, error)
- func (t *Template) ExecuteTextString(text string, data interface{}) (string, error)
- func (t *Template) Parse(text string) (*Template, error)
- func (t *Template) ParseDir(path string) (*Template, error)
- func (t *Template) ParseFS(fsys fs.FS, patterns ...string) (*Template, error)
- func (t *Template) ParseFiles(filenames ...string) (*Template, error)
- func (t *Template) ParseGlob(pattern string) (*Template, error)
- func (t *Template) RemoveAttachFile(attachments []string, tenantID int) error
- func (t *Template) RemoveTemplates(tplPath string) error
- func (t *Template) RemoveTplFile(tpl string, tenantID int) error
Constants ¶
This section is empty.
Variables ¶
var DefaultFuncs = map[string]any{ "toUpper": strings.ToUpper, "toLower": strings.ToLower, "title": func(text string) string { return cases.Title(language.AmericanEnglish).String(text) }, "trimSpace": strings.TrimSpace, "join": func(sep string, s []string) string { return strings.Join(s, sep) }, "match": regexp.MatchString, "safeHtml": func(text string) tmplhtml.HTML { return tmplhtml.HTML(text) }, "reReplaceAll": func(pattern, repl, text string) string { re := regexp.MustCompile(pattern) return re.ReplaceAllString(text, repl) }, "stringSlice": func(s ...string) []string { return s }, "markdown": markdownEscapeString, "toJSON": toJson, }
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
Status string `json:"status"`
Labels KV `json:"labels"`
Annotations KV `json:"annotations"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
GeneratorURL string `json:"generatorURL"`
Fingerprint string `json:"fingerprint"`
}
Alert holds one alert for notification templates.
type Alerts ¶
type Alerts []Alert
Alerts is a list of Alert objects.
type Config ¶
type Config struct {
// path for custom template
BaseDir string
// path for active template dir
DataDir string
// path for attachment
AttachmentDir string
}
Config stores configuration for template.
type Data ¶
type Data struct {
Receiver string `json:"receiver"`
Status string `json:"status"`
Alerts Alerts `json:"alerts"`
GroupLabels KV `json:"groupLabels"`
CommonLabels KV `json:"commonLabels"`
CommonAnnotations KV `json:"commonAnnotations"`
ExternalURL string `json:"externalURL"`
}
Data is the data passed to notification templates and webhook pushes.
End-users should not be exposed to Go's type system, as this will confuse them and prevent simple things like simple equality checks to fail. Map everything to float64/string.
type KV ¶
func (KV) SortedPairs ¶
SortedPairs returns a sorted list of key/value pairs.
type Template ¶
type Template struct {
Config
ExternalURL *url.URL
KOSdk *api.SDK
TempParams map[string]map[string]string
// contains filtered or unexported fields
}
Template bundles a text and a html template instance.
func MustParse ¶
MustParse is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil.
func New ¶
New returns a new Template with the DefaultFuncs added. The DefaultFuncs have precedence over any added custom functions. Options allow customization of the text and html templates in given order.
func (*Template) AddParseTree ¶
AddParseTree adds the given parse tree to the template.
func (*Template) AppendTempParams ¶
AppendTempParams appends template params to the alerts.
func (*Template) EnableAttachFile ¶
EnableAttachFile 启用模板文件 tpl 模板地址
func (*Template) EnableTplFile ¶
EnableTplFile 启用模板文件 tpl 模板地址
func (*Template) ExecuteHTMLString ¶
ExecuteHTMLString needs a meaningful doc comment (TODO(fabxc)).
func (*Template) ExecuteTextString ¶
ExecuteTextString needs a meaningful doc comment (TODO(fabxc)).
func (*Template) ParseDir ¶
ParseDir walks on the given dir path and parses the given matches with aren't Go files.
func (*Template) ParseFS ¶
ParseFS is like ParseFiles or ParseGlob but reads from the file system fsys instead of the host operating system's file system.
func (*Template) ParseFiles ¶
ParseFiles parses a list of files as templates and associate them with t. Each file can be a standalone template.
func (*Template) ParseGlob ¶
ParseGlob parses the files that match the given pattern as templates and associate them with t.
func (*Template) RemoveAttachFile ¶
RemoveAttachFile 移除模板文件 tpl 模板地址
func (*Template) RemoveTemplates ¶
RemoveTemplates removes the given templates from the template.