mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-30 18:24:03 +00:00
Merge 21a2d3c681
into d7ffa33950
This commit is contained in:
commit
610c6358a3
7 changed files with 153 additions and 1 deletions
17
db/knex_migrations/2024-10-1315-rabbitmq-monitor.js
Normal file
17
db/knex_migrations/2024-10-1315-rabbitmq-monitor.js
Normal 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");
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
|
@ -153,6 +153,7 @@ class Monitor extends BeanModel {
|
||||||
snmpOid: this.snmpOid,
|
snmpOid: this.snmpOid,
|
||||||
jsonPathOperator: this.jsonPathOperator,
|
jsonPathOperator: this.jsonPathOperator,
|
||||||
snmpVersion: this.snmpVersion,
|
snmpVersion: this.snmpVersion,
|
||||||
|
rabbitmqNodes: JSON.parse(this.rabbitmqNodes),
|
||||||
conditions: JSON.parse(this.conditions),
|
conditions: JSON.parse(this.conditions),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -183,6 +184,8 @@ class Monitor extends BeanModel {
|
||||||
tlsCert: this.tlsCert,
|
tlsCert: this.tlsCert,
|
||||||
tlsKey: this.tlsKey,
|
tlsKey: this.tlsKey,
|
||||||
kafkaProducerSaslOptions: JSON.parse(this.kafkaProducerSaslOptions),
|
kafkaProducerSaslOptions: JSON.parse(this.kafkaProducerSaslOptions),
|
||||||
|
rabbitmqUsername: this.rabbitmqUsername,
|
||||||
|
rabbitmqPassword: this.rabbitmqPassword,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
61
server/monitor-types/rabbitmq.js
Normal file
61
server/monitor-types/rabbitmq.js
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
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 (const baseUrl of baseUrls) {
|
||||||
|
try {
|
||||||
|
const options = {
|
||||||
|
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"),
|
||||||
|
},
|
||||||
|
// Use axios signal to handle connection timeouts https://stackoverflow.com/a/74739938
|
||||||
|
signal: axiosAbortSignal((monitor.timeout + 10) * 1000),
|
||||||
|
validateStatus: () => true,
|
||||||
|
};
|
||||||
|
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 {
|
||||||
|
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,
|
||||||
|
};
|
|
@ -718,6 +718,8 @@ let needSetup = false;
|
||||||
|
|
||||||
monitor.conditions = JSON.stringify(monitor.conditions);
|
monitor.conditions = JSON.stringify(monitor.conditions);
|
||||||
|
|
||||||
|
monitor.rabbitmqNodes = JSON.stringify(monitor.rabbitmqNodes);
|
||||||
|
|
||||||
bean.import(monitor);
|
bean.import(monitor);
|
||||||
bean.user_id = socket.userID;
|
bean.user_id = socket.userID;
|
||||||
|
|
||||||
|
@ -868,6 +870,9 @@ let needSetup = false;
|
||||||
bean.snmpOid = monitor.snmpOid;
|
bean.snmpOid = monitor.snmpOid;
|
||||||
bean.jsonPathOperator = monitor.jsonPathOperator;
|
bean.jsonPathOperator = monitor.jsonPathOperator;
|
||||||
bean.timeout = monitor.timeout;
|
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.conditions = JSON.stringify(monitor.conditions);
|
||||||
|
|
||||||
bean.validate();
|
bean.validate();
|
||||||
|
|
|
@ -115,6 +115,7 @@ class UptimeKumaServer {
|
||||||
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
|
UptimeKumaServer.monitorTypeList["mqtt"] = new MqttMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
|
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
|
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
|
||||||
|
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
|
||||||
|
|
||||||
// Allow all CORS origins (polling) in development
|
// Allow all CORS origins (polling) in development
|
||||||
let cors = undefined;
|
let cors = undefined;
|
||||||
|
@ -552,4 +553,5 @@ const { DnsMonitorType } = require("./monitor-types/dns");
|
||||||
const { MqttMonitorType } = require("./monitor-types/mqtt");
|
const { MqttMonitorType } = require("./monitor-types/mqtt");
|
||||||
const { SNMPMonitorType } = require("./monitor-types/snmp");
|
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 Monitor = require("./model/monitor");
|
const Monitor = require("./model/monitor");
|
||||||
|
|
|
@ -1052,6 +1052,12 @@
|
||||||
"Can be found on:": "Can be found on: {0}",
|
"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.",
|
"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.",
|
"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 complete URL for RabbitMQ nodes.",
|
||||||
|
"RabbitMQ Username": "RabbitMQ Username",
|
||||||
|
"RabbitMQ Password": "RabbitMQ Password",
|
||||||
"SendGrid API Key": "SendGrid API Key",
|
"SendGrid API Key": "SendGrid API Key",
|
||||||
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
|
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,9 @@
|
||||||
<option value="mqtt">
|
<option value="mqtt">
|
||||||
MQTT
|
MQTT
|
||||||
</option>
|
</option>
|
||||||
|
<option value="rabbitmq">
|
||||||
|
RabbitMQ (using Management Plugin)
|
||||||
|
</option>
|
||||||
<option value="kafka-producer">
|
<option value="kafka-producer">
|
||||||
Kafka Producer
|
Kafka Producer
|
||||||
</option>
|
</option>
|
||||||
|
@ -233,6 +236,43 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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 -->
|
<!-- Hostname -->
|
||||||
<!-- TCP Port / Ping / DNS / Steam / MQTT / Radius / Tailscale Ping / SNMP only -->
|
<!-- 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">
|
<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 +589,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Timeout: HTTP / Keyword / SNMP only -->
|
<!-- 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>
|
<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">
|
<input id="timeout" v-model="monitor.timeout" type="number" class="form-control" required min="0" step="0.1">
|
||||||
</div>
|
</div>
|
||||||
|
@ -1122,6 +1162,9 @@ const monitorDefaults = {
|
||||||
kafkaProducerAllowAutoTopicCreation: false,
|
kafkaProducerAllowAutoTopicCreation: false,
|
||||||
gamedigGivenPortOnly: true,
|
gamedigGivenPortOnly: true,
|
||||||
remote_browser: null,
|
remote_browser: null,
|
||||||
|
rabbitmqNodes: [],
|
||||||
|
rabbitmqUsername: "",
|
||||||
|
rabbitmqPassword: "",
|
||||||
conditions: []
|
conditions: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1709,6 +1752,10 @@ message HealthCheckResponse {
|
||||||
this.monitor.kafkaProducerBrokers.push(newBroker);
|
this.monitor.kafkaProducerBrokers.push(newBroker);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addRabbitmqNode(newNode) {
|
||||||
|
this.monitor.rabbitmqNodes.push(newNode);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate form input
|
* Validate form input
|
||||||
* @returns {boolean} Is the form input valid?
|
* @returns {boolean} Is the form input valid?
|
||||||
|
@ -1736,6 +1783,17 @@ message HealthCheckResponse {
|
||||||
return false;
|
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;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue