feat(alerts): add ntfy notification provider with TUI support

POST to ntfy server/topic with title, priority, and optional basic auth.
TUI alert form includes ntfy type with server URL, topic, priority
selector (1-5), and credential fields.
This commit is contained in:
2026-05-14 17:25:22 -04:00
parent 93fe372497
commit a1f22af179
2 changed files with 105 additions and 9 deletions
+40
View File
@@ -7,6 +7,7 @@ import (
"go-upkeep/internal/models"
"net/http"
"net/smtp"
"strings"
"time"
)
@@ -38,6 +39,18 @@ func GetProvider(cfg models.AlertConfig) Provider {
To: cfg.Settings["to"],
From: cfg.Settings["from"],
}
case "ntfy":
priority := "3"
if p, ok := cfg.Settings["priority"]; ok && p != "" {
priority = p
}
return &NtfyProvider{
ServerURL: cfg.Settings["url"],
Topic: cfg.Settings["topic"],
Priority: priority,
Username: cfg.Settings["username"],
Password: cfg.Settings["password"],
}
default:
return nil
}
@@ -102,3 +115,30 @@ func (e *EmailProvider) Send(title, message string) error {
message + "\r\n")
return smtp.SendMail(e.Host+":"+e.Port, auth, e.From, []string{e.To}, msg)
}
type NtfyProvider struct {
ServerURL string
Topic string
Priority string
Username string
Password string
}
func (n *NtfyProvider) Send(title, message string) error {
url := strings.TrimRight(n.ServerURL, "/") + "/" + n.Topic
req, err := http.NewRequest("POST", url, strings.NewReader(message))
if err != nil {
return err
}
req.Header.Set("Title", title)
req.Header.Set("Priority", n.Priority)
if n.Username != "" && n.Password != "" {
req.SetBasicAuth(n.Username, n.Password)
}
resp, err := alertClient.Do(req)
if err != nil {
return err
}
resp.Body.Close()
return nil
}