mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-17 09:05:56 +00:00
Make requested changes
This commit is contained in:
parent
44cd675910
commit
009b004756
3 changed files with 23 additions and 34 deletions
|
@ -10,16 +10,16 @@ class RabbitMqMonitorType extends MonitorType {
|
|||
* @inheritdoc
|
||||
*/
|
||||
async check(monitor, heartbeat, server) {
|
||||
// HTTP basic auth
|
||||
let basicAuthHeader = {};
|
||||
basicAuthHeader = {
|
||||
"Authorization": "Basic " + this.encodeBase64(monitor.rabbitmqUsername, monitor.rabbitmqPassword),
|
||||
};
|
||||
let baseUrls = [];
|
||||
try {
|
||||
baseUrls = JSON.parse(monitor.rabbitmqNodes);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error("Invalid RabbitMQ Nodes");
|
||||
}
|
||||
|
||||
let status = DOWN;
|
||||
let msg = "";
|
||||
|
||||
for (const baseUrl of JSON.parse(monitor.rabbitmqNodes)) {
|
||||
heartbeat.status = DOWN;
|
||||
for (const baseUrl of baseUrls) {
|
||||
try {
|
||||
const options = {
|
||||
url: new URL("/api/health/checks/alarms", baseUrl).href,
|
||||
|
@ -27,8 +27,9 @@ class RabbitMqMonitorType extends MonitorType {
|
|||
timeout: monitor.timeout * 1000,
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
...(basicAuthHeader),
|
||||
"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,
|
||||
};
|
||||
|
@ -36,36 +37,22 @@ class RabbitMqMonitorType extends MonitorType {
|
|||
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) {
|
||||
status = UP;
|
||||
msg = "OK";
|
||||
heartbeat.status = UP;
|
||||
heartbeat.msg = "OK";
|
||||
break;
|
||||
} else {
|
||||
msg = `${res.status} - ${res.statusText}`;
|
||||
heartbeat.msg = `${res.status} - ${res.statusText}`;
|
||||
}
|
||||
} catch (error) {
|
||||
if (axios.isCancel(error)) {
|
||||
msg = "Request timed out";
|
||||
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)}`);
|
||||
msg = error.message;
|
||||
heartbeat.msg = error.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heartbeat.msg = msg;
|
||||
heartbeat.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode user and password to Base64 encoding
|
||||
* for HTTP "basic" auth, as per RFC-7617
|
||||
* @param {string|null} user - The username (nullable if not changed by a user)
|
||||
* @param {string|null} pass - The password (nullable if not changed by a user)
|
||||
* @returns {string} Encoded Base64 string
|
||||
*/
|
||||
encodeBase64(user, pass) {
|
||||
return Buffer.from(`${user || ""}:${pass || ""}`).toString("base64");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1053,7 +1053,9 @@
|
|||
"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: https://node1.rabbitmq.com:15672",
|
||||
"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 complete URL for RabbitMQ nodes."
|
||||
"rabbitmqNodesInvalid": "Please use a complete URL for RabbitMQ nodes.",
|
||||
"RabbitMQ Username": "RabbitMQ Username",
|
||||
"RabbitMQ Password": "RabbitMQ Password"
|
||||
}
|
||||
|
|
|
@ -258,17 +258,17 @@
|
|||
@tag="addRabbitmqNode"
|
||||
></VueMultiselect>
|
||||
<div class="form-text">
|
||||
{{ $t("rabbitmqNodesDescription") }}
|
||||
{{ $t("rabbitmqNodesDescription", ["https://node1.rabbitmq.com:15672"]) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="my-3">
|
||||
<label for="rabbitmqUsername" class="form-label">RabbitMQ {{ $t("Username") }}</label>
|
||||
<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">RabbitMQ {{ $t("Password") }}</label>
|
||||
<label for="rabbitmqPassword" class="form-label">{{ $t("RabbitMQ Password") }}</label>
|
||||
<HiddenInput id="rabbitmqPassword" v-model="monitor.rabbitmqPassword" autocomplete="false" required="true"></HiddenInput>
|
||||
</div>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Reference in a new issue