diff --git a/lib/notifier.js b/lib/notifier.js index 333b9138..20bb6024 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -18,6 +18,23 @@ function sameState (a, b) { return a.note.sessionId === b.note.sessionId && a.note.state === b.note.state } +function checkPing (deviceEvents) { + var sortedEvents = R.sortBy(R.compose(toInt10, R.prop('device_time')), R.map(jsonParse, deviceEvents)) + var lastEvent = R.last(sortedEvents) + var NETWORK_DOWN_TIME = 2 * 60 * 1000 + + if (!lastEvent) { + console.log('No data for device') + return + } + + if (lastEvent.age > NETWORK_DOWN_TIME) { + return console.log('Device not reachable [ALERT]') + } + + console.log('Device reachable [OK]') +} + function checkStuckScreen (deviceEvents) { var sortedEvents = R.sortBy(R.compose(toInt10, R.prop('device_time')), R.map(jsonParse, deviceEvents)) var noRepeatEvents = R.dropRepeatsWith(sameState, sortedEvents) @@ -72,6 +89,7 @@ function checkStatus () { console.log('DEVICE: ' + deviceRow.fingerprint) checkStuckScreen(deviceEvents) + checkPing(deviceEvents) }) }) })