-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,625 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
|
||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const NotificationProvider = require("./notification-provider"); | ||
const axios = require("axios"); | ||
|
||
class Elks extends NotificationProvider { | ||
name = "Elks"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||
const okMsg = "Sent Successfully."; | ||
const url = "https://api.46elks.com/a1/sms"; | ||
|
||
try { | ||
let data = new URLSearchParams(); | ||
data.append("from", notification.elksFromNumber); | ||
data.append("to", notification.elksToNumber ); | ||
data.append("message", msg); | ||
|
||
const config = { | ||
headers: { | ||
"Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64") | ||
} | ||
}; | ||
|
||
await axios.post(url, data, config); | ||
|
||
return okMsg; | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Elks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const NotificationProvider = require("./notification-provider"); | ||
const axios = require("axios"); | ||
|
||
class SendGrid extends NotificationProvider { | ||
name = "SendGrid"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||
const okMsg = "Sent Successfully."; | ||
|
||
try { | ||
let config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${notification.sendgridApiKey}`, | ||
}, | ||
}; | ||
|
||
let personalizations = { | ||
to: [{ email: notification.sendgridToEmail }], | ||
}; | ||
|
||
// Add CC recipients if provided | ||
if (notification.sendgridCcEmail) { | ||
personalizations.cc = notification.sendgridCcEmail | ||
.split(",") | ||
.map((email) => ({ email: email.trim() })); | ||
} | ||
|
||
// Add BCC recipients if provided | ||
if (notification.sendgridBccEmail) { | ||
personalizations.bcc = notification.sendgridBccEmail | ||
.split(",") | ||
.map((email) => ({ email: email.trim() })); | ||
} | ||
|
||
let data = { | ||
personalizations: [ personalizations ], | ||
from: { email: notification.sendgridFromEmail.trim() }, | ||
subject: | ||
notification.sendgridSubject || | ||
"Notification from Your Uptime Kuma", | ||
content: [ | ||
{ | ||
type: "text/plain", | ||
value: msg, | ||
}, | ||
], | ||
}; | ||
|
||
await axios.post( | ||
"https://api.sendgrid.com/v3/mail/send", | ||
data, | ||
config | ||
); | ||
return okMsg; | ||
} catch (error) { | ||
this.throwGeneralAxiosError(error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = SendGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.