Open gorkem-bwl opened 2 months ago
Hello @gorkem-bwl Seems interesting, this issue would be fun to work on. I would like to work on this issue.
Hello @gorkem-bwl Seems interesting, this issue would be fun to work on. I would like to work on this issue.
That’s a great addition indeed, and definitely worth addressing. Could you draft an implementation plan for this? You might also want to take a look at how Uptime Kuma handles it for some inspiration.
Hey, @gorkem-bwl Here is the Implementation Plan for ntfy Integration
I have reviewed the email notification provider in Bluewave Uptime and the ntfy notification integration in Uptime Kuma to explore how we can integrate ntfy notifications into Bluewave Uptime. Here's a summary of my findings and proposed approach:
Understanding Uptime Kuma’s Notification Architecture
NotificationProvider
. title()
, send()
, and message()
. This design provides a modular approach, allowing different providers to be plugged in easily.How Bluewave Uptime Manages Notifications
Proposal for ntfy Integration
https://ntfy.sh
), etc.Route Handling for ntfy notifications
This approach aligns with the existing architecture of Bluewave Uptime while drawing inspiration from Uptime Kuma's modularity. Let me know if further refinements are needed!
Thanks for pulling things together. However, please ensure that all the details are fully outlined in the implementation document. Using AI for the documentation is good, but this task requires a more committed approach. For instance, I don't see any mention of the UI options for ntfy.sh. What are other user inputs? (eg how do you handle authentication?). How do you plan to develop back-end related tasks? You can also remove "How Bluewave Uptime Manages Notifications" as it's not related to this task.
Let me know your thoughts!
Thanks for the feedback. I will rewrite the draft in a more detailed manner by tomorrow.
Thank you.
@aryanp-86 just wanted to check back here to see if there is any progress on your end. Thanks!
Still working on it. Will update you soon.
Hey @gorkem-bwl Here is the detailed implementation draft.
On the UI side, we will show a checkbox of "Notify via ntfy.sh" in the incidents section which on enabling will request users to enter required fields like friendly name, topic, server url, priority and authentication mode.
Taking inspiration from Uptime Kuma's design, I have also added three auth modes. By default it will be set to no auth( which is the easiest way for the user to test ntfy.sh). The other options being username-password and access token for secured ntfy.sh servers.
Users can test the ntfy.sh connection using the test button which runs a axios request using the config provided. On saving, the ntfy config is added to the monitor state's notification array.
Notification model:
const NotificationSchema = mongoose.Schema(
{
monitorId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Monitor",
immutable: true,
},
type: {
type: String,
enum: ["email", "sms", "ntfy"],
},
ntfyConfig: {
type: Object,
},
address: {
type: String,
},
phone: {
type: String,
},
},
{
timestamps: true,
}
);
export default mongoose.model("Notification", NotificationSchema);
Backend
for (const notification of notifications) {
if (notification.type === "email") {
await this.emailService.buildAndSendEmail(
template,
{ monitorName: monitor.name, monitorUrl: monitor.url },
notification.address,
`Monitor ${monitor.name} is ${status}`
);
} else if (notification.type === "ntfy") {
console.log("ntfy reached");
await this.sendNtfyNotification(monitor, isAlive);
}
}
We also need to add a custom sendNtfyNotification method that will send the incident message based upon monitor status.
async sendNtfyNotification(monitor, isAlive) {
try {
const status = isAlive ? "up" : "down";
const message = `Monitor ${monitor.name} is ${status}`;
// Send the Ntfy notification using the configuration from the notification object
const ntfyConfig = monitor.notifications.find((n) => n.type === "ntfy")?.ntfyConfig;
console.log(ntfyConfig)
await this.axios.post(`${ntfyConfig.serverUrl}/${ntfyConfig.topic}`, {
title: `Monitor ${status}`,
message: message,
priority: isAlive ? 5 : 1,
});
} catch (error) {
this.logger.error(`Failed to send Ntfy notification: ${error.message}`, {
method: "sendNtfyNotification",
service: this.SERVICE_NAME,
monitorId: monitor._id,
});
}
}
Let me know if further refinements are needed!
Looks good. Thanks for the detailed implementation plan. Let's move forward with this!
@aryanp-86 I'm working on cleaning up the notification process and network service at the moment, so if you could start from the front end that would be great!
We can work out the back end implementation once the refactoring is done :+1:
Ok great. Actually, I am almost ready with the frontend code. Would you please ping me once the refactoring is done?
Ntfy.sh is a library that helps send push notifications to your phone or desktop via scripts from any computer, and/or using a REST API.
When integrated with BlueWave Uptime, it can send incidents to a smartphone running the ntfy application.
One advantage is that it's faster than email notifications.