@ -19,13 +19,25 @@ func init() {
Description : "Sends notifications using Grafana server configured SMTP settings" ,
Factory : NewEmailNotifier ,
OptionsTemplate : `
< h3 class = "page-heading" > Email addresses < / h3 >
< div class = "gf-form" >
< textarea rows = "7" class = "gf-form-input width-27" required ng - model = "ctrl.model.settings.addresses" > < / textarea >
< / div >
< div class = "gf-form" >
< span > You can enter multiple email addresses using a ";" separator < / span >
< / div >
< h3 class = "page-heading" > Email settings < / h3 >
< div class = "gf-form" >
< gf - form - switch
class = "gf-form"
label = "Single email"
label - class = "width-8"
checked = "ctrl.model.settings.singleEmail"
tooltip = "Send a single email to all recipients" >
< / gf - form - switch >
< / div >
< div class = "gf-form" >
< label class = "gf-form-label width-8" >
Addresses
< / label >
< textarea rows = "7" class = "gf-form-input width-27" required ng - model = "ctrl.model.settings.addresses" > < / textarea >
< / div >
< div class = "gf-form offset-width-8" >
< span > You can enter multiple email addresses using a ";" separator < / span >
< / div >
` ,
} )
}
@ -34,14 +46,16 @@ func init() {
// alert notifications over email.
type EmailNotifier struct {
NotifierBase
Addresses [ ] string
log log . Logger
Addresses [ ] string
SingleEmail bool
log log . Logger
}
// NewEmailNotifier is the constructor function
// for the EmailNotifier.
func NewEmailNotifier ( model * models . AlertNotification ) ( alerting . Notifier , error ) {
addressesString := model . Settings . Get ( "addresses" ) . MustString ( )
singleEmail := model . Settings . Get ( "singleEmail" ) . MustBool ( false )
if addressesString == "" {
return nil , alerting . ValidationError { Reason : "Could not find addresses in settings" }
@ -53,13 +67,14 @@ func NewEmailNotifier(model *models.AlertNotification) (alerting.Notifier, error
return & EmailNotifier {
NotifierBase : NewNotifierBase ( model ) ,
Addresses : addresses ,
SingleEmail : singleEmail ,
log : log . New ( "alerting.notifier.email" ) ,
} , nil
}
// Notify sends the alert notification.
func ( en * EmailNotifier ) Notify ( evalContext * alerting . EvalContext ) error {
en . log . Info ( "Sending alert notification to" , "addresses" , en . Addresses )
en . log . Info ( "Sending alert notification to" , "addresses" , en . Addresses , "singleEmail" , en . SingleEmail )
ruleURL , err := evalContext . GetRuleURL ( )
if err != nil {
@ -89,6 +104,7 @@ func (en *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
"EvalMatches" : evalContext . EvalMatches ,
} ,
To : en . Addresses ,
SingleEmail : en . SingleEmail ,
Template : "alert_notification.html" ,
EmbededFiles : [ ] string { } ,
} ,