bluewave-labs / bluewave-uptime

BlueWave Uptime Monitor application
https://uptime-demo.bluewavelabs.ca/
GNU Affero General Public License v3.0
443 stars 52 forks source link

Add ntfy.sh support #702

Open gorkem-bwl opened 2 months ago

gorkem-bwl commented 2 months ago

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.

aryanp-86 commented 1 week ago

Hello @gorkem-bwl Seems interesting, this issue would be fun to work on. I would like to work on this issue.

gorkem-bwl commented 1 week ago

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.

aryanp-86 commented 5 days ago

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:

  1. Understanding Uptime Kuma’s Notification Architecture

    • Uptime Kuma uses an abstract class called NotificationProvider.
    • Any new notification service must extend this class and implement key methods like title(), send(), and message(). This design provides a modular approach, allowing different providers to be plugged in easily.
  2. How Bluewave Uptime Manages Notifications

    • In Bluewave Uptime, users configure email notifications while creating a monitor. A checkbox is provided to enable or disable sending emails to the default user email configured at login.
  3. Proposal for ntfy Integration

    • We can enhance the existing monitor creation form by adding an option for ntfy notifications.
    • Users will provide:
      • Topic
      • Friendly Name (optional display name for the service)
      • Server URL (default: https://ntfy.sh), etc.
  4. Route Handling for ntfy notifications

    • On form submission, we will to manage the ntfy notification logic via a route handler at the server side. This handler will send messages using the provided configuration.
    • This ensures that notifications are sent seamlessly whenever the monitor status changes.

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!

gorkem-bwl commented 5 days ago

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!

aryanp-86 commented 5 days ago

Thanks for the feedback. I will rewrite the draft in a more detailed manner by tomorrow.

gorkem-bwl commented 5 days ago

Thank you.

gorkem-bwl commented 2 days ago

@aryanp-86 just wanted to check back here to see if there is any progress on your end. Thanks!

aryanp-86 commented 2 days ago

Still working on it. Will update you soon.

aryanp-86 commented 1 day ago

Hey @gorkem-bwl Here is the detailed implementation draft.

  1. User Interface

Screenshot 2024-10-25 at 19-50-48 BlueWave Uptime Screenshot 2024-10-25 at 19-51-20 BlueWave Uptime

  1. Notification model:

    • The notification model needs to be updated to support the ntfy options.
      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);
  2. 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);
    }
}
gorkem-bwl commented 23 hours ago

Looks good. Thanks for the detailed implementation plan. Let's move forward with this!

ajhollid commented 19 hours ago

@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:

aryanp-86 commented 17 hours ago

Ok great. Actually, I am almost ready with the frontend code. Would you please ping me once the refactoring is done?