Skip to content

Commit

Permalink
feat: Health check endpoints #264
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Feb 19, 2020
1 parent 648da43 commit 3396b75
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@ app.startSocket = function (server) {

// ----- APIs ------

app.get('/health', async function (req, res) {

var mqtt = false
var zwave = false

if(gw) {
mqtt = gw.mqtt ? gw.mqtt.getStatus().status : false
zwave = gw.zwave ? gw.zwave.getStatus().status : false
}

var status = mqtt && zwave

res.status(status ? 200 : 500).send(status ? 'Ok' : 'Error')
})

app.get('/health/:client', async function (req, res) {
var client = req.params.client


if(client !== 'zwave' && client !== 'mqtt')
res.status(500).send('Requested client doesn \'t exist')
else {
status = gw && gw[client] ? gw[client].getStatus().status : false
}

res.status(status ? 200 : 500).send(status ? 'Ok' : 'Error')
})


//get settings
app.get('/api/settings', async function (req, res) {
var data = { success: true, settings: jsonStore.get(store.settings), devices: gw.zwave ? gw.zwave.devices : {}, serial_ports: [] }
Expand Down
9 changes: 9 additions & 0 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,15 @@ ZwaveClient.prototype.close = function () {
}
}

ZwaveClient.prototype.getStatus = function () {
var status = {}

status.status = this.connected
status.config = this.config

return status
}

/**
* Inits a Zwave node object with give nodeinfo object
* Overrides `name` and `loc` properties and add node specific `hassDevices` using info stored in `nodes.json`
Expand Down

0 comments on commit 3396b75

Please sign in to comment.