add ping check

This commit is contained in:
Josh Harvey 2016-02-14 20:08:51 +02:00
parent 056d035805
commit 12a1dcbf9a

View file

@ -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)
})
})
})