Merge 1f058cb654b422fa5316678cedf0001b8c18e190 into 8d8e3e5a8e78030b8ffbe258dc872b8bea234390

This commit is contained in:
PoleTransformer 2025-04-18 23:34:26 +00:00 committed by GitHub
commit cd04b7d72f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 406 additions and 10 deletions

View File

@ -23,7 +23,7 @@ It is a temporary live demo, all data will be deleted after 10 minutes. Sponsore
## ⭐ Features
- Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / HTTP(s) Json Query / Ping / DNS Record / Push / Steam Game Server / Docker Containers
- Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / HTTP(s) Json Query / Websocket / Ping / DNS Record / Push / Steam Game Server / Docker Containers
- Fancy, Reactive, Fast UI/UX
- Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
- 20-second intervals

View File

@ -0,0 +1,15 @@
// Add websocket ignore headers and websocket subprotocol
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.boolean("ws_ignore_sec_websocket_accept_header").notNullable().defaultTo(false);
table.string("ws_subprotocol", 255).notNullable().defaultTo("");
});
};
exports.down = function (knex) {
return knex.schema.alterTable("monitor", function (table) {
table.dropColumn("ws_ignore_sec_websocket_accept_header");
table.dropColumn("ws_subprotocol");
});
};

View File

@ -96,6 +96,8 @@ class Monitor extends BeanModel {
parent: this.parent,
childrenIDs: preloadData.childrenIDs.get(this.id) || [],
url: this.url,
wsIgnoreSecWebsocketAcceptHeader: this.getWsIgnoreSecWebsocketAcceptHeader(),
wsSubprotocol: this.wsSubprotocol,
method: this.method,
hostname: this.hostname,
port: this.port,
@ -255,6 +257,14 @@ class Monitor extends BeanModel {
return Boolean(this.ignoreTls);
}
/**
* Parse to boolean
* @returns {boolean} Should WS headers be ignored?
*/
getWsIgnoreSecWebsocketAcceptHeader() {
return Boolean(this.wsIgnoreSecWebsocketAcceptHeader);
}
/**
* Parse to boolean
* @returns {boolean} Is the monitor in upside down mode?

View File

@ -0,0 +1,52 @@
const { MonitorType } = require("./monitor-type");
const WebSocket = require("ws");
const { UP, DOWN } = require("../../src/util");
class WebSocketMonitorType extends MonitorType {
name = "websocket-upgrade";
/**
* @inheritdoc
*/
async check(monitor, heartbeat, _server) {
const [ message, code ] = await this.attemptUpgrade(monitor);
heartbeat.status = code === 1000 ? UP : DOWN;
heartbeat.msg = message;
}
/**
* Uses the builtin Websocket API to establish a connection to target server
* @param {object} monitor The monitor object for input parameters.
* @returns {[ string, int ]} Array containing a status message and response code
*/
async attemptUpgrade(monitor) {
return new Promise((resolve) => {
let ws;
//If user selected a subprotocol, sets Sec-WebSocket-Protocol header. Subprotocol Identifier column: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name
ws = monitor.wsSubprotocol === "" ? new WebSocket(monitor.url) : new WebSocket(monitor.url, monitor.wsSubprotocol);
ws.addEventListener("open", (event) => {
// Immediately close the connection
ws.close(1000);
});
ws.onerror = (error) => {
// Give user the choice to ignore Sec-WebSocket-Accept header
if (monitor.wsIgnoreSecWebsocketAcceptHeader && error.message === "Invalid Sec-WebSocket-Accept header") {
resolve([ "101 - OK", 1000 ]);
}
// Upgrade failed, return message to user
resolve([ error.message, error.code ]);
};
ws.onclose = (event) => {
// Upgrade success, connection closed successfully
resolve([ "101 - OK", event.code ]);
};
});
}
}
module.exports = {
WebSocketMonitorType,
};

View File

@ -790,6 +790,8 @@ let needSetup = false;
bean.parent = monitor.parent;
bean.type = monitor.type;
bean.url = monitor.url;
bean.wsIgnoreSecWebsocketAcceptHeader = monitor.wsIgnoreSecWebsocketAcceptHeader;
bean.wsSubprotocol = monitor.wsSubprotocol;
bean.method = monitor.method;
bean.body = monitor.body;
bean.headers = monitor.headers;

View File

@ -111,6 +111,7 @@ class UptimeKumaServer {
// Set Monitor Types
UptimeKumaServer.monitorTypeList["real-browser"] = new RealBrowserMonitorType();
UptimeKumaServer.monitorTypeList["tailscale-ping"] = new TailscalePing();
UptimeKumaServer.monitorTypeList["websocket-upgrade"] = new WebSocketMonitorType();
UptimeKumaServer.monitorTypeList["dns"] = new DnsMonitorType();
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
@ -549,6 +550,7 @@ module.exports = {
// Must be at the end to avoid circular dependencies
const { RealBrowserMonitorType } = require("./monitor-types/real-browser-monitor-type");
const { TailscalePing } = require("./monitor-types/tailscale-ping");
const { WebSocketMonitorType } = require("./monitor-types/websocket-upgrade");
const { DnsMonitorType } = require("./monitor-types/dns");
const { MqttMonitorType } = require("./monitor-types/mqtt");
const { SNMPMonitorType } = require("./monitor-types/snmp");

View File

@ -86,6 +86,40 @@
"ignoreTLSError": "Ignore TLS/SSL errors for HTTPS websites",
"ignoreTLSErrorGeneral": "Ignore TLS/SSL error for connection",
"upsideDownModeDescription": "Flip the status upside down. If the service is reachable, it is DOWN.",
"ignoreSecWebsocketAcceptHeaderDescription": "Allows the server to not reply with Sec-WebSocket-Accept header, if the websocket upgrade succeeds.",
"Ignore Sec-WebSocket-Accept header": "Ignore {0} header",
"wsSubprotocolDescription": "For more information on subprotocols, please consult the {documentation}",
"WebSocket Application Messaging Protocol": "WAMP (The WebSocket Application Messaging Protocol)",
"Session Initiation Protocol": "WebSocket Transport for SIP (Session Initiation Protocol)",
"Network API for Notification Channel": "OMA RESTful Network API for Notification Channel",
"Web Process Control Protocol": "Web Process Control Protocol (WPCP)",
"Advanced Message Queuing Protocol": "Advanced Message Queuing Protocol (AMQP) 1.0+",
"jsflow": "jsFlow pubsub/queue Protocol",
"Reverse Web Process Control": "Reverse Web Process Control Protocol (RWPCP)",
"Extensible Messaging and Presence Protocol": "WebSocket Transport for the Extensible Messaging and Presence Protocol (XMPP)",
"Smart Home IP": "SHIP - Smart Home IP",
"Miele Cloud Connect Protocol": "Miele Cloud Connect Protocol",
"Push Channel Protocol": "Push Channel Protocol",
"Message Session Relay Protocol": "WebSocket Transport for MSRP (Message Session Relay Protocol)",
"Binary Floor Control Protocol": "WebSocket Transport for BFCP (Binary Floor Control Protocol)",
"Softvelum Low Delay Protocol": "Softvelum Low Delay Protocol",
"OPC UA Connection Protocol": "OPC UA Connection Protocol",
"OPC UA JSON Encoding": "OPC UA JSON Encoding",
"Swindon Web Server Protocol": "Swindon Web Server Protocol (JSON encoding)",
"Broadband Forum User Services Platform": "USP (Broadband Forum User Services Platform)",
"Constrained Application Protocol": "Constrained Application Protocol (CoAP)",
"Softvelum WebSocket signaling protocol": "Softvelum WebSocket Signaling Protocol",
"Cobra Real Time Messaging Protocol": "Cobra Real Time Messaging Protocol",
"Declarative Resource Protocol": "Declarative Resource Protocol",
"BACnet Secure Connect Hub Connection": "BACnet Secure Connect Hub Connection",
"BACnet Secure Connect Direct Connection": "BACnet Secure Connect Direct Connection",
"WebSocket Transport for JMAP": "WebSocket Transport for JMAP (JSON Meta Application Protocol)",
"ITU-T T.140 Real-Time Text": "ITU-T T.140 Real-Time Text",
"Done.best IoT Protocol": "Done.best IoT Protocol",
"Collection Update": "The Collection Update Websocket Subprotocol",
"Text IRC Protocol": "Text IRC Protocol",
"Binary IRC Protocol": "Binary IRC Protocol",
"Penguin Statistics Live Protocol v3": "Penguin Statistics Live Protocol v3 (Protobuf encoding)",
"maxRedirectDescription": "Maximum number of redirects to follow. Set to 0 to disable redirects.",
"Upside Down Mode": "Upside Down Mode",
"Max. Redirects": "Max. Redirects",

View File

@ -46,6 +46,10 @@
<option value="real-browser">
HTTP(s) - Browser Engine (Chrome/Chromium) (Beta)
</option>
<option value="websocket-upgrade">
Websocket Upgrade
</option>
</optgroup>
<optgroup :label="$t('Passive Monitor Type')">
@ -113,9 +117,85 @@
</div>
<!-- URL -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
<div v-if="monitor.type === 'websocket-upgrade' || monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
<label for="url" class="form-label">{{ $t("URL") }}</label>
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required data-testid="url-input">
<input id="url" v-model="monitor.url" type="url" class="form-control" :pattern="monitor.type !== 'websocket-upgrade' ? 'https?://.+' : 'wss?://.+'" required data-testid="url-input">
</div>
<!-- Websocket Subprotocol Docs: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name -->
<div v-if="monitor.type === 'websocket-upgrade'" class="my-3">
<label for="ws_subprotocol" class="form-label">{{ $t("Subprotocol") }}</label>
<select id="ws_subprotocol" v-model="monitor.wsSubprotocol" class="form-select">
<option value="" selected>{{ $t("None") }}</option>
<option value="MBWS.huawei.com">MBWS</option>
<option value="MBLWS.huawei.com">MBLWS</option>
<option value="soap">soap</option>
<option value="wamp">{{ $t("WebSocket Application Messaging Protocol") }}</option>
<option value="v10.stomp">STOMP 1.0</option>
<option value="v11.stomp">STOMP 1.1</option>
<option value="v12.stomp">STOMP 1.2</option>
<option value="ocpp1.2">OCPP 1.2</option>
<option value="ocpp1.5">OCPP 1.5</option>
<option value="ocpp1.6">OCPP 1.6</option>
<option value="ocpp2.0">OCPP 2.0</option>
<option value="ocpp2.0.1">OCPP 2.0.1</option>
<option value="ocpp2.1">OCPP 2.1</option>
<option value="rfb">RFB</option>
<option value="sip">{{ $t("Session Initiation Protocol") }}</option>
<option value="notificationchannel-netapi-rest.openmobilealliance.org">{{ $t("Network API for Notification Channel") }}</option>
<option value="wpcp">{{ $t("Web Process Control Protocol") }}</option>
<option value="amqp">{{ $t("Advanced Message Queuing Protocol") }}</option>
<option value="mqtt">MQTT</option>
<option value="jsflow">{{ $t("jsflow") }}</option>
<option value="rwpcp">{{ $t("Reverse Web Process Control") }}</option>
<option value="xmpp">{{ $t("Extensible Messaging and Presence Protocol") }}</option>
<option value="ship">{{ $t("Smart Home IP") }}</option>
<option value="mielecloudconnect">{{ $t("Miele Cloud Connect Protocol") }}</option>
<option value="v10.pcp.sap.com">{{ $t("Push Channel Protocol") }}</option>
<option value="msrp">{{ $t("Message Session Relay Protocol") }}</option>
<option value="v1.saltyrtc.org">SaltyRTC 1.0</option>
<option value="TLCP-2.0.0.lightstreamer.com">TLCP 2.0.0</option>
<option value="bfcp">{{ $t("Binary Floor Control Protocol") }}</option>
<option value="sldp.softvelum.com">{{ $t("Softvelum Low Delay Protocol") }}</option>
<option value="opcua+uacp">{{ $t("OPC UA Connection Protocol") }}</option>
<option value="opcua+uajson">{{ $t("OPC UA JSON Encoding") }}</option>
<option value="v1.swindon-lattice+json">{{ $t("Swindon Web Server Protocol") }}</option>
<option value="v1.usp">{{ $t("Broadband Forum User Services Platform") }}</option>
<option value="mles-websocket">mles-websocket</option>
<option value="coap">{{ $t("Constrained Application Protocol") }}</option>
<option value="TLCP-2.1.0.lightstreamer.com">TLCP 2.1.0</option>
<option value="sqlnet.oracle.com">sqlnet</option>
<option value="oneM2M.R2.0.json">oneM2M R2.0 JSON</option>
<option value="oneM2M.R2.0.xml">oneM2M R2.0 XML</option>
<option value="oneM2M.R2.0.cbor">oneM2M R2.0 CBOR</option>
<option value="transit">Transit</option>
<option value="2016.serverpush.dash.mpeg.org">MPEG-DASH-ServerPush-23009-6-2017</option>
<option value="2018.mmt.mpeg.org">MPEG-MMT-23008-1-2018</option>
<option value="clue">clue</option>
<option value="webrtc.softvelum.com">{{ $t("Softvelum WebSocket signaling protocol") }}</option>
<option value="cobra.v2.json">{{ $t("Cobra Real Time Messaging Protocol") }}</option>
<option value="drp">{{ $t("Declarative Resource Protocol") }}</option>
<option value="hub.bsc.bacnet.org">{{ $t("BACnet Secure Connect Hub Connection") }}</option>
<option value="dc.bsc.bacnet.org">{{ $t("BACnet Secure Connect Direct Connection") }}</option>
<option value="jmap">{{ $t("WebSocket Transport for JMAP") }}</option>
<option value="t140">{{ $t("ITU-T T.140 Real-Time Text") }}</option>
<option value="done">{{ $t("Done.best IoT Protocol") }}</option>
<option value="TLCP-2.2.0.lightstreamer.com">TLCP 2.2.0</option>
<option value="collection-update">{{ $t("Collection Update") }}</option>
<option value="TLCP-2.3.0.lightstreamer.com">TLCP 2.3.0</option>
<option value="text.ircv3.net">{{ $t("Text IRC Protocol") }}</option>
<option value="binary.ircv3.net">{{ $t("Binary IRC Protocol") }}</option>
<option value="v3.penguin-stats.live+proto">{{ $t("Penguin Statistics Live Protocol v3") }}</option>
<option value="TLCP-2.4.0.lightstreamer.com">TLCP 2.4.0</option>
<option value="TLCP-2.5.0.lightstreamer.com">TLCP 2.5.0</option>
<option value="Redfish">Redfish DSP0266</option>
<option value="bidib">webBiDiB</option>
</select>
<i18n-t tag="div" class="form-text" keypath="wsSubprotocolDescription">
<template #documentation>
<a href="https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name" target="_blank" rel="noopener noreferrer">{{ $t('documentationOf', ['IANA']) }}</a>
</template>
</i18n-t>
</div>
<!-- gRPC URL -->
@ -335,8 +415,8 @@
<div class="my-2">
<label for="jsonPath" class="form-label mb-0">{{ $t("Json Query Expression") }}</label>
<i18n-t tag="div" class="form-text mb-2" keypath="jsonQueryDescription">
<a href="https://jsonata.org/">jsonata.org</a>
<a href="https://try.jsonata.org/">{{ $t('playground') }}</a>
<a href="https://jsonata.org/" target="_blank" rel="noopener noreferrer">jsonata.org</a>
<a href="https://try.jsonata.org/" target="_blank" rel="noopener noreferrer">{{ $t('playground') }}</a>
</i18n-t>
<input id="jsonPath" v-model="monitor.jsonPath" type="text" class="form-control" placeholder="$" required>
</div>
@ -475,8 +555,8 @@
<input id="jsonPath" v-model="monitor.jsonPath" type="text" class="form-control" required>
<i18n-t tag="div" class="form-text" keypath="jsonQueryDescription">
<a href="https://jsonata.org/">jsonata.org</a>
<a href="https://try.jsonata.org/">{{ $t('here') }}</a>
<a href="https://jsonata.org/" target="_blank" rel="noopener noreferrer">jsonata.org</a>
<a href="https://try.jsonata.org/" target="_blank" rel="noopener noreferrer">{{ $t('here') }}</a>
</i18n-t>
<br>
@ -546,7 +626,7 @@
<textarea id="mongodbCommand" v-model="monitor.databaseQuery" class="form-control" :placeholder="$t('Example:', [ '{ &quot;ping&quot;: 1 }' ])"></textarea>
<i18n-t tag="div" class="form-text" keypath="mongodbCommandDescription">
<template #documentation>
<a href="https://www.mongodb.com/docs/manual/reference/command/">{{ $t('documentationOf', ['MongoDB']) }}</a>
<a href="https://www.mongodb.com/docs/manual/reference/command/" target="_blank" rel="noopener noreferrer">{{ $t('documentationOf', ['MongoDB']) }}</a>
</template>
</i18n-t>
</div>
@ -555,8 +635,8 @@
<input id="jsonPath" v-model="monitor.jsonPath" type="text" class="form-control">
<i18n-t tag="div" class="form-text" keypath="jsonQueryDescription">
<a href="https://jsonata.org/">jsonata.org</a>
<a href="https://try.jsonata.org/">{{ $t('here') }}</a>
<a href="https://jsonata.org/" target="_blank" rel="noopener noreferrer">jsonata.org</a>
<a href="https://try.jsonata.org/" target="_blank" rel="noopener noreferrer">{{ $t('here') }}</a>
</i18n-t>
</div>
<div class="my-3">
@ -621,6 +701,16 @@
</div>
</div>
<div v-if="monitor.type === 'websocket-upgrade' " class="my-3 form-check">
<input id="wsIgnoreSecWebsocketAcceptHeader" v-model="monitor.wsIgnoreSecWebsocketAcceptHeader" class="form-check-input" type="checkbox">
<i18n-t tag="label" keypath="Ignore Sec-WebSocket-Accept header" class="form-check-label" for="wsIgnoreSecWebsocketAcceptHeader">
<code>Sec-Websocket-Accept</code>
</i18n-t>
<div class="form-text">
{{ $t("ignoreSecWebsocketAcceptHeaderDescription") }}
</div>
</div>
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'redis' " class="my-3 form-check">
<input id="ignore-tls" v-model="monitor.ignoreTls" class="form-check-input" type="checkbox" value="">
<label class="form-check-label" for="ignore-tls">
@ -1074,6 +1164,7 @@ const monitorDefaults = {
name: "",
parent: null,
url: "https://",
wsSubprotocol: "",
method: "GET",
interval: 60,
retryInterval: 60,
@ -1422,6 +1513,9 @@ message HealthCheckResponse {
},
"monitor.type"(newType, oldType) {
if (oldType && this.monitor.type === "websocket-upgrade") {
this.monitor.url = "wss://";
}
if (this.monitor.type === "push") {
if (! this.monitor.pushToken) {
// ideally this would require checking if the generated token is already used

View File

@ -0,0 +1,187 @@
const { WebSocketServer } = require("ws");
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { WebSocketMonitorType } = require("../../server/monitor-types/websocket-upgrade");
const { UP, DOWN, PENDING } = require("../../src/util");
describe("Websocket Test", {
}, () => {
test("Non Websocket Server", {}, async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://example.org",
wsIgnoreSecWebsocketAcceptHeader: false,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "Unexpected server response: 200",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Secure Websocket", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://echo.websocket.org",
wsIgnoreSecWebsocketAcceptHeader: false,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "101 - OK",
status: UP,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Insecure Websocket", async (t) => {
t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType();
const wss = new WebSocketServer({ port: 8080 });
const monitor = {
url: "ws://localhost:8080",
wsIgnoreSecWebsocketAcceptHeader: false,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "101 - OK",
status: UP,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Non compliant WS server without IgnoreSecWebsocket", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://c.img-cdn.net/yE4s7KehTFyj/",
wsIgnoreSecWebsocketAcceptHeader: false,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "Invalid Sec-WebSocket-Accept header",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Non compliant WS server with IgnoreSecWebsocket", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://c.img-cdn.net/yE4s7KehTFyj/",
wsIgnoreSecWebsocketAcceptHeader: true,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "101 - OK",
status: UP,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Compliant WS server with IgnoreSecWebsocket", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://echo.websocket.org",
wsIgnoreSecWebsocketAcceptHeader: true,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "101 - OK",
status: UP,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Non WS server with IgnoreSecWebsocket", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://example.org",
wsIgnoreSecWebsocketAcceptHeader: true,
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "Unexpected server response: 200",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
test("Secure Websocket with Subprotocol", async () => {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
url: "wss://echo.websocket.org",
wsIgnoreSecWebsocketAcceptHeader: false,
wsSubprotocol: "ocpp1.6",
};
const heartbeat = {
msg: "",
status: PENDING,
};
const expected = {
msg: "Server sent no subprotocol",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
});
});