mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-19 07:44:02 +02:00
extends monitor-type heartbeat msg update
This commit is contained in:
parent
4490a05123
commit
9d6c5014bf
1 changed files with 28 additions and 15 deletions
|
@ -1,29 +1,25 @@
|
||||||
|
const { MonitorType } = require("./monitor-type");
|
||||||
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 extends MonitorType {
|
||||||
name = "rtsp";
|
name = "rtsp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the availability of an RTSP stream.
|
* @inheritdoc
|
||||||
* @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) {
|
async check(monitor, heartbeat, _server) {
|
||||||
const { rtspUsername, rtspPassword, hostname, port, rtspPath } = monitor;
|
const { rtspUsername, rtspPassword, hostname, port, rtspPath } = monitor;
|
||||||
|
|
||||||
// Construct RTSP URL
|
// Construct RTSP URL
|
||||||
let url = `rtsp://${hostname}:${port}${rtspPath}`;
|
let url = `rtsp://${hostname}:${port}${rtspPath}`;
|
||||||
if (rtspUsername && rtspPassword !== undefined) {
|
if (rtspUsername && rtspPassword !== undefined) {
|
||||||
url = url.replace(/^rtsp:\/\//, `rtsp://${rtspUsername}:${rtspPassword}@`);
|
url = `rtsp://${rtspUsername}:${rtspPassword}@${hostname}:${port}${rtspPath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default heartbeat status
|
|
||||||
heartbeat.status = DOWN;
|
|
||||||
heartbeat.msg = "Starting RTSP stream check...";
|
|
||||||
|
|
||||||
// Validate URL
|
// Validate URL
|
||||||
if (!url || !url.startsWith("rtsp://")) {
|
if (!url || !url.startsWith("rtsp://")) {
|
||||||
|
heartbeat.status = DOWN;
|
||||||
heartbeat.msg = "Invalid RTSP URL";
|
heartbeat.msg = "Invalid RTSP URL";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -31,13 +27,30 @@ class RtspMonitorType {
|
||||||
const client = new RTSPClient();
|
const client = new RTSPClient();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
log.debug("monitor", `Connecting to RTSP URL: ${url}`);
|
||||||
await client.connect(url);
|
await client.connect(url);
|
||||||
await client.describe();
|
|
||||||
heartbeat.status = UP;
|
const res = await client.describe();
|
||||||
heartbeat.msg = "RTSP stream is accessible";
|
log.debug("monitor", `RTSP DESCRIBE response: ${JSON.stringify(res)}`);
|
||||||
|
|
||||||
|
const statusCode = res?.statusCode;
|
||||||
|
const statusMessage = res?.statusMessage || "Unknown";
|
||||||
|
|
||||||
|
if (statusCode === 200) {
|
||||||
|
heartbeat.status = UP;
|
||||||
|
heartbeat.msg = "RTSP stream is accessible";
|
||||||
|
} else if (statusCode === 503) {
|
||||||
|
heartbeat.status = DOWN;
|
||||||
|
heartbeat.msg = res.body?.reason || "Service Unavailable";
|
||||||
|
} else {
|
||||||
|
heartbeat.status = DOWN;
|
||||||
|
heartbeat.msg = `${statusCode} - ${statusMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
heartbeat.msg = `Error: ${error.message}`;
|
heartbeat.status = DOWN;
|
||||||
log.debug("monitor", `[${monitor.name}] RTSP check failed: ${error.message}`);
|
heartbeat.msg = `RTSP check failed: ${error.message}`;
|
||||||
|
log.debug("monitor", `[${monitor.name}] RTSP check failed: ${JSON.stringify(error.message)}`);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
await client.close();
|
await client.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue