diff --git a/CHANGES b/CHANGES index 552954bb8..42dbfd647 100644 --- a/CHANGES +++ b/CHANGES @@ -2171,4 +2171,5 @@ * cloudron-setup: add --generate-setup-token * dashboard: pass accessToken query param to automatically login * wellknown: add a way to set well known docs +* oom: notification mails have links to dashboard diff --git a/src/mail_templates/oom_event.ejs b/src/mail_templates/oom_event.ejs index 1d78baee4..74575edb2 100644 --- a/src/mail_templates/oom_event.ejs +++ b/src/mail_templates/oom_event.ejs @@ -2,12 +2,13 @@ Dear <%= cloudronName %> Admin, -<%= program %> was restarted now as it ran out of memory. - -If this message appears repeatedly, give the app more memory. - -* To increase an app's memory limit - https://docs.cloudron.io/apps/#memory-limit -* To increase a service's memory limit - https://docs.cloudron.io/troubleshooting/#services +<%if (app) { %> +The application at <%= app.fqdn %> ran out of memory. The application has been restarted automatically. If you see this notification often, +consider increasing the memory limit - <%= webadminUrl %>/#/app/<%= app.id %>/resources . +<% } else { %> +The addon <%= addon.name %> service ran out of memory. The service has been restarted automatically. If you see this notification often, +consider increasing the memory limit - <%= webadminUrl %>/#/services . +<% } %> Out of memory event: diff --git a/src/mailer.js b/src/mailer.js index cca5043b0..622013cfe 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -33,8 +33,7 @@ var assert = require('assert'), settings = require('./settings.js'), showdown = require('showdown'), translation = require('./translation.js'), - smtpTransport = require('nodemailer-smtp-transport'), - util = require('util'); + smtpTransport = require('nodemailer-smtp-transport'); var NOOP_CALLBACK = function (error) { if (error) debug(error); }; @@ -386,19 +385,30 @@ function boxUpdateError(mailTo, message) { }); } -function oomEvent(mailTo, program, event) { +function oomEvent(mailTo, app, addon, containerId, event) { assert.strictEqual(typeof mailTo, 'string'); - assert.strictEqual(typeof program, 'string'); + assert.strictEqual(typeof app, 'object'); + assert.strictEqual(typeof addon, 'object'); + assert.strictEqual(typeof containerId, 'string'); assert.strictEqual(typeof event, 'object'); getMailConfig(function (error, mailConfig) { if (error) return debug('Error getting mail details:', error); + const templateData = { + webadminUrl: settings.adminOrigin(), + cloudronName: mailConfig.cloudronName, + app, + addon, + event: JSON.stringify(event), + format: 'text' + }; + var mailOptions = { from: mailConfig.notificationFrom, to: mailTo, - subject: `[${mailConfig.cloudronName}] ${program} was restarted (OOM)`, - text: render('oom_event.ejs', { cloudronName: mailConfig.cloudronName, program: program, event: JSON.stringify(event), format: 'text' }) + subject: `[${mailConfig.cloudronName}] ${app ? app.fqdn : addon.name} was restarted (OOM)`, + text: render('oom_event.ejs', templateData) }; sendMail(mailOptions); diff --git a/src/notifications.js b/src/notifications.js index adb992dd7..d71c451a0 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -154,23 +154,19 @@ function oomEvent(eventId, app, addon, containerId, event, callback) { assert.strictEqual(typeof containerId, 'string'); assert.strictEqual(typeof callback, 'function'); - let title, message, program; + assert(app || addon); + + let title, message; if (app) { - program = `App ${app.fqdn}`; title = `The application at ${app.fqdn} ran out of memory.`; - message = 'The application has been restarted automatically. If you see this notification often, consider increasing the [memory limit](https://docs.cloudron.io/apps/#memory-limit)'; + message = `The application has been restarted automatically. If you see this notification often, consider increasing the [memory limit](${settings.adminOrigin()}/#/app/${app.id}/resources)`; } else if (addon) { - program = `${addon.name} service`; title = `The ${addon.name} service ran out of memory`; - message = 'The service has been restarted automatically. If you see this notification often, consider increasing the [memory limit](https://docs.cloudron.io/troubleshooting/#services)'; - } else { // this never happens currently - program = `Container ${containerId}`; - title = `The container ${containerId} ran out of memory`; - message = 'The container has been restarted automatically. Consider increasing the [memory limit](https://docs.docker.com/v17.09/edge/engine/reference/commandline/update/#update-a-containers-kernel-memory-constraints)'; + message = `The service has been restarted automatically. If you see this notification often, consider increasing the [memory limit](${settings.adminOrigin()}/#/services)`; } forEachAdmin({ skip: [] }, function (admin, done) { - mailer.oomEvent(admin.email, program, event); + mailer.oomEvent(admin.email, app, addon, containerId, event); add(admin.id, eventId, title, message, done); }, callback);