Send oom email to cloudron admins

Part of #166
This commit is contained in:
Girish Ramakrishnan
2017-01-07 13:52:32 -08:00
parent 8a05fdcb10
commit 3f3b97dc16
3 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ function processDockerEvents() {
// do not send mails for dev apps
if ((!app || app.appStoreId !== '') && (now - lastOomMailTime > OOM_MAIL_LIMIT)) {
mailer.unexpectedExit(program, context); // app can be null if it's an addon crash
mailer.oomEvent(program, context); // app can be null if it's an addon crash
lastOomMailTime = now;
}
});
+19
View File
@@ -0,0 +1,19 @@
<%if (format === 'text') { %>
Dear Cloudron Team,
Unfortunately <%= program %> on <%= fqdn %> exited unexpectedly!
Please see some excerpt of the logs below.
Thank you,
Your Cloudron
-------------------------------------
<%- context %>
<% } else { %>
<% } %>
+19
View File
@@ -15,6 +15,7 @@ exports = module.exports = {
unexpectedExit: unexpectedExit,
appDied: appDied,
oomEvent: oomEvent,
outOfDiskSpace: outOfDiskSpace,
backupFailed: backupFailed,
@@ -499,6 +500,24 @@ function certificateRenewalError(domain, message) {
});
}
function oomEvent(program, context) {
assert.strictEqual(typeof program, 'string');
assert.strictEqual(typeof context, 'string');
getAdminEmails(function (error, adminEmails) {
if (error) return console.log('Error getting admins', error);
var mailOptions = {
from: mailConfig().from,
to: config.provider() === 'caas' ? 'support@cloudron.io' : adminEmails.concat('support@cloudron.io').join(', '),
subject: util.format('[%s] %s exited unexpectedly', config.fqdn(), program),
text: render('oom_event.ejs', { fqdn: config.fqdn(), program: program, context: context, format: 'text' })
};
sendMails([ mailOptions ]);
});
}
// this function bypasses the queue intentionally. it is also expected to work without the mailer module initialized
// NOTE: crashnotifier should be able to send mail when there is no db
function unexpectedExit(program, context) {