mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-18 23:34:04 +02:00
rtsp client connection
This commit is contained in:
parent
10fd6ede1e
commit
aaaeec1efd
3 changed files with 59 additions and 0 deletions
|
@ -133,6 +133,7 @@
|
|||
"qs": "~6.10.4",
|
||||
"redbean-node": "~0.3.0",
|
||||
"redis": "~4.5.1",
|
||||
"rtsp-client": "^1.4.5",
|
||||
"semver": "~7.5.4",
|
||||
"socket.io": "~4.8.0",
|
||||
"socket.io-client": "~4.8.0",
|
||||
|
|
56
server/monitor-types/RtspMonitorType.js
Normal file
56
server/monitor-types/RtspMonitorType.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
const RTSPClient = require("rtsp-client");
|
||||
const { log, UP, DOWN } = require("../../src/util");
|
||||
class RtspMonitorType {
|
||||
name = "rtsp";
|
||||
|
||||
/**
|
||||
* @param {Object} monitor - monitor config containing rtspUrl and timeout
|
||||
* @param {Object} heartbeat - object to update with status and message
|
||||
*/
|
||||
async check(monitor, heartbeat) {
|
||||
const url = monitor.rtspUrl;
|
||||
const timeoutMs = (monitor.timeout || 10) * 1000;
|
||||
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = "Starting RTSP stream check...";
|
||||
|
||||
if (!url || !url.startsWith("rtsp://")) {
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = "Invalid RTSP URL";
|
||||
return;
|
||||
}
|
||||
|
||||
const client = new RTSPClient();
|
||||
|
||||
// Timeout promise to kill hanging connections
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error("RTSP connection timed out")), timeoutMs)
|
||||
);
|
||||
|
||||
try {
|
||||
// Use Promise.race to enforce timeout
|
||||
await Promise.race([
|
||||
(async () => {
|
||||
await client.connect(url);
|
||||
const describe = await client.describe();
|
||||
await client.close();
|
||||
|
||||
heartbeat.status = UP;
|
||||
heartbeat.msg = "RTSP stream is accessible";
|
||||
})(),
|
||||
timeoutPromise,
|
||||
]);
|
||||
} catch (error) {
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = `Error: ${error.message}`;
|
||||
log.debug("monitor", `[${monitor.name}] RTSP check failed: ${error.message}`);
|
||||
try {
|
||||
await client.close();
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RtspMonitorType,
|
||||
};
|
|
@ -119,6 +119,7 @@ class UptimeKumaServer {
|
|||
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
|
||||
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
|
||||
UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType();
|
||||
UptimeKumaServer.monitorTypeList["rtsp"] = new RtspMonitorType();
|
||||
|
||||
// Allow all CORS origins (polling) in development
|
||||
let cors = undefined;
|
||||
|
@ -560,4 +561,5 @@ const { SNMPMonitorType } = require("./monitor-types/snmp");
|
|||
const { MongodbMonitorType } = require("./monitor-types/mongodb");
|
||||
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
|
||||
const { ManualMonitorType } = require("./monitor-types/manual");
|
||||
const {RtspMonitorType}= require("./monitor-types/RtspMonitorType")
|
||||
const Monitor = require("./model/monitor");
|
||||
|
|
Loading…
Add table
Reference in a new issue