Compare commits

...

20 commits

Author SHA1 Message Date
Peace
d7b8934d00
Merge ac8d1d6346 into c01494ec33 2024-10-20 13:57:15 +00:00
Suven-p
c01494ec33
feat: add RabbitMQ monitor (#5199)
Some checks failed
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
json-yaml-validate / json-yaml-validate (push) Has been cancelled
Co-authored-by: Frank Elsinga <frank@elsinga.de>
2024-10-20 15:57:03 +02:00
Ryo Hanafusa
a7e9bdd43e
fix: expand hover trigger area of beat (#5223)
Co-authored-by: Frank Elsinga <frank@elsinga.de>
2024-10-20 15:30:03 +02:00
Peace
ac8d1d6346
docs: add comments for queries 2024-10-17 17:16:29 +02:00
Peace
ec2cebc5df
perf: option to only get ids of active children 2024-10-17 17:16:08 +02:00
Peace
0a479ecb50
Merge branch 'master' into fix/pause-child-monitors 2024-10-17 00:22:51 +02:00
Peace
c9e5dff162
perf: less recursion for isUnderMaintenance using db query 2024-10-17 00:07:07 +02:00
Peace
16c04f6ac2
perf: less recursion for isParentActive using db query 2024-10-17 00:06:40 +02:00
Peace
5dc66e1495
refactor: make getAllChildrenIDs more compact 2024-10-17 00:05:55 +02:00
Peace
c079971a7b
fix: cast getParent and getChildren to Beans 2024-10-17 00:05:29 +02:00
Peace
71c7ee69c7
feat: db statement to get all active monitors 2024-10-17 00:04:45 +02:00
Peace
22dcba17c8
fix: remove test logging 2024-10-16 22:56:14 +02:00
Peace
f622898ff1
perf: less sql statements and concurrent start/stop 2024-10-16 22:54:15 +02:00
Peace
6179f31348
Merge branch 'master' into fix/pause-child-monitors 2024-10-14 23:08:48 +02:00
Peace
d336d09d78
fix: display children as paused when pausing parent 2024-10-14 23:04:07 +02:00
Peace
b02b21299b
feat: set group to pending if all childs are paused. 2024-10-14 00:01:55 +02:00
Peace
9eda25d0b6
revert: fix: pause child monitors if parent is paused 2024-10-13 23:29:11 +02:00
Peace
d1677300a4
style: fix formatting 2024-10-13 01:16:16 +02:00
Peace
b4fabbb00f
fix: update children in ui on pause 2024-10-13 01:14:24 +02:00
Peace
703e3d0fae
fix: pause child monitors if parent is paused 2024-10-13 00:25:45 +02:00
12 changed files with 448 additions and 100 deletions

View file

@ -0,0 +1,17 @@
exports.up = function (knex) {
return knex.schema.alterTable("monitor", function (table) {
table.text("rabbitmq_nodes");
table.string("rabbitmq_username");
table.string("rabbitmq_password");
});
};
exports.down = function (knex) {
return knex.schema.alterTable("monitor", function (table) {
table.dropColumn("rabbitmq_nodes");
table.dropColumn("rabbitmq_username");
table.dropColumn("rabbitmq_password");
});
};

17
package-lock.json generated
View file

@ -93,6 +93,7 @@
"@playwright/test": "~1.39.0",
"@popperjs/core": "~2.10.2",
"@testcontainers/hivemq": "^10.13.1",
"@testcontainers/rabbitmq": "^10.13.2",
"@types/bootstrap": "~5.1.9",
"@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.7.5",
@ -4172,6 +4173,15 @@
"testcontainers": "^10.13.1"
}
},
"node_modules/@testcontainers/rabbitmq": {
"version": "10.13.2",
"resolved": "https://registry.npmjs.org/@testcontainers/rabbitmq/-/rabbitmq-10.13.2.tgz",
"integrity": "sha512-npBKBnq3c6hETmxGZ/gVMke9cc1J/pcftNW9S3WidL48hxFBIPjYNM9FdTfWuoNER/8kuf4xJ8yCuJEYGH3ZAg==",
"dev": true,
"dependencies": {
"testcontainers": "^10.13.2"
}
},
"node_modules/@tootallnate/once": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
@ -15925,11 +15935,10 @@
}
},
"node_modules/testcontainers": {
"version": "10.13.1",
"resolved": "https://registry.npmjs.org/testcontainers/-/testcontainers-10.13.1.tgz",
"integrity": "sha512-JBbOhxmygj/ouH/47GnoVNt+c55Telh/45IjVxEbDoswsLchVmJiuKiw/eF6lE5i7LN+/99xsrSCttI3YRtirg==",
"version": "10.13.2",
"resolved": "https://registry.npmjs.org/testcontainers/-/testcontainers-10.13.2.tgz",
"integrity": "sha512-LfEll+AG/1Ks3n4+IA5lpyBHLiYh/hSfI4+ERa6urwfQscbDU+M2iW1qPQrHQi+xJXQRYy4whyK1IEHdmxWa3Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"@balena/dockerignore": "^1.0.2",
"@types/dockerode": "^3.3.29",

View file

@ -155,6 +155,7 @@
"@playwright/test": "~1.39.0",
"@popperjs/core": "~2.10.2",
"@testcontainers/hivemq": "^10.13.1",
"@testcontainers/rabbitmq": "^10.13.2",
"@types/bootstrap": "~5.1.9",
"@types/node": "^20.8.6",
"@typescript-eslint/eslint-plugin": "^6.7.5",

View file

@ -153,6 +153,7 @@ class Monitor extends BeanModel {
snmpOid: this.snmpOid,
jsonPathOperator: this.jsonPathOperator,
snmpVersion: this.snmpVersion,
rabbitmqNodes: JSON.parse(this.rabbitmqNodes),
conditions: JSON.parse(this.conditions),
};
@ -183,6 +184,8 @@ class Monitor extends BeanModel {
tlsCert: this.tlsCert,
tlsKey: this.tlsKey,
kafkaProducerSaslOptions: JSON.parse(this.kafkaProducerSaslOptions),
rabbitmqUsername: this.rabbitmqUsername,
rabbitmqPassword: this.rabbitmqPassword,
};
}
@ -380,7 +383,11 @@ class Monitor extends BeanModel {
} else if (this.type === "group") {
const children = await Monitor.getChildren(this.id);
if (children.length > 0) {
if (children.length > 0 && children.filter(child => child.active).length === 0) {
// Set status pending if all children are paused
bean.status = PENDING;
bean.msg = "All Children are paused.";
} else if (children.length > 0) {
bean.status = UP;
bean.msg = "All children up and running";
for (const child of children) {
@ -1465,10 +1472,12 @@ class Monitor extends BeanModel {
* @returns {Promise<boolean>} Is the monitor under maintenance
*/
static async isUnderMaintenance(monitorID) {
const ancestorIDs = await Monitor.getAllAncestorIDs(monitorID);
const allIDs = [ monitorID, ...ancestorIDs ];
const maintenanceIDList = await R.getCol(`
SELECT maintenance_id FROM monitor_maintenance
WHERE monitor_id = ?
`, [ monitorID ]);
WHERE monitor_id IN (${allIDs.map((_) => "?").join(",")})
`, allIDs);
for (const maintenanceID of maintenanceIDList) {
const maintenance = await UptimeKumaServer.getInstance().getMaintenance(maintenanceID);
@ -1477,11 +1486,6 @@ class Monitor extends BeanModel {
}
}
const parent = await Monitor.getParent(monitorID);
if (parent != null) {
return await Monitor.isUnderMaintenance(parent.id);
}
return false;
}
@ -1601,13 +1605,32 @@ class Monitor extends BeanModel {
};
}
/**
* Gets all active monitors
* @returns {Promise<Bean[]>} Active Monitors
*/
static async getAllActiveMonitors() {
// Gets all monitors but only if they and all their ancestors are active
return R.convertToBeans("monitor", await R.getAll(`
WITH RECURSIVE MonitorHierarchy AS (
SELECT * FROM monitor
WHERE parent IS NULL AND active = 1
UNION ALL
SELECT m.* FROM monitor m
INNER JOIN MonitorHierarchy mh ON m.parent = mh.id
WHERE m.active = 1
)
SELECT * FROM MonitorHierarchy;
`));
}
/**
* Gets Parent of the monitor
* @param {number} monitorID ID of monitor to get
* @returns {Promise<LooseObject<any>>} Parent
* @returns {Promise<Bean | null>} Parent
*/
static async getParent(monitorID) {
return await R.getRow(`
const result = await R.getRow(`
SELECT parent.* FROM monitor parent
LEFT JOIN monitor child
ON child.parent = parent.id
@ -1615,20 +1638,25 @@ class Monitor extends BeanModel {
`, [
monitorID,
]);
if (!result) {
return null;
}
return R.convertToBean("monitor", result);
}
/**
* Gets all Children of the monitor
* @param {number} monitorID ID of monitor to get
* @returns {Promise<LooseObject<any>>} Children
* @returns {Promise<Bean[]>} Children
*/
static async getChildren(monitorID) {
return await R.getAll(`
return R.convertToBeans("monitor", await R.getAll(`
SELECT * FROM monitor
WHERE parent = ?
`, [
monitorID,
]);
]));
}
/**
@ -1654,25 +1682,64 @@ class Monitor extends BeanModel {
}
/**
* Gets recursive all child ids
* Gets recursive all ancestor ids
* @param {number} monitorID ID of the monitor to get
* @returns {Promise<Array>} IDs of all children
* @returns {Promise<number[]>} IDs of all ancestors
*/
static async getAllChildrenIDs(monitorID) {
const childs = await Monitor.getChildren(monitorID);
if (childs === null) {
return [];
static async getAllAncestorIDs(monitorID) {
// Gets all ancestor monitor ids recursive
return await R.getCol(`
WITH RECURSIVE Ancestors AS (
SELECT parent FROM monitor
WHERE id = ?
UNION ALL
SELECT m.parent FROM monitor m
JOIN Ancestors a ON m.id = a.parent
)
SELECT parent AS ancestor_id FROM Ancestors
WHERE parent IS NOT NULL;
`, [
monitorID,
]);
}
let childrenIDs = [];
for (const child of childs) {
childrenIDs.push(child.id);
childrenIDs = childrenIDs.concat(await Monitor.getAllChildrenIDs(child.id));
/**
* Gets recursive all children ids
* @param {number} monitorID ID of the monitor to get
* @param {boolean} onlyActive Return only monitors which are active (including all ancestors)
* @returns {Promise<number[]>} IDs of all children
*/
static async getAllChildrenIDs(monitorID, onlyActive = false) {
if (onlyActive) {
// Gets all children monitor ids recursive but only if they and all their ancestors are active
return await R.getCol(`
WITH RECURSIVE MonitorHierarchy(id, active_chain) AS (
SELECT id, active FROM monitor
WHERE id = ?
UNION ALL
SELECT m.id, m.active * mh.active_chain FROM monitor m
INNER JOIN MonitorHierarchy mh ON m.parent = mh.id
WHERE mh.active_chain = 1
)
SELECT id FROM MonitorHierarchy
WHERE id != ? AND active_chain = 1;
`, [
monitorID,
monitorID
]);
}
return childrenIDs;
// Gets all children monitor ids recursive
return await R.getCol(`
WITH RECURSIVE MonitorHierarchy(id) AS (
SELECT id FROM monitor WHERE id = ?
UNION ALL
SELECT m.id FROM monitor m INNER JOIN MonitorHierarchy mh ON m.parent = mh.id
)
SELECT id FROM MonitorHierarchy WHERE id != ?;
`, [
monitorID,
monitorID
]);
}
/**
@ -1692,14 +1759,32 @@ class Monitor extends BeanModel {
* @returns {Promise<boolean>} Is the parent monitor active?
*/
static async isParentActive(monitorID) {
const parent = await Monitor.getParent(monitorID);
// Checks recursive if the parent and all its ancestors are active
const result = await R.getRow(`
WITH RECURSIVE MonitorHierarchy AS (
SELECT parent FROM monitor
WHERE id = ?
UNION ALL
SELECT m.parent FROM monitor m
JOIN MonitorHierarchy mh ON m.id = mh.parent
)
SELECT
CASE
WHEN (SELECT parent FROM monitor WHERE id = ?) IS NULL THEN 1
ELSE
CASE
WHEN COUNT(m.id) = SUM(m.active) THEN 1
ELSE 0
END
END AS all_active
FROM MonitorHierarchy mh
LEFT JOIN monitor m ON mh.parent = m.id;
`, [
monitorID,
monitorID
]);
if (parent === null) {
return true;
}
const parentActive = await Monitor.isParentActive(parent.id);
return parent.active && parentActive;
return result.all_active === 1;
}
/**

View file

@ -0,0 +1,67 @@
const { MonitorType } = require("./monitor-type");
const { log, UP, DOWN } = require("../../src/util");
const { axiosAbortSignal } = require("../util-server");
const axios = require("axios");
class RabbitMqMonitorType extends MonitorType {
name = "rabbitmq";
/**
* @inheritdoc
*/
async check(monitor, heartbeat, server) {
let baseUrls = [];
try {
baseUrls = JSON.parse(monitor.rabbitmqNodes);
} catch (error) {
throw new Error("Invalid RabbitMQ Nodes");
}
heartbeat.status = DOWN;
for (let baseUrl of baseUrls) {
try {
// Without a trailing slash, path in baseUrl will be removed. https://example.com/api -> https://example.com
if ( !baseUrl.endsWith("/") ) {
baseUrl += "/";
}
const options = {
// Do not start with slash, it will strip the trailing slash from baseUrl
url: new URL("api/health/checks/alarms/", baseUrl).href,
method: "get",
timeout: monitor.timeout * 1000,
headers: {
"Accept": "application/json",
"Authorization": "Basic " + Buffer.from(`${monitor.rabbitmqUsername || ""}:${monitor.rabbitmqPassword || ""}`).toString("base64"),
},
signal: axiosAbortSignal((monitor.timeout + 10) * 1000),
// Capture reason for 503 status
validateStatus: (status) => status === 200 || status === 503,
};
log.debug("monitor", `[${monitor.name}] Axios Request: ${JSON.stringify(options)}`);
const res = await axios.request(options);
log.debug("monitor", `[${monitor.name}] Axios Response: status=${res.status} body=${JSON.stringify(res.data)}`);
if (res.status === 200) {
heartbeat.status = UP;
heartbeat.msg = "OK";
break;
} else if (res.status === 503) {
heartbeat.msg = res.data.reason;
} else {
heartbeat.msg = `${res.status} - ${res.statusText}`;
}
} catch (error) {
if (axios.isCancel(error)) {
heartbeat.msg = "Request timed out";
log.debug("monitor", `[${monitor.name}] Request timed out`);
} else {
log.debug("monitor", `[${monitor.name}] Axios Error: ${JSON.stringify(error.message)}`);
heartbeat.msg = error.message;
}
}
}
}
}
module.exports = {
RabbitMqMonitorType,
};

View file

@ -718,6 +718,8 @@ let needSetup = false;
monitor.conditions = JSON.stringify(monitor.conditions);
monitor.rabbitmqNodes = JSON.stringify(monitor.rabbitmqNodes);
bean.import(monitor);
bean.user_id = socket.userID;
@ -727,7 +729,7 @@ let needSetup = false;
await updateMonitorNotification(bean.id, notificationIDList);
await server.sendUpdateMonitorIntoList(socket, bean.id);
await server.sendUpdateMonitorsIntoList(socket, bean.id);
if (monitor.active !== false) {
await startMonitor(socket.userID, bean.id);
@ -868,6 +870,9 @@ let needSetup = false;
bean.snmpOid = monitor.snmpOid;
bean.jsonPathOperator = monitor.jsonPathOperator;
bean.timeout = monitor.timeout;
bean.rabbitmqNodes = JSON.stringify(monitor.rabbitmqNodes);
bean.rabbitmqUsername = monitor.rabbitmqUsername;
bean.rabbitmqPassword = monitor.rabbitmqPassword;
bean.conditions = JSON.stringify(monitor.conditions);
bean.validate();
@ -884,7 +889,7 @@ let needSetup = false;
await restartMonitor(socket.userID, bean.id);
}
await server.sendUpdateMonitorIntoList(socket, bean.id);
await server.sendUpdateMonitorsIntoList(socket, bean.id);
callback({
ok: true,
@ -985,7 +990,9 @@ let needSetup = false;
try {
checkLogin(socket);
await startMonitor(socket.userID, monitorID);
await server.sendUpdateMonitorIntoList(socket, monitorID);
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
await server.sendUpdateMonitorsIntoList(socket, [ monitorID, ...childrenIDs ]);
callback({
ok: true,
@ -1005,7 +1012,9 @@ let needSetup = false;
try {
checkLogin(socket);
await pauseMonitor(socket.userID, monitorID);
await server.sendUpdateMonitorIntoList(socket, monitorID);
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
await server.sendUpdateMonitorsIntoList(socket, [ monitorID, ...childrenIDs ]);
callback({
ok: true,
@ -1748,16 +1757,19 @@ async function startMonitor(userID, monitorID) {
userID,
]);
let monitor = await R.findOne("monitor", " id = ? ", [
monitorID,
]);
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID, true);
const monitorIDs = [ monitorID, ...childrenIDs ];
let monitors = await R.find("monitor", ` id IN (${monitorIDs.map((_) => "?").join(",")})`, monitorIDs);
await Promise.all(monitors.map(async (monitor) => {
if (monitor.id in server.monitorList) {
await server.monitorList[monitor.id].stop();
}
server.monitorList[monitor.id] = monitor;
await monitor.start(io);
}));
}
/**
@ -1786,10 +1798,16 @@ async function pauseMonitor(userID, monitorID) {
userID,
]);
if (monitorID in server.monitorList) {
await server.monitorList[monitorID].stop();
server.monitorList[monitorID].active = 0;
const childrenIDs = await Monitor.getAllChildrenIDs(monitorID);
const monitorIDs = [ monitorID, ...childrenIDs ];
await Promise.all(monitorIDs.map(async (currentMonitorID) => {
if (currentMonitorID in server.monitorList) {
await server.monitorList[currentMonitorID].stop();
}
}));
server.monitorList[monitorID].active = 0;
}
/**
@ -1797,7 +1815,7 @@ async function pauseMonitor(userID, monitorID) {
* @returns {Promise<void>}
*/
async function startMonitors() {
let list = await R.find("monitor", " active = 1 ");
let list = await Monitor.getAllActiveMonitors();
for (let monitor of list) {
server.monitorList[monitor.id] = monitor;

View file

@ -115,6 +115,7 @@ class UptimeKumaServer {
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
// Allow all CORS origins (polling) in development
let cors = undefined;
@ -208,12 +209,16 @@ class UptimeKumaServer {
/**
* Update Monitor into list
* @param {Socket} socket Socket to send list on
* @param {number} monitorID update or deleted monitor id
* @param {number | number[]} monitorIDs update or deleted monitor ids
* @returns {Promise<void>}
*/
async sendUpdateMonitorIntoList(socket, monitorID) {
let list = await this.getMonitorJSONList(socket.userID, monitorID);
this.io.to(socket.userID).emit("updateMonitorIntoList", list);
async sendUpdateMonitorsIntoList(socket, monitorIDs) {
if (!Array.isArray(monitorIDs)) {
monitorIDs = [ monitorIDs ];
}
let list = await this.getMonitorJSONList(socket.userID, monitorIDs);
this.io.to(socket.userID).emit("updateMonitorsIntoList", list);
}
/**
@ -229,19 +234,19 @@ class UptimeKumaServer {
/**
* Get a list of monitors for the given user.
* @param {string} userID - The ID of the user to get monitors for.
* @param {number} monitorID - The ID of monitor for.
* @param {number[]} monitorIDs - The IDs of monitors for.
* @returns {Promise<object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
*
* Generated by Trelent
*/
async getMonitorJSONList(userID, monitorID = null) {
async getMonitorJSONList(userID, monitorIDs = null) {
let query = " user_id = ? ";
let queryParams = [ userID ];
if (monitorID) {
query += "AND id = ? ";
queryParams.push(monitorID);
if (monitorIDs) {
query += `AND id IN (${monitorIDs.map((_) => "?").join(",")}) `;
queryParams.push(...monitorIDs);
}
let monitorList = await R.find("monitor", query + "ORDER BY weight DESC, name", queryParams);
@ -552,4 +557,5 @@ const { DnsMonitorType } = require("./monitor-types/dns");
const { MqttMonitorType } = require("./monitor-types/mqtt");
const { SNMPMonitorType } = require("./monitor-types/snmp");
const { MongodbMonitorType } = require("./monitor-types/mongodb");
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
const Monitor = require("./model/monitor");

View file

@ -4,12 +4,18 @@
<div
v-for="(beat, index) in shortBeatList"
:key="index"
class="beat-hover-area"
:class="{ 'empty': (beat === 0) }"
:style="beatHoverAreaStyle"
:title="getBeatTitle(beat)"
>
<div
class="beat"
:class="{ 'empty': (beat === 0), 'down': (beat.status === 0), 'pending': (beat.status === 2), 'maintenance': (beat.status === 3) }"
:style="beatStyle"
:title="getBeatTitle(beat)"
/>
</div>
</div>
<div
v-if="!$root.isMobile && size !== 'small' && beatList.length > 4 && $root.styleElapsedTime !== 'none'"
class="d-flex justify-content-between align-items-center word" :style="timeStyle"
@ -47,7 +53,7 @@ export default {
beatWidth: 10,
beatHeight: 30,
hoverScale: 1.5,
beatMargin: 4,
beatHoverAreaPadding: 4,
move: false,
maxBeat: -1,
};
@ -123,7 +129,7 @@ export default {
barStyle() {
if (this.move && this.shortBeatList.length > this.maxBeat) {
let width = -(this.beatWidth + this.beatMargin * 2);
let width = -(this.beatWidth + this.beatHoverAreaPadding * 2);
return {
transition: "all ease-in-out 0.25s",
@ -137,12 +143,17 @@ export default {
},
beatHoverAreaStyle() {
return {
padding: this.beatHoverAreaPadding + "px",
"--hover-scale": this.hoverScale,
};
},
beatStyle() {
return {
width: this.beatWidth + "px",
height: this.beatHeight + "px",
margin: this.beatMargin + "px",
"--hover-scale": this.hoverScale,
};
},
@ -152,7 +163,7 @@ export default {
*/
timeStyle() {
return {
"margin-left": this.numPadding * (this.beatWidth + this.beatMargin * 2) + "px",
"margin-left": this.numPadding * (this.beatWidth + this.beatHoverAreaPadding * 2) + "px",
};
},
@ -219,20 +230,20 @@ export default {
if (this.size !== "big") {
this.beatWidth = 5;
this.beatHeight = 16;
this.beatMargin = 2;
this.beatHoverAreaPadding = 2;
}
// Suddenly, have an idea how to handle it universally.
// If the pixel * ratio != Integer, then it causes render issue, round it to solve it!!
const actualWidth = this.beatWidth * window.devicePixelRatio;
const actualMargin = this.beatMargin * window.devicePixelRatio;
const actualHoverAreaPadding = this.beatHoverAreaPadding * window.devicePixelRatio;
if (!Number.isInteger(actualWidth)) {
this.beatWidth = Math.round(actualWidth) / window.devicePixelRatio;
}
if (!Number.isInteger(actualMargin)) {
this.beatMargin = Math.round(actualMargin) / window.devicePixelRatio;
if (!Number.isInteger(actualHoverAreaPadding)) {
this.beatHoverAreaPadding = Math.round(actualHoverAreaPadding) / window.devicePixelRatio;
}
window.addEventListener("resize", this.resize);
@ -245,7 +256,7 @@ export default {
*/
resize() {
if (this.$refs.wrap) {
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatMargin * 2));
this.maxBeat = Math.floor(this.$refs.wrap.clientWidth / (this.beatWidth + this.beatHoverAreaPadding * 2));
}
},
@ -273,11 +284,25 @@ export default {
}
.hp-bar-big {
.beat {
.beat-hover-area {
display: inline-block;
&:not(.empty):hover {
transition: all ease-in-out 0.15s;
opacity: 0.8;
transform: scale(var(--hover-scale));
}
.beat {
background-color: $primary;
border-radius: $border-radius;
/*
pointer-events needs to be changed because
tooltip momentarily disappears when crossing between .beat-hover-area and .beat
*/
pointer-events: none;
&.empty {
background-color: aliceblue;
}
@ -293,11 +318,6 @@ export default {
&.maintenance {
background-color: $maintenance;
}
&:not(.empty):hover {
transition: all ease-in-out 0.15s;
opacity: 0.8;
transform: scale(var(--hover-scale));
}
}
}

View file

@ -1052,6 +1052,13 @@
"Can be found on:": "Can be found on: {0}",
"The phone number of the recipient in E.164 format.": "The phone number of the recipient in E.164 format.",
"Either a text sender ID or a phone number in E.164 format if you want to be able to receive replies.":"Either a text sender ID or a phone number in E.164 format if you want to be able to receive replies.",
"RabbitMQ Nodes": "RabbitMQ Management Nodes",
"rabbitmqNodesDescription": "Enter the URL for the RabbitMQ management nodes including protocol and port. Example: {0}",
"rabbitmqNodesRequired": "Please set the nodes for this monitor.",
"rabbitmqNodesInvalid": "Please use a fully qualified (starting with 'http') URL for RabbitMQ nodes.",
"RabbitMQ Username": "RabbitMQ Username",
"RabbitMQ Password": "RabbitMQ Password",
"rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.",
"SendGrid API Key": "SendGrid API Key",
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
}

View file

@ -145,7 +145,7 @@ export default {
this.monitorList = data;
});
socket.on("updateMonitorIntoList", (data) => {
socket.on("updateMonitorsIntoList", (data) => {
this.assignMonitorUrlParser(data);
Object.entries(data).forEach(([ monitorID, updatedMonitor ]) => {
this.monitorList[monitorID] = updatedMonitor;

View file

@ -64,6 +64,9 @@
<option value="mqtt">
MQTT
</option>
<option value="rabbitmq">
RabbitMQ
</option>
<option value="kafka-producer">
Kafka Producer
</option>
@ -90,6 +93,13 @@
</option>
</optgroup>
</select>
<i18n-t v-if="monitor.type === 'rabbitmq'" keypath="rabbitmqHelpText" tag="div" class="form-text">
<template #rabitmq_documentation>
<a href="https://www.rabbitmq.com/management" target="_blank" rel="noopener noreferrer">
RabbitMQ documentation
</a>
</template>
</i18n-t>
</div>
<div v-if="monitor.type === 'tailscale-ping'" class="alert alert-warning" role="alert">
@ -233,6 +243,43 @@
</div>
</template>
<template v-if="monitor.type === 'rabbitmq'">
<!-- RabbitMQ Nodes List -->
<div class="my-3">
<label for="rabbitmqNodes" class="form-label">{{ $t("RabbitMQ Nodes") }}</label>
<VueMultiselect
id="rabbitmqNodes"
v-model="monitor.rabbitmqNodes"
:required="true"
:multiple="true"
:options="[]"
:placeholder="$t('Enter the list of nodes')"
:tag-placeholder="$t('Press Enter to add node')"
:max-height="500"
:taggable="true"
:show-no-options="false"
:close-on-select="false"
:clear-on-select="false"
:preserve-search="false"
:preselect-first="false"
@tag="addRabbitmqNode"
></VueMultiselect>
<div class="form-text">
{{ $t("rabbitmqNodesDescription", ["https://node1.rabbitmq.com:15672"]) }}
</div>
</div>
<div class="my-3">
<label for="rabbitmqUsername" class="form-label">RabbitMQ {{ $t("RabbitMQ Username") }}</label>
<input id="rabbitmqUsername" v-model="monitor.rabbitmqUsername" type="text" required class="form-control">
</div>
<div class="my-3">
<label for="rabbitmqPassword" class="form-label">{{ $t("RabbitMQ Password") }}</label>
<HiddenInput id="rabbitmqPassword" v-model="monitor.rabbitmqPassword" autocomplete="false" required="true"></HiddenInput>
</div>
</template>
<!-- Hostname -->
<!-- TCP Port / Ping / DNS / Steam / MQTT / Radius / Tailscale Ping / SNMP only -->
<div v-if="monitor.type === 'port' || monitor.type === 'ping' || monitor.type === 'dns' || monitor.type === 'steam' || monitor.type === 'gamedig' || monitor.type === 'mqtt' || monitor.type === 'radius' || monitor.type === 'tailscale-ping' || monitor.type === 'snmp'" class="my-3">
@ -549,7 +596,7 @@
</div>
<!-- Timeout: HTTP / Keyword / SNMP only -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'snmp'" class="my-3">
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'snmp' || monitor.type === 'rabbitmq'" class="my-3">
<label for="timeout" class="form-label">{{ $t("Request Timeout") }} ({{ $t("timeoutAfter", [ monitor.timeout || clampTimeout(monitor.interval) ]) }})</label>
<input id="timeout" v-model="monitor.timeout" type="number" class="form-control" required min="0" step="0.1">
</div>
@ -1122,6 +1169,9 @@ const monitorDefaults = {
kafkaProducerAllowAutoTopicCreation: false,
gamedigGivenPortOnly: true,
remote_browser: null,
rabbitmqNodes: [],
rabbitmqUsername: "",
rabbitmqPassword: "",
conditions: []
};
@ -1709,6 +1759,10 @@ message HealthCheckResponse {
this.monitor.kafkaProducerBrokers.push(newBroker);
},
addRabbitmqNode(newNode) {
this.monitor.rabbitmqNodes.push(newNode);
},
/**
* Validate form input
* @returns {boolean} Is the form input valid?
@ -1736,6 +1790,17 @@ message HealthCheckResponse {
return false;
}
}
if (this.monitor.type === "rabbitmq") {
if (this.monitor.rabbitmqNodes.length === 0) {
toast.error(this.$t("rabbitmqNodesRequired"));
return false;
}
if (!this.monitor.rabbitmqNodes.every(node => node.startsWith("http://") || node.startsWith("https://"))) {
toast.error(this.$t("rabbitmqNodesInvalid"));
return false;
}
}
return true;
},

View file

@ -0,0 +1,53 @@
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { RabbitMQContainer } = require("@testcontainers/rabbitmq");
const { RabbitMqMonitorType } = require("../../server/monitor-types/rabbitmq");
const { UP, DOWN, PENDING } = require("../../src/util");
describe("RabbitMQ Single Node", {
skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),
}, () => {
test("RabbitMQ is running", async () => {
// The default timeout of 30 seconds might not be enough for the container to start
const rabbitMQContainer = await new RabbitMQContainer().withStartupTimeout(60000).start();
const rabbitMQMonitor = new RabbitMqMonitorType();
const connectionString = `http://${rabbitMQContainer.getHost()}:${rabbitMQContainer.getMappedPort(15672)}`;
const monitor = {
rabbitmqNodes: JSON.stringify([ connectionString ]),
rabbitmqUsername: "guest",
rabbitmqPassword: "guest",
};
const heartbeat = {
msg: "",
status: PENDING,
};
try {
await rabbitMQMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, UP);
assert.strictEqual(heartbeat.msg, "OK");
} finally {
rabbitMQContainer.stop();
}
});
test("RabbitMQ is not running", async () => {
const rabbitMQMonitor = new RabbitMqMonitorType();
const monitor = {
rabbitmqNodes: JSON.stringify([ "http://localhost:15672" ]),
rabbitmqUsername: "rabbitmqUser",
rabbitmqPassword: "rabbitmqPass",
};
const heartbeat = {
msg: "",
status: PENDING,
};
await rabbitMQMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, DOWN);
});
});