Skip to content

Commit 18cfa90

Browse files
warprealityMaksim KachynskiCommanderStorm
authored
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>
1 parent f282422 commit 18cfa90

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
exports.up = function (knex) {
2+
return knex.schema
3+
.alterTable("monitor", function (table) {
4+
table.string("manual_status").defaultTo(null);
5+
});
6+
};
7+
8+
exports.down = function (knex) {
9+
return knex.schema.alterTable("monitor", function (table) {
10+
table.dropColumn("manual_status");
11+
});
12+
};

server/monitor-types/manual.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { MonitorType } = require("./monitor-type");
2+
const { UP, DOWN, PENDING } = require("../../src/util");
3+
4+
class ManualMonitorType extends MonitorType {
5+
name = "Manual";
6+
type = "manual";
7+
description = "A monitor that allows manual control of the status";
8+
supportsConditions = false;
9+
conditionVariables = [];
10+
11+
/**
12+
* @inheritdoc
13+
*/
14+
async check(monitor, heartbeat) {
15+
if (monitor.manual_status !== null) {
16+
heartbeat.status = monitor.manual_status;
17+
switch (monitor.manual_status) {
18+
case UP:
19+
heartbeat.msg = "Up";
20+
break;
21+
case DOWN:
22+
heartbeat.msg = "Down";
23+
break;
24+
default:
25+
heartbeat.msg = "Pending";
26+
}
27+
} else {
28+
heartbeat.status = PENDING;
29+
heartbeat.msg = "Manual monitoring - No status set";
30+
}
31+
}
32+
}
33+
34+
module.exports = {
35+
ManualMonitorType
36+
};

server/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ let needSetup = false;
876876
bean.rabbitmqUsername = monitor.rabbitmqUsername;
877877
bean.rabbitmqPassword = monitor.rabbitmqPassword;
878878
bean.conditions = JSON.stringify(monitor.conditions);
879+
bean.manual_status = monitor.manual_status;
879880

880881
// ping advanced options
881882
bean.ping_numeric = monitor.ping_numeric;

server/uptime-kuma-server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class UptimeKumaServer {
118118
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
119119
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
120120
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
121+
UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType();
121122

122123
// Allow all CORS origins (polling) in development
123124
let cors = undefined;
@@ -558,4 +559,5 @@ const { GroupMonitorType } = require("./monitor-types/group");
558559
const { SNMPMonitorType } = require("./monitor-types/snmp");
559560
const { MongodbMonitorType } = require("./monitor-types/mongodb");
560561
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
562+
const { ManualMonitorType } = require("./monitor-types/manual");
561563
const Monitor = require("./model/monitor");

src/lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,5 +1122,6 @@
11221122
"Add Another Tag": "Add Another Tag",
11231123
"Staged Tags for Batch Add": "Staged Tags for Batch Add",
11241124
"Clear Form": "Clear Form",
1125-
"pause": "Pause"
1125+
"pause": "Pause",
1126+
"Manual": "Manual"
11261127
}

src/pages/EditMonitor.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<option value="push">
5656
Push
5757
</option>
58+
<option value="manual">
59+
{{ $t("Manual") }}
60+
</option>
5861
</optgroup>
5962

6063
<optgroup :label="$t('Specific Monitor Type')">
@@ -115,6 +118,18 @@
115118
<input id="name" v-model="monitor.name" type="text" class="form-control" data-testid="friendly-name-input" :placeholder="defaultFriendlyName">
116119
</div>
117120

121+
<!-- Manual Status switcher -->
122+
<div v-if="monitor.type === 'manual'" class="mb-3">
123+
<div class="btn-group w-100 mb-3">
124+
<button class="btn btn-success" @click="monitor.manual_status = 1">
125+
<i class="fas fa-check"></i> {{ $t("Up") }}
126+
</button>
127+
<button class="btn btn-danger" @click="monitor.manual_status = 0">
128+
<i class="fas fa-times"></i> {{ $t("Down") }}
129+
</button>
130+
</div>
131+
</div>
132+
118133
<!-- URL -->
119134
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
120135
<label for="url" class="form-label">{{ $t("URL") }}</label>

0 commit comments

Comments
 (0)