notifications: add back app down and app oom mails
This commit is contained in:
+67
-6
@@ -7,8 +7,10 @@ exports = module.exports = {
|
||||
sendNewLoginLocation,
|
||||
|
||||
backupFailed,
|
||||
|
||||
certificateRenewalError,
|
||||
appDown,
|
||||
appUp,
|
||||
oomEvent,
|
||||
|
||||
sendTestMail,
|
||||
|
||||
@@ -40,7 +42,8 @@ async function getMailConfig() {
|
||||
cloudronName,
|
||||
notificationFrom: `"${cloudronName}" <no-reply@${dashboardDomain}>`,
|
||||
supportEmail: 'support@cloudron.io',
|
||||
dashboardFqdn
|
||||
dashboardFqdn,
|
||||
notificationsUrl: `https://${dashboardFqdn}/cloudron/#/notifications`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -182,19 +185,78 @@ async function passwordReset(user, email, resetLink) {
|
||||
await sendMail(mailOptions);
|
||||
}
|
||||
|
||||
async function appDown(mailTo, app) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] App ${app.fqdn} is down`,
|
||||
text: render('app_down.ejs', { title: app.manifest.title, appFqdn: app.fqdn, notificationsUrl: mailConfig.notificationsUrl })
|
||||
};
|
||||
|
||||
await sendMail(mailOptions);
|
||||
}
|
||||
|
||||
async function appUp(mailTo, app) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] App ${app.fqdn} is back online`,
|
||||
text: render('app_up.ejs', { title: app.manifest.title, appFqdn: app.fqdn, notificationsUrl: mailConfig.notificationsUrl })
|
||||
};
|
||||
|
||||
await sendMail(mailOptions);
|
||||
}
|
||||
|
||||
async function oomEvent(mailTo, app, addon, containerId, event) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof addon, 'object');
|
||||
assert.strictEqual(typeof containerId, 'string');
|
||||
assert.strictEqual(typeof event, 'object');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
|
||||
const templateData = {
|
||||
webadminUrl: `https://${mailConfig.dashboardFqdn}`,
|
||||
cloudronName: mailConfig.cloudronName,
|
||||
app,
|
||||
addon,
|
||||
event: JSON.stringify(event),
|
||||
notificationsUrl: mailConfig.notificationsUrl
|
||||
};
|
||||
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] ${app ? app.fqdn : addon.name} was restarted (OOM)`,
|
||||
text: render('oom_event.ejs', templateData)
|
||||
};
|
||||
|
||||
await sendMail(mailOptions);
|
||||
}
|
||||
|
||||
async function backupFailed(mailTo, errorMessage, logUrl) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof errorMessage, 'string');
|
||||
assert.strictEqual(typeof logUrl, 'string');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
const notificationsUrl = `https://${mailConfig.dashboardFqdn}/cloudron/#/notifications`;
|
||||
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] Failed to backup`,
|
||||
text: render('backup_failed.ejs', { cloudronName: mailConfig.cloudronName, message: errorMessage, logUrl, notificationsUrl })
|
||||
text: render('backup_failed.ejs', { cloudronName: mailConfig.cloudronName, message: errorMessage, logUrl, notificationsUrl: mailConfig.notificationsUrl })
|
||||
};
|
||||
|
||||
await sendMail(mailOptions);
|
||||
@@ -206,13 +268,12 @@ async function certificateRenewalError(mailTo, domain, message) {
|
||||
assert.strictEqual(typeof message, 'string');
|
||||
|
||||
const mailConfig = await getMailConfig();
|
||||
const notificationsUrl = `https://${mailConfig.dashboardFqdn}/cloudron/#/notifications`;
|
||||
|
||||
const mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] Certificate renewal error`,
|
||||
text: render('certificate_renewal_error.ejs', { domain, message, notificationsUrl })
|
||||
text: render('certificate_renewal_error.ejs', { domain, message, notificationsUrl: mailConfig.notificationsUrl })
|
||||
};
|
||||
|
||||
await sendMail(mailOptions);
|
||||
|
||||
Reference in New Issue
Block a user