mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-27 16:43:41 +00:00
Fix inverted cleanup trigger, proper mail notifications
This commit is contained in:
parent
4b49350122
commit
e77bda4e9f
@ -41,7 +41,6 @@ var (
|
||||
Templates: EmailTemplates{
|
||||
Header: "email.default.header",
|
||||
HTML: "email.default.html",
|
||||
Plain: "email.default.plain",
|
||||
},
|
||||
}
|
||||
)
|
||||
@ -84,7 +83,6 @@ type EmailConfig struct {
|
||||
type EmailTemplates struct {
|
||||
Header string `yaml:"header"`
|
||||
HTML string `yaml:"html"`
|
||||
Plain string `yaml:"plain"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||
|
@ -56,7 +56,7 @@ func (d *Dispatcher) Run() {
|
||||
}
|
||||
|
||||
func (d *Dispatcher) run(it provider.AlertIterator) {
|
||||
cleanup := time.NewTicker(5 * time.Minute)
|
||||
cleanup := time.NewTicker(30 * time.Second)
|
||||
defer cleanup.Stop()
|
||||
|
||||
defer it.Close()
|
||||
@ -140,7 +140,7 @@ func (d *Dispatcher) processAlert(alert *types.Alert, opts *RouteOpts) {
|
||||
if err != nil {
|
||||
log.Errorf("Notify for %d alerts failed: %s %T", len(alerts), err, err)
|
||||
}
|
||||
return err != nil
|
||||
return err == nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -175,8 +175,6 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugln("sending mail", n.conf.Email, c)
|
||||
|
||||
// Send the email body.
|
||||
wc, err := c.Data()
|
||||
if err != nil {
|
||||
@ -184,18 +182,26 @@ func (n *Email) Notify(ctx context.Context, as ...*types.Alert) error {
|
||||
}
|
||||
defer wc.Close()
|
||||
|
||||
data := struct {
|
||||
Alerts model.Alerts
|
||||
From string
|
||||
To string
|
||||
Date string
|
||||
}{
|
||||
Alerts: types.Alerts(as...),
|
||||
From: n.conf.Sender,
|
||||
To: n.conf.Email,
|
||||
Date: time.Now().Format(time.RFC1123Z),
|
||||
groupLabels, ok := GroupLabels(ctx)
|
||||
if !ok {
|
||||
log.Error("missing group labels")
|
||||
}
|
||||
|
||||
data := struct {
|
||||
Alerts model.Alerts
|
||||
GroupLabels model.LabelSet
|
||||
From string
|
||||
To string
|
||||
Date string
|
||||
}{
|
||||
Alerts: types.Alerts(as...),
|
||||
GroupLabels: groupLabels,
|
||||
From: n.conf.Sender,
|
||||
To: n.conf.Email,
|
||||
Date: time.Now().Format(time.RFC1123Z),
|
||||
}
|
||||
|
||||
// Expand the mail header first without HTML escaping
|
||||
if err := n.tmpl.ExecuteText(wc, n.conf.Templates.Header, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -23,17 +23,37 @@ my text
|
||||
{{ define "email.default.header" }}From: "Prometheus Alertmanager" <{{ .From }}>
|
||||
To: {{ .To }}
|
||||
Date: {{ .Date }}
|
||||
Subject: [{{ .Alerts.Status }}]
|
||||
{{ end }}
|
||||
|
||||
{{ define "email.default.plain" }}
|
||||
{{ range .Alerts }}
|
||||
{{ .String }}
|
||||
{{ end }}
|
||||
Subject: [{{ .Alerts.Status }}] {{ .GroupLabels }}
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
{{ end }}
|
||||
|
||||
{{ define "email.default.html" }}
|
||||
<h1 style="font-size: 115%">{{ len .Alerts }} alert(s) for {{ .GroupLabels }}</h1>
|
||||
|
||||
{{ range .Alerts }}
|
||||
{{ .String }}
|
||||
<div style="
|
||||
padding: 18px;
|
||||
margin-top: 7px;
|
||||
border: 1px solid #bbb;
|
||||
">
|
||||
<strong>{{ .Status }}</strong><br>
|
||||
<div style="float: left; min-width: 150px;">
|
||||
<em>Labels</em><br>
|
||||
<ul>
|
||||
{{range $label, $value := .Labels}}
|
||||
<li>{{$label}}: {{$value}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
<div style="float: left; margin-left: 15px">
|
||||
<em>Annotations</em><br>
|
||||
<ul>
|
||||
{{ range $label, $value := .Annotations }}
|
||||
<li>{{ $label }}: {{ $value }}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user