Show machine names on SMS notifications

This commit is contained in:
Rafael Taranto 2019-05-09 00:14:54 -03:00 committed by Josh Harvey
parent 67919892e8
commit c80d8ddb08

View file

@ -73,13 +73,12 @@ function checkNotification (plugins) {
lastAlertTime - Date.now() < ALERT_SEND_INTERVAL
if (alertChanged) return
const subject = alertSubject(alertRec)
const rec = {
sms: {
body: subject
body: printSmsAlerts(alertRec)
},
email: {
subject,
subject: alertSubject(alertRec),
body: printEmailAlerts(alertRec)
}
}
@ -225,6 +224,18 @@ function printEmailAlerts (alertRec) {
function alertSubject (alertRec) {
let alerts = alertRec.general
_.keys(alertRec.devices).forEach(function (device) {
alerts = _.concat(alerts, alertRec.devices[device])
})
const alertTypes = _.map(codeDisplay, _.uniq(_.map('code', alerts))).sort()
return '[Lamassu] Errors reported: ' + alertTypes.join(', ')
}
function printSmsAlerts (alertRec) {
let alerts = alertRec.general
_.keys(alertRec.devices).forEach(function (device) {
alerts = _.concat(alerts, alertRec.devices[device])
})
@ -243,12 +254,11 @@ function alertSubject (alertRec) {
}
}, _.toPairs(alertsMap))
const sortedAlertTypes = _.sortBy('codeDisplay', alertTypes)
const mapByCodeDisplay = _.map(it => _.isEmpty(it.machineNames)
? it.codeDisplay : `${it.codeDisplay} (${it.machineNames.join(', ')})`
)
const displayAlertTypes = _.uniq(_.map(alertType => _.isEmpty(alertType.machineNames.length)
? alertType.codeDisplay
: `${alertType.codeDisplay} (${alertType.machineNames.join(', ')})`
, sortedAlertTypes))
const displayAlertTypes = _.compose(_.uniq, mapByCodeDisplay, _.sortBy('codeDisplay'))(alertTypes)
return '[Lamassu] Errors reported: ' + displayAlertTypes.join(', ')
}