forked from openhab/openhab-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.js
54 lines (50 loc) · 1.54 KB
/
health.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var system = require('../system');
var mongoose = require('mongoose');
const Errors = {
DBERROR: 'DBERROR'
}
exports.gethealth = function (req, res) {
const isHealthEndpointEnabled = system.isHealthEndpointEnabled();
if (!isHealthEndpointEnabled) {
return res.status(404).send("not found");
} else {
const mongoose_state = mongoose.connection.readyState
var errors = collectErrors();
if (errors.length == 0) {
return res.status(200).json({
status: "OK",
mongoose: mongoose_state
});
} else {
return res.status(500).json({
status: "Not OK",
mongoose: mongoose_state,
errors: errors
});
}
function collectErrors() {
var errors = [];
switch (mongoose_state) {
case 0:
errors.push({
error: Errors.DBERROR,
message: "mongodb disconnected"
});
break;
case 2:
errors.push({
error: Errors.DBERROR,
message: "mongodb connecting"
});
break;
case 3:
errors.push({
error: Errors.DBERROR,
message: "mongodb disconnecting"
});
break;
};
return errors;
}
}
};