WIP
This commit is contained in:
parent
f48ce99744
commit
eba5d13a36
1 changed files with 26 additions and 22 deletions
|
|
@ -23,10 +23,10 @@ function sameState (a, b) {
|
||||||
function checkBalance () {
|
function checkBalance () {
|
||||||
var LOW_BALANCE_THRESHOLD = 10
|
var LOW_BALANCE_THRESHOLD = 10
|
||||||
if (getBalance() < LOW_BALANCE_THRESHOLD) {
|
if (getBalance() < LOW_BALANCE_THRESHOLD) {
|
||||||
return console.log('Bitcoin balance is low [ALERT]')
|
return [{code: 'lowBitcoinBalance'}]
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Bitcoin balance ok [OK]')
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPing (deviceEvents) {
|
function checkPing (deviceEvents) {
|
||||||
|
|
@ -35,15 +35,14 @@ function checkPing (deviceEvents) {
|
||||||
var NETWORK_DOWN_TIME = 2 * 60 * 1000
|
var NETWORK_DOWN_TIME = 2 * 60 * 1000
|
||||||
|
|
||||||
if (!lastEvent) {
|
if (!lastEvent) {
|
||||||
console.log('No data for device')
|
return []
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastEvent.age > NETWORK_DOWN_TIME) {
|
if (lastEvent.age > NETWORK_DOWN_TIME) {
|
||||||
return console.log('Device not reachable [ALERT]')
|
return [{code: 'ping'}]
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Device reachable [OK]')
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStuckScreen (deviceEvents) {
|
function checkStuckScreen (deviceEvents) {
|
||||||
|
|
@ -54,26 +53,23 @@ function checkStuckScreen (deviceEvents) {
|
||||||
var STALE_STATE = 60 * 1000
|
var STALE_STATE = 60 * 1000
|
||||||
|
|
||||||
if (!lastEvent) {
|
if (!lastEvent) {
|
||||||
console.log('No data for device')
|
return []
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = lastEvent.note.state
|
var state = lastEvent.note.state
|
||||||
if (R.contains(state, IDLE_STATES)) {
|
if (R.contains(state, IDLE_STATES)) {
|
||||||
console.log('Machine is idle [OK]')
|
return []
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(lastEvent.age)
|
console.log(lastEvent.age)
|
||||||
if (lastEvent.age > STALE_STATE) {
|
if (lastEvent.age > STALE_STATE) {
|
||||||
console.log('Stale state: ' + state + ' [ALERT]')
|
return [{code: 'stale', state: state}]
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[OK]')
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStatus () {
|
function checkStatus (cb) {
|
||||||
/*
|
/*
|
||||||
- Fetch devices from devices table
|
- Fetch devices from devices table
|
||||||
- Fetch all machine_events into memory
|
- Fetch all machine_events into memory
|
||||||
|
|
@ -82,18 +78,20 @@ function checkStatus () {
|
||||||
- last screen is >5m stale and is not idle screen
|
- last screen is >5m stale and is not idle screen
|
||||||
- report stuck on screen and name of screen
|
- report stuck on screen and name of screen
|
||||||
- not scanning qr codes?
|
- not scanning qr codes?
|
||||||
- low bitcoins -- need a separate strategy, but server has this info
|
v low bitcoins -- need a separate strategy, but server has this info
|
||||||
- var fiatBalance = plugins.fiatBalance();
|
- var fiatBalance = plugins.fiatBalance();
|
||||||
v machine isn't pinging server
|
v machine isn't pinging server
|
||||||
- jam checking, need report from l-m
|
- jam checking, need report from l-m [next release]
|
||||||
*/
|
*/
|
||||||
checkBalance()
|
var alerts = []
|
||||||
|
|
||||||
|
alerts = R.concat(alerts, checkBalance())
|
||||||
|
|
||||||
db.devices(function (err, devices) {
|
db.devices(function (err, devices) {
|
||||||
if (err) return console.error(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
db.machineEvents(function (err, events) {
|
db.machineEvents(function (err, events) {
|
||||||
if (err) return console.error(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
devices.rows.forEach(function (deviceRow) {
|
devices.rows.forEach(function (deviceRow) {
|
||||||
var deviceFingerprint = deviceRow.fingerprint
|
var deviceFingerprint = deviceRow.fingerprint
|
||||||
|
|
@ -102,8 +100,10 @@ function checkStatus () {
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('DEVICE: ' + deviceRow.fingerprint)
|
console.log('DEVICE: ' + deviceRow.fingerprint)
|
||||||
checkStuckScreen(deviceEvents)
|
alerts = R.concat(alerts, checkStuckScreen(deviceRow, deviceEvents))
|
||||||
checkPing(deviceEvents)
|
alerts = R.concat(alerts, checkPing(deviceRow, deviceEvents))
|
||||||
|
|
||||||
|
// TODO: Use promises to do this right
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -119,7 +119,11 @@ var _getBalance = function () {
|
||||||
_db.init(connectionString)
|
_db.init(connectionString)
|
||||||
init(_db, _getBalance)
|
init(_db, _getBalance)
|
||||||
|
|
||||||
checkStatus()
|
checkStatus(function (err, alerts) {
|
||||||
|
if (err) console.log(err)
|
||||||
|
console.log('DEBUG1')
|
||||||
|
console.log(alerts)
|
||||||
|
})
|
||||||
|
|
||||||
// TODO: How to know which alerts have been sent?
|
// TODO: How to know which alerts have been sent?
|
||||||
// Send alert every 10m while alert state
|
// Send alert every 10m while alert state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue