sendSystemAlert sends a system error alert to a single superuser. note: unexported for now until there is clarity around the planned log level alerts.
(app App, superuser *Record, subject string, details string)
| 87 | // |
| 88 | // note: unexported for now until there is clarity around the planned log level alerts. |
| 89 | func sendSystemAlert(app App, superuser *Record, subject string, details string) error { |
| 90 | if !superuser.IsSuperuser() { |
| 91 | return errors.New("system alerts can be sent only to superusers") |
| 92 | } |
| 93 | |
| 94 | if subject == "" || details == "" { |
| 95 | return errors.New("system alerts subject and details are required") |
| 96 | } |
| 97 | |
| 98 | data := struct { |
| 99 | AppName string |
| 100 | AlertDetails string |
| 101 | }{ |
| 102 | AppName: app.Settings().Meta.AppName, |
| 103 | AlertDetails: details, |
| 104 | } |
| 105 | |
| 106 | tpl := template.New("system_alert") |
| 107 | |
| 108 | var parseErr error |
| 109 | tpl, parseErr = tpl.Parse(systemAlertHTML) |
| 110 | if parseErr != nil { |
| 111 | return parseErr |
| 112 | } |
| 113 | |
| 114 | var buff bytes.Buffer |
| 115 | executeErr := tpl.Execute(&buff, data) |
| 116 | if executeErr != nil { |
| 117 | return executeErr |
| 118 | } |
| 119 | |
| 120 | message := &mailer.Message{ |
| 121 | From: mail.Address{ |
| 122 | Name: app.Settings().Meta.SenderName, |
| 123 | Address: app.Settings().Meta.SenderAddress, |
| 124 | }, |
| 125 | To: []mail.Address{{Address: superuser.Email()}}, |
| 126 | Subject: "[" + app.Settings().Meta.AppName + " system alert] " + html.EscapeString(subject), |
| 127 | HTML: buff.String(), |
| 128 | } |
| 129 | |
| 130 | return app.NewMailClient().Send(message) |
| 131 | } |
searching dependent graphs…