notifications: per user email prefs
This commit is contained in:
+7
-12
@@ -24,7 +24,7 @@ exports = module.exports = {
|
||||
TYPE_REBOOT: 'reboot',
|
||||
TYPE_UPDATE_UBUNTU: 'ubuntuUpdate',
|
||||
TYPE_BOX_UPDATE: 'boxUpdate',
|
||||
TYPE_MANUAL_APP_UPDATE_NEEDED: 'manualAppUpdate-',
|
||||
TYPE_MANUAL_APP_UPDATE_NEEDED: 'manualAppUpdate',
|
||||
|
||||
// these work off singleton types
|
||||
pin,
|
||||
@@ -212,7 +212,9 @@ async function certificateRenewalError(eventId, fqdn, errorMessage) {
|
||||
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
await mailer.certificateRenewalError(admin.email, fqdn, errorMessage);
|
||||
if (admin.notificationConfig.includes(exports.TYPE_CERTIFICATE_RENEWAL_FAILED)) {
|
||||
await mailer.certificateRenewalError(admin.email, fqdn, errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,19 +225,12 @@ async function backupFailed(eventId, taskId, errorMessage) {
|
||||
|
||||
await add(exports.TYPE_BACKUP_FAILED, 'Backup failed', `Backup failed: ${errorMessage}. Logs are available [here](/logs.html?taskId=${taskId}).`, { eventId });
|
||||
|
||||
// only send mail if the past 3 automated backups failed
|
||||
const backupEvents = await eventlog.listPaged([eventlog.ACTION_BACKUP_FINISH], null /* search */, 1, 20);
|
||||
let count = 0;
|
||||
for (const event of backupEvents) {
|
||||
if (!event.data.errorMessage) return; // successful backup (manual or cron)
|
||||
if (event.source.username === AuditSource.CRON.username && ++count === 3) break; // last 3 consecutive crons have failed
|
||||
}
|
||||
if (count !== 3) return; // less than 3 failures
|
||||
|
||||
const { fqdn:dashboardFqdn } = await dashboard.getLocation();
|
||||
const superadmins = await users.getSuperadmins();
|
||||
for (const superadmin of superadmins) {
|
||||
await mailer.backupFailed(superadmin.email, errorMessage, `https://${dashboardFqdn}/logs.html?taskId=${taskId}`);
|
||||
if (superadmin.notificationConfig.includes(exports.TYPE_BACKUP_FAILED)) {
|
||||
await mailer.backupFailed(superadmin.email, errorMessage, `https://${dashboardFqdn}/logs.html?taskId=${taskId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user