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