feat: Add a "manual" (static/fixed) monitor (#5897)
Co-authored-by: Maksim Kachynski <max.kachinsky@rocketdata.io> Co-authored-by: Frank Elsinga <frank@elsinga.de>pull/5871/head^2
parent
f282422b22
commit
18cfa901ad
@ -0,0 +1,12 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema
|
||||
.alterTable("monitor", function (table) {
|
||||
table.string("manual_status").defaultTo(null);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.alterTable("monitor", function (table) {
|
||||
table.dropColumn("manual_status");
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,36 @@
|
||||
const { MonitorType } = require("./monitor-type");
|
||||
const { UP, DOWN, PENDING } = require("../../src/util");
|
||||
|
||||
class ManualMonitorType extends MonitorType {
|
||||
name = "Manual";
|
||||
type = "manual";
|
||||
description = "A monitor that allows manual control of the status";
|
||||
supportsConditions = false;
|
||||
conditionVariables = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async check(monitor, heartbeat) {
|
||||
if (monitor.manual_status !== null) {
|
||||
heartbeat.status = monitor.manual_status;
|
||||
switch (monitor.manual_status) {
|
||||
case UP:
|
||||
heartbeat.msg = "Up";
|
||||
break;
|
||||
case DOWN:
|
||||
heartbeat.msg = "Down";
|
||||
break;
|
||||
default:
|
||||
heartbeat.msg = "Pending";
|
||||
}
|
||||
} else {
|
||||
heartbeat.status = PENDING;
|
||||
heartbeat.msg = "Manual monitoring - No status set";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ManualMonitorType
|
||||
};
|
||||
Loading…
Reference in new issue