mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-19 07:44:02 +02:00
eslint fix
This commit is contained in:
parent
152c93e7d3
commit
4490a05123
4 changed files with 48 additions and 65 deletions
|
@ -199,9 +199,7 @@ class Monitor extends BeanModel {
|
|||
rabbitmqPassword: this.rabbitmqPassword,
|
||||
rtspUsername: this.rtspUsername,
|
||||
rtspPassword: this.rtspPassword,
|
||||
rtspPath:this.rtspPath
|
||||
|
||||
|
||||
rtspPath: this.rtspPath
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,64 +1,49 @@
|
|||
const RTSPClient = require("rtsp-client");
|
||||
const { log, UP, DOWN } = require("../../src/util");
|
||||
|
||||
class RtspMonitorType {
|
||||
name = "rtsp";
|
||||
|
||||
/**
|
||||
* @param {Object} monitor - monitor config containing hostname, port, username, password, path, and timeout
|
||||
* @param {Object} heartbeat - object to update with status and message
|
||||
* Check the availability of an RTSP stream.
|
||||
* @param {object} monitor - Monitor config: hostname, port, username, password, path.
|
||||
* @param {object} heartbeat - Heartbeat object to update with status and message.
|
||||
*/
|
||||
async check(monitor, heartbeat) {
|
||||
const { rtsp_username, rtsp_password, hostname, port, rtsp_path, timeout } = monitor;
|
||||
const timeoutMs = (timeout || 10) * 1000;
|
||||
const { rtspUsername, rtspPassword, hostname, port, rtspPath } = monitor;
|
||||
|
||||
// Construct the RTSP URL from individual components
|
||||
let url = `rtsp://${hostname}:${port}${rtsp_path}`;
|
||||
|
||||
// If username and password are provided, inject them into the URL
|
||||
if (rtsp_username && rtsp_password !== undefined) {
|
||||
const auth = `${rtsp_username}:${rtsp_password}@`;
|
||||
const urlPattern = /^rtsp:\/\//;
|
||||
|
||||
// Inject authentication details into URL (before host)
|
||||
url = url.replace(urlPattern, `rtsp://${auth}`);
|
||||
// Construct RTSP URL
|
||||
let url = `rtsp://${hostname}:${port}${rtspPath}`;
|
||||
if (rtspUsername && rtspPassword !== undefined) {
|
||||
url = url.replace(/^rtsp:\/\//, `rtsp://${rtspUsername}:${rtspPassword}@`);
|
||||
}
|
||||
|
||||
// Default heartbeat status
|
||||
heartbeat.status = DOWN;
|
||||
heartbeat.msg = "Starting RTSP stream check...";
|
||||
|
||||
// Validate URL
|
||||
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();
|
||||
|
||||
await client.describe();
|
||||
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}`);
|
||||
} finally {
|
||||
try {
|
||||
await client.close();
|
||||
} catch {}
|
||||
} catch (closeError) {
|
||||
log.debug("monitor", `Error closing RTSP client: ${closeError.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -877,9 +877,9 @@ let needSetup = false;
|
|||
bean.rabbitmqPassword = monitor.rabbitmqPassword;
|
||||
bean.conditions = JSON.stringify(monitor.conditions);
|
||||
bean.manual_status = monitor.manual_status;
|
||||
bean.rtspUsername=monitor.rtspUsername
|
||||
bean.rtspPassword=monitor.rtspPassword
|
||||
bean.rtspPath=monitor.path
|
||||
bean.rtspUsername = monitor.rtspUsername;
|
||||
bean.rtspPassword = monitor.rtspPassword;
|
||||
bean.rtspPath = monitor.path;
|
||||
|
||||
// ping advanced options
|
||||
bean.ping_numeric = monitor.ping_numeric;
|
||||
|
|
|
@ -561,5 +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/rtsp")
|
||||
const { RtspMonitorType } = require("./monitor-types/rtsp");
|
||||
const Monitor = require("./model/monitor");
|
||||
|
|
Loading…
Add table
Reference in a new issue