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,
|
rabbitmqPassword: this.rabbitmqPassword,
|
||||||
rtspUsername: this.rtspUsername,
|
rtspUsername: this.rtspUsername,
|
||||||
rtspPassword: this.rtspPassword,
|
rtspPassword: this.rtspPassword,
|
||||||
rtspPath:this.rtspPath
|
rtspPath: this.rtspPath
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +1,53 @@
|
||||||
const RTSPClient = require("rtsp-client");
|
const RTSPClient = require("rtsp-client");
|
||||||
const { log, UP, DOWN } = require("../../src/util");
|
const { log, UP, DOWN } = require("../../src/util");
|
||||||
|
|
||||||
class RtspMonitorType {
|
class RtspMonitorType {
|
||||||
name = "rtsp";
|
name = "rtsp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} monitor - monitor config containing hostname, port, username, password, path, and timeout
|
* Check the availability of an RTSP stream.
|
||||||
* @param {Object} heartbeat - object to update with status and message
|
* @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;
|
async check(monitor, heartbeat) {
|
||||||
const timeoutMs = (timeout || 10) * 1000;
|
const { rtspUsername, rtspPassword, hostname, port, rtspPath } = monitor;
|
||||||
|
|
||||||
// Construct the RTSP URL from individual components
|
// Construct RTSP URL
|
||||||
let url = `rtsp://${hostname}:${port}${rtsp_path}`;
|
let url = `rtsp://${hostname}:${port}${rtspPath}`;
|
||||||
|
if (rtspUsername && rtspPassword !== undefined) {
|
||||||
|
url = url.replace(/^rtsp:\/\//, `rtsp://${rtspUsername}:${rtspPassword}@`);
|
||||||
|
}
|
||||||
|
|
||||||
// If username and password are provided, inject them into the URL
|
// Default heartbeat status
|
||||||
if (rtsp_username && rtsp_password !== undefined) {
|
heartbeat.status = DOWN;
|
||||||
const auth = `${rtsp_username}:${rtsp_password}@`;
|
heartbeat.msg = "Starting RTSP stream check...";
|
||||||
const urlPattern = /^rtsp:\/\//;
|
|
||||||
|
|
||||||
// Inject authentication details into URL (before host)
|
// Validate URL
|
||||||
url = url.replace(urlPattern, `rtsp://${auth}`);
|
if (!url || !url.startsWith("rtsp://")) {
|
||||||
|
heartbeat.msg = "Invalid RTSP URL";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new RTSPClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.connect(url);
|
||||||
|
await client.describe();
|
||||||
|
heartbeat.status = UP;
|
||||||
|
heartbeat.msg = "RTSP stream is accessible";
|
||||||
|
} catch (error) {
|
||||||
|
heartbeat.msg = `Error: ${error.message}`;
|
||||||
|
log.debug("monitor", `[${monitor.name}] RTSP check failed: ${error.message}`);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await client.close();
|
||||||
|
} catch (closeError) {
|
||||||
|
log.debug("monitor", `Error closing RTSP client: ${closeError.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = {
|
module.exports = {
|
||||||
RtspMonitorType,
|
RtspMonitorType,
|
||||||
};
|
};
|
||||||
|
|
|
@ -877,9 +877,9 @@ let needSetup = false;
|
||||||
bean.rabbitmqPassword = monitor.rabbitmqPassword;
|
bean.rabbitmqPassword = monitor.rabbitmqPassword;
|
||||||
bean.conditions = JSON.stringify(monitor.conditions);
|
bean.conditions = JSON.stringify(monitor.conditions);
|
||||||
bean.manual_status = monitor.manual_status;
|
bean.manual_status = monitor.manual_status;
|
||||||
bean.rtspUsername=monitor.rtspUsername
|
bean.rtspUsername = monitor.rtspUsername;
|
||||||
bean.rtspPassword=monitor.rtspPassword
|
bean.rtspPassword = monitor.rtspPassword;
|
||||||
bean.rtspPath=monitor.path
|
bean.rtspPath = monitor.path;
|
||||||
|
|
||||||
// ping advanced options
|
// ping advanced options
|
||||||
bean.ping_numeric = monitor.ping_numeric;
|
bean.ping_numeric = monitor.ping_numeric;
|
||||||
|
|
|
@ -561,5 +561,5 @@ const { SNMPMonitorType } = require("./monitor-types/snmp");
|
||||||
const { MongodbMonitorType } = require("./monitor-types/mongodb");
|
const { MongodbMonitorType } = require("./monitor-types/mongodb");
|
||||||
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
|
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
|
||||||
const { ManualMonitorType } = require("./monitor-types/manual");
|
const { ManualMonitorType } = require("./monitor-types/manual");
|
||||||
const {RtspMonitorType}= require("./monitor-types/rtsp")
|
const { RtspMonitorType } = require("./monitor-types/rtsp");
|
||||||
const Monitor = require("./model/monitor");
|
const Monitor = require("./model/monitor");
|
||||||
|
|
Loading…
Add table
Reference in a new issue