diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js index 493c3c24d..5dc9f97e5 100644 --- a/src/apphealthmonitor.js +++ b/src/apphealthmonitor.js @@ -8,6 +8,7 @@ var appdb = require('./appdb.js'), debug = require('debug')('box:apphealthmonitor'), docker = require('./docker.js').connection, mailer = require('./mailer.js'), + notifications = require('./notifications.js'), superagent = require('superagent'), util = require('util'); @@ -144,7 +145,7 @@ function processDockerEvents(intervalSecs, callback) { // do not send mails for dev apps if (notifyUser) { - mailer.oomEvent(program, context); // app can be null if it's an addon crash + notifications.oomEvent(program, context); // app can be null if it's an addon crash gLastOomMailTime = now; } }); diff --git a/src/notifications.js b/src/notifications.js index e568086e3..a4849e7d0 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -9,7 +9,8 @@ exports = module.exports = { getAllPaged: getAllPaged, // specialized notifications - userAdded: userAdded + userAdded: userAdded, + oomEvent: oomEvent }; var assert = require('assert'), @@ -126,3 +127,20 @@ function userAdded(user, callback) { }, callback); }); } + +function oomEvent(program, context, callback) { + assert.strictEqual(typeof program, 'string'); + assert.strictEqual(typeof context, 'string'); + assert(typeof callback === 'undefined' || typeof callback === 'function'); + + callback = callback || NOOP_CALLBACK; + + users.getAllAdmins(function (error, result) { + if (error) return callback(new NotificationsError(NotificationsError.INTERNAL_ERROR, error)); + + async.each(result, function (admin, callback) { + mailer.oomEvent(program, context); + add(admin.id, program, context, '', callback); + }, callback); + }); +}