From b01eefdbce8ab0cee944814a6aa95c938f0d638c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sun, 22 Nov 2026 16:07:24 +0100 Subject: [PATCH] feat: notification channels for chat, push and paging services Channels of the new types store their settings with secrets sealed and bound to type and field, never return them, and keep them when an update leaves them empty. Messages are rendered in the channel's language with a link to the monitor. The channels page offers every service with its fields. Closes #92 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- internal/api/alerting.go | 7 + internal/api/apidocs.go | 5 +- internal/api/channels.go | 15 +- internal/api/console.go | 25 + internal/api/providers.go | 158 ++++ internal/api/providers_test.go | 105 +++ internal/i18n/i18n_test.go | 3 +- internal/i18n/locales/de.json | 55 ++ internal/i18n/locales/en.json | 55 ++ .../sql/00034_notification_providers.sql | 10 + internal/web/monitors.templ | 88 +++ internal/web/monitors_templ.go | 722 ++++++++++++++---- 12 files changed, 1114 insertions(+), 134 deletions(-) create mode 100644 internal/api/providers.go create mode 100644 internal/api/providers_test.go create mode 100644 internal/migrations/sql/00034_notification_providers.sql diff --git a/internal/api/alerting.go b/internal/api/alerting.go index a28bb69..8cb27d5 100644 --- a/internal/api/alerting.go +++ b/internal/api/alerting.go @@ -217,6 +217,13 @@ func (s *Server) send(ctx context.Context, typ string, config []byte, ev notify. } return s.smtp.Send(ctx, s.mailFor(ev, c.To, c.Locale)) } + if p, ok := notify.Lookup(typ); ok { + settings, locale, err := s.openProviderSettings(typ, config) + if err != nil { + return err + } + return p.Send(ctx, settings, s.messageFor(ev, locale), !s.cloud()) + } return fmt.Errorf("unknown channel type %q", typ) } diff --git a/internal/api/apidocs.go b/internal/api/apidocs.go index 0f4c995..9d93e4d 100644 --- a/internal/api/apidocs.go +++ b/internal/api/apidocs.go @@ -121,8 +121,9 @@ var endpoints = []endpoint{ {method: "GET", path: "/api/v1/org/channels", tag: "Alerting", summary: "List notification channels", perm: "notifications.read", resp: obj{"channels": []channelView{}, "email_available": false}}, {method: "POST", path: "/api/v1/org/channels", tag: "Alerting", summary: "Create a channel", - description: "Webhook channels return their signing secret once.", perm: "notifications.write", - req: channelRequest{}, status: http.StatusCreated, resp: obj{"channel": channelView{}, "signing_secret": ""}}, + description: "`type` is webhook (`url`), email (`to`, `locale`) or one of slack, discord, teams, googlechat, mattermost, rocketchat, telegram, matrix, ntfy, gotify, pushover, pushbullet, signal, pagerduty, opsgenie, apprise with their `settings`. Secret settings are stored encrypted and never returned; on update, leaving one empty keeps it. Webhook channels return their signing secret once.", + perm: "notifications.write", + req: channelRequest{}, status: http.StatusCreated, resp: obj{"channel": channelView{}, "signing_secret": ""}}, {method: "PUT", path: "/api/v1/org/channels/:id", tag: "Alerting", summary: "Change a channel", perm: "notifications.write", req: channelRequest{}, resp: obj{"channel": channelView{}, "signing_secret": ""}}, {method: "DELETE", path: "/api/v1/org/channels/:id", tag: "Alerting", summary: "Delete a channel", perm: "notifications.write", diff --git a/internal/api/channels.go b/internal/api/channels.go index e6947a7..8f60bbc 100644 --- a/internal/api/channels.go +++ b/internal/api/channels.go @@ -22,11 +22,14 @@ import ( type channelRequest struct { Name string `json:"name" binding:"required,max=100"` - Type string `json:"type" binding:"required,oneof=webhook email"` + Type string `json:"type" binding:"required,max=32"` URL string `json:"url" binding:"max=2000"` To []string `json:"to" binding:"max=20,dive,max=320"` Locale string `json:"locale" binding:"max=10"` Enabled *bool `json:"enabled"` + // Settings configure the other channel types, as listed by + // notify.Providers; secret settings left empty keep their value. + Settings map[string]string `json:"settings" binding:"max=20"` } type channelView struct { @@ -37,6 +40,10 @@ type channelView struct { URL string `json:"url,omitempty"` To []string `json:"to,omitempty"` Locale string `json:"locale,omitempty"` + // Settings and SecretsSet describe other channel types; secret values + // are never returned. + Settings map[string]string `json:"settings,omitempty"` + SecretsSet []string `json:"secrets_set,omitempty"` } func viewChannel(ch store.NotificationChannel) channelView { @@ -50,6 +57,8 @@ func viewChannel(ch store.NotificationChannel) channelView { var c emailConfig _ = json.Unmarshal(ch.Config, &c) v.To, v.Locale = c.To, c.Locale + default: + v.Settings, v.SecretsSet, v.Locale = providerView(ch.Config) } return v } @@ -109,6 +118,10 @@ func (s *Server) channelConfig(req *channelRequest, previous []byte) (config []b config, _ = json.Marshal(emailConfig{To: req.To, Locale: req.Locale}) return config, "", "" } + if p, ok := notify.Lookup(req.Type); ok { + config, code = s.providerSettings(p, req, previous) + return config, "", code + } return nil, "", "invalid_input" } diff --git a/internal/api/console.go b/internal/api/console.go index da8c551..81cdf62 100644 --- a/internal/api/console.go +++ b/internal/api/console.go @@ -21,6 +21,7 @@ import ( "git.zb-server.de/ZB-Server/uptimesebi/internal/check" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" "git.zb-server.de/ZB-Server/uptimesebi/internal/maintenance" + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify" "git.zb-server.de/ZB-Server/uptimesebi/internal/store" "git.zb-server.de/ZB-Server/uptimesebi/internal/web" ) @@ -663,12 +664,36 @@ func (s *Server) channelsView(c *gin.Context, p *principal, page web.Page, me we return nil, err } v := web.ChannelsView{EmailAvailable: s.smtp != nil, CanWrite: p.Grants.Can(authz.NotificationsWrite), Languages: s.catalog.Supported()} + ctx2 := c.Request.Context() + for _, pr := range notify.Providers { + opt := web.ProviderOption{Type: pr.Type} + if help := i18n.T(ctx2, "channels.help_"+pr.Type); help != "channels.help_"+pr.Type { + opt.Help = help + } + for _, f := range pr.Fields { + opt.Fields = append(opt.Fields, web.ProviderField{ + Name: f.Name, Label: i18n.T(ctx2, "channels.field_"+f.Name), Required: f.Required, Secret: f.Secret, + Kind: f.Kind, Options: f.Options, Default: f.Default, + }) + } + v.Providers = append(v.Providers, opt) + } for _, r := range rows { cv := viewChannel(r) target := cv.URL if cv.Type == "email" { target = strings.Join(cv.To, ", ") } + // Other services show their first setting that is no secret, such + // as the chat, topic or server. + if p, ok := notify.Lookup(cv.Type); ok { + for _, f := range p.Fields { + if v, ok := cv.Settings[f.Name]; ok && !f.Secret { + target = v + break + } + } + } v.Channels = append(v.Channels, web.ChannelRow{ID: r.ID.String(), Name: r.Name, Type: r.Type, Target: target, Enabled: r.Enabled}) } return web.ChannelsPage(page, me, v), nil diff --git a/internal/api/providers.go b/internal/api/providers.go new file mode 100644 index 0000000..0405872 --- /dev/null +++ b/internal/api/providers.go @@ -0,0 +1,158 @@ +package api + +import ( + "encoding/base64" + "encoding/json" + "net/url" + "slices" + "strconv" + "strings" + "time" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify" +) + +// providerConfig is stored for channels of notify.Providers. Secret +// settings are sealed, bound to the channel type and field, and never +// shown again. +type providerConfig struct { + Settings map[string]string `json:"settings"` + Sealed map[string]string `json:"sealed"` + Locale string `json:"locale"` +} + +func secretAAD(typ, field string) []byte { return []byte("channel:" + typ + ":" + field) } + +// providerSettings validates the settings of a provider channel. Secret +// fields left empty keep their previous value, so a form can be saved +// without asking for tokens again. +func (s *Server) providerSettings(p notify.Provider, req *channelRequest, previous []byte) ([]byte, string) { + var old providerConfig + if previous != nil { + _ = json.Unmarshal(previous, &old) + } + cfg := providerConfig{Settings: map[string]string{}, Sealed: map[string]string{}, Locale: req.Locale} + for _, f := range p.Fields { + v := strings.TrimSpace(req.Settings[f.Name]) + if f.Secret { + if v == "" { + if sealed, ok := old.Sealed[f.Name]; ok { + cfg.Sealed[f.Name] = sealed + continue + } + if f.Required { + return nil, "invalid_channel_settings" + } + continue + } + } else if v == "" { + v = f.Default + } + if v == "" { + if f.Required { + return nil, "invalid_channel_settings" + } + continue + } + if len(v) > 2000 || !s.validSetting(f, v) { + return nil, "invalid_channel_settings" + } + if f.Secret { + cfg.Sealed[f.Name] = base64.StdEncoding.EncodeToString(s.keys.Seal([]byte(v), secretAAD(p.Type, f.Name))) + } else { + cfg.Settings[f.Name] = v + } + } + if cfg.Locale == "" || !s.catalog.IsSupported(cfg.Locale) { + cfg.Locale = "en" + } + raw, _ := json.Marshal(cfg) + return raw, "" +} + +func (s *Server) validSetting(f notify.Field, v string) bool { + switch f.Kind { + case "url": + u, err := url.Parse(v) + // Plain http only where services may live on private networks. + return err == nil && u.Host != "" && u.User == nil && (u.Scheme == "https" || (u.Scheme == "http" && !s.cloud())) + case "number": + _, err := strconv.Atoi(v) + return err == nil + case "select": + return slices.Contains(f.Options, v) + } + return !strings.ContainsAny(v, "\r\n") +} + +// providerView shows the settings of a provider channel; secrets appear +// only as the names of fields that are set. +func providerView(raw []byte) (map[string]string, []string, string) { + var cfg providerConfig + _ = json.Unmarshal(raw, &cfg) + set := make([]string, 0, len(cfg.Sealed)) + for k := range cfg.Sealed { + set = append(set, k) + } + slices.Sort(set) + if cfg.Settings == nil { + cfg.Settings = map[string]string{} + } + return cfg.Settings, set, cfg.Locale +} + +// openProviderSettings returns all settings with secrets unsealed. +func (s *Server) openProviderSettings(typ string, raw []byte) (map[string]string, string, error) { + var cfg providerConfig + if err := json.Unmarshal(raw, &cfg); err != nil { + return nil, "", err + } + out := map[string]string{} + for k, v := range cfg.Settings { + out[k] = v + } + for k, v := range cfg.Sealed { + sealed, err := base64.StdEncoding.DecodeString(v) + if err != nil { + return nil, "", err + } + plain, err := s.keys.Open(sealed, secretAAD(typ, k)) + if err != nil { + return nil, "", err + } + out[k] = string(plain) + } + return out, cfg.Locale, nil +} + +// messageFor renders an event for chat and push services in locale. +func (s *Server) messageFor(ev notify.Event, locale string) notify.Message { + l := s.catalog.Match(locale) + data := map[string]any{"Monitor": ev.Monitor.Name} + m := notify.Message{Event: ev.Kind, Key: ev.IncidentID} + var lines []string + switch ev.Kind { + case notify.Opened: + m.Title = l.T("notify.title_opened", data) + for region, msg := range ev.Cause { + lines = append(lines, region+": "+msg) + } + slices.Sort(lines) + case notify.Resolved: + m.Title = l.T("notify.title_resolved", data) + if ev.ResolvedAt != nil { + lines = append(lines, l.T("notify.duration", map[string]any{"Duration": ev.ResolvedAt.Sub(ev.StartedAt).Round(time.Second).String()})) + } + default: + m.Title = l.T("notify.title_test", data) + lines = append(lines, l.T("notify.test_body", nil)) + } + if ev.Monitor.Target != "" && ev.Monitor.Type != "heartbeat" { + lines = append([]string{ev.Monitor.Type + " · " + ev.Monitor.Target}, lines...) + } + m.Body = strings.Join(lines, "\n") + if ev.Monitor.ID != [16]byte{} { + m.URL = strings.TrimSuffix(s.cfg.PublicURL, "/") + "/monitors/" + ev.Monitor.ID.String() + } + return m +} diff --git a/internal/api/providers_test.go b/internal/api/providers_test.go new file mode 100644 index 0000000..06c8cfa --- /dev/null +++ b/internal/api/providers_test.go @@ -0,0 +1,105 @@ +package api_test + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify" +) + +func TestProvidersAreTranslated(t *testing.T) { + catalog, err := i18n.Load() + if err != nil { + t.Fatal(err) + } + for _, lang := range catalog.Supported() { + ctx := i18n.NewContext(context.Background(), catalog.Match(lang)) + for _, p := range notify.Providers { + ids := []string{"channels.type_" + p.Type} + for _, f := range p.Fields { + ids = append(ids, "channels.field_"+f.Name) + } + for _, id := range ids { + if i18n.T(ctx, id) == id { + t.Errorf("%s: %s is not translated", lang, id) + } + } + } + } +} + +func TestProviderChannel(t *testing.T) { + e := newEnv(t) + var mu sync.Mutex + var paths, bodies []string + telegram := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + mu.Lock() + paths, bodies = append(paths, r.URL.Path), append(bodies, string(b)) + mu.Unlock() + })) + defer telegram.Close() + + owner := e.browser(t) + owner.signup("o@"+uniq("pr")+".test", uniq("pr-")) + st, body := owner.do("POST", "/api/v1/org/channels", map[string]any{"name": "Ops chat", "type": "telegram", "settings": map[string]string{"chat_id": "-100"}}) + expect(t, "missing bot token", st, body, http.StatusUnprocessableEntity, "invalid_channel_settings") + st, body = owner.do("POST", "/api/v1/org/channels", map[string]any{"name": "x", "type": "carrierpigeon"}) + expect(t, "unknown type", st, body, http.StatusUnprocessableEntity, "invalid_input") + + st, body = owner.do("POST", "/api/v1/org/channels", map[string]any{ + "name": "Ops chat", "type": "telegram", "locale": "de", + "settings": map[string]string{"bot_token": "4711:very-secret", "chat_id": "-100123", "api_url": telegram.URL}, + }) + if st != http.StatusCreated { + t.Fatalf("create telegram channel = %d %v", st, body) + } + ch := body["channel"].(map[string]any) + id := ch["id"].(string) + if raw := mustJSON(body); strings.Contains(raw, "very-secret") || ch["settings"].(map[string]any)["chat_id"] != "-100123" || + mustJSON(ch["secrets_set"]) != `["bot_token"]` { + t.Errorf("create answer = %s", raw) + } + var stored string + _ = e.asSystem(t, func(tx pgx.Tx) error { + return tx.QueryRow(context.Background(), `SELECT config::text FROM notification_channels WHERE id = $1`, id).Scan(&stored) + }) + if strings.Contains(stored, "very-secret") { + t.Error("the bot token is stored in plain text") + } + if _, list := owner.do("GET", "/api/v1/org/channels", nil); strings.Contains(mustJSON(list), "very-secret") { + t.Error("the channel list shows the bot token") + } + + if st, body := owner.do("POST", "/api/v1/org/channels/"+id+"/test", nil); st != http.StatusNoContent { + t.Fatalf("test send = %d %v", st, body) + } + // Saving without the token keeps it. + st, body = owner.do("PUT", "/api/v1/org/channels/"+id, map[string]any{ + "name": "Ops chat", "type": "telegram", "locale": "de", + "settings": map[string]string{"chat_id": "-100999", "api_url": telegram.URL}, + }) + if st != http.StatusOK { + t.Fatalf("update = %d %v", st, body) + } + owner.do("POST", "/api/v1/org/channels/"+id+"/test", nil) + mu.Lock() + defer mu.Unlock() + if len(paths) != 2 || paths[0] != "/bot4711:very-secret/sendMessage" || paths[1] != paths[0] { + t.Errorf("telegram requests = %v", paths) + } + if !strings.Contains(bodies[0], "Test von UptimeSebi") || !strings.Contains(bodies[1], `"chat_id":"-100999"`) { + t.Errorf("telegram bodies = %v", bodies) + } + if _, _, page := owner.page("/settings/channels"); !strings.Contains(page, `name="settings.bot_token"`) || !strings.Contains(page, "-100999") { + t.Error("the channels page lacks the service form or the channel") + } +} diff --git a/internal/i18n/i18n_test.go b/internal/i18n/i18n_test.go index 6d845e0..e20cf9c 100644 --- a/internal/i18n/i18n_test.go +++ b/internal/i18n/i18n_test.go @@ -153,7 +153,7 @@ func TestDynamicFamilies(t *testing.T) { families := map[string][]string{ "status.": {"up", "degraded", "down", "unknown", "paused", "maintenance"}, "monitors.type_": {"http", "tcp", "tls", "dns", "icmp", "json", "prometheus", "heartbeat", "alertmanager"}, - "channels.type_": {"webhook", "email"}, + "channels.type_": {"webhook", "email", "slack", "discord", "teams", "googlechat", "mattermost", "rocketchat", "telegram", "matrix", "ntfy", "gotify", "pushover", "pushbullet", "signal", "pagerduty", "opsgenie", "apprise"}, "agents.kind_": {"checker", "statuspage"}, "page.status.": {"operational", "degraded", "outage", "unknown", "maintenance"}, "page.component.": {"operational", "degraded", "outage", "unknown", "maintenance"}, @@ -162,6 +162,7 @@ func TestDynamicFamilies(t *testing.T) { "monitors.op_": {"eq", "ne", "gt", "ge", "lt", "le", "contains", "exists", "absent"}, "evidence.stage_": {"dns", "connect", "tls", "response", "body"}, "evidence.phase_": {"dns", "connect", "tls", "wait", "download"}, + "channels.field_": {"webhook_url", "channel", "bot_token", "chat_id", "thread_id", "api_url", "homeserver_url", "access_token", "room_id", "server_url", "topic", "priority", "app_token", "user_key", "device", "number", "recipients", "routing_key", "severity", "api_key", "region", "urls", "config_key"}, "weekday.": {"0", "1", "2", "3", "4", "5", "6"}, "md.": {"heading", "bold", "italic", "strike", "link", "ul", "ol", "quote", "code", "codeblock", "table", "hr"}, "maintenance.recurrence_": {"none", "daily", "weekly", "monthly"}, diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index 3836dea..c0dd450 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -112,16 +112,65 @@ "auth.sso.submit": "Weiter", "channels.create": "Kanal anlegen", "channels.delete_confirm": "Diesen Kanal löschen?", + "channels.field_access_token": "Zugriffstoken", + "channels.field_api_key": "API-Schlüssel", + "channels.field_api_url": "API-URL", + "channels.field_app_token": "Anwendungs-Token", + "channels.field_bot_token": "Bot-Token", + "channels.field_channel": "Kanal", + "channels.field_chat_id": "Chat-ID", + "channels.field_config_key": "Konfigurationsschlüssel", + "channels.field_device": "Gerät", + "channels.field_homeserver_url": "Homeserver-URL", + "channels.field_number": "Absendernummer", + "channels.field_priority": "Priorität", + "channels.field_recipients": "Empfänger (durch Komma getrennt)", + "channels.field_region": "Region", + "channels.field_room_id": "Raum-ID", + "channels.field_routing_key": "Integrationsschlüssel", + "channels.field_server_url": "Server-URL", + "channels.field_severity": "Schweregrad", + "channels.field_thread_id": "Themen-ID (Forum-Gruppen)", + "channels.field_topic": "Topic", + "channels.field_urls": "Apprise-URLs", + "channels.field_user_key": "Benutzer-Schlüssel", + "channels.field_webhook_url": "Webhook-URL", + "channels.help_apprise": "Erreicht über 100 Dienste über einen Apprise-API-Server: gib Apprise-URLs oder den Schlüssel einer dort gespeicherten Konfiguration an.", + "channels.help_opsgenie": "Der Alert wird geschlossen, wenn der Vorfall behoben ist.", + "channels.help_pagerduty": "Nutze den Integrationsschlüssel einer Events-API-v2-Integration; die Behebung schließt den PagerDuty-Vorfall.", + "channels.help_signal": "Braucht einen signal-cli-REST-API-Server (bbernhard/signal-cli-rest-api) mit registrierter Nummer.", + "channels.help_teams": "Nutze die URL eines Teams-Workflows „Bei Empfang einer Webhookanforderung in einem Kanal posten“.", + "channels.help_telegram": "Lege mit @BotFather einen Bot an; die Chat-ID einer Gruppe beginnt mit -100.", "channels.intro": "Jeder aktive Kanal wird benachrichtigt, wenn ein Monitor in allen seinen Regionen ausfällt und wenn er sich erholt.", "channels.language": "Sprache", "channels.new_email": "Neuer E-Mail-Kanal", + "channels.new_service": "Weitere Dienste", "channels.new_webhook": "Neuer Webhook", + "channels.optional": "optional", "channels.secret_now": "Signatur-Secret: Prüfe damit den Header X-Uptimesebi-Signature. Es wird nicht erneut angezeigt.", + "channels.service": "Dienst", + "channels.service_intro": "Chat-, Push- und Alarmierungsdienste. Tokens und Schlüssel werden verschlüsselt gespeichert und nie wieder angezeigt.", "channels.test": "Test senden", "channels.test_ok": "Testbenachrichtigung zugestellt.", "channels.title": "Benachrichtigungen", "channels.to": "Empfänger", + "channels.type_apprise": "Apprise", + "channels.type_discord": "Discord", "channels.type_email": "E-Mail", + "channels.type_googlechat": "Google Chat", + "channels.type_gotify": "Gotify", + "channels.type_matrix": "Matrix", + "channels.type_mattermost": "Mattermost", + "channels.type_ntfy": "ntfy", + "channels.type_opsgenie": "Opsgenie", + "channels.type_pagerduty": "PagerDuty", + "channels.type_pushbullet": "Pushbullet", + "channels.type_pushover": "Pushover", + "channels.type_rocketchat": "Rocket.Chat", + "channels.type_signal": "Signal", + "channels.type_slack": "Slack", + "channels.type_teams": "Microsoft Teams", + "channels.type_telegram": "Telegram", "channels.type_webhook": "Webhook", "channels.url": "Webhook-URL", "checkers.avg_latency": "Mittlere Latenz", @@ -189,6 +238,7 @@ "error.invalid_assertion_path": "Ein Pfad ist ungültig. Nutze durch Punkte getrennte Schlüssel und [n] für Array-Elemente.", "error.invalid_assertion_value": "Vergleiche mit <, >, ≤ und ≥ brauchen eine Zahl.", "error.invalid_assertions": "Lege 1 bis 10 Bedingungen an.", + "error.invalid_channel_settings": "Fülle die Pflichtfelder aus; Adressen müssen https-URLs sein.", "error.invalid_code": "Code ungültig.", "error.invalid_config": "Die Check-Einstellungen sind ungültig.", "error.invalid_credentials": "E-Mail oder Passwort falsch.", @@ -595,6 +645,11 @@ "monitors.type_tls": "TLS-Zertifikat", "monitors.uptime_chart": "Uptime pro Zeitraum", "monitors.verify_tls": "TLS-Zertifikat prüfen", + "notify.duration": "Ausgefallen für {{.Duration}}", + "notify.test_body": "Wenn du das lesen kannst, funktioniert der Kanal.", + "notify.title_opened": "{{.Monitor}} ist ausgefallen", + "notify.title_resolved": "{{.Monitor}} ist wieder erreichbar", + "notify.title_test": "Test von UptimeSebi", "org.policy": "Anmelderichtlinie", "org.require_sso": "SSO verlangen", "org.require_sso_hint": "Mitglieder müssen sich über den Identity Provider dieser Organisation anmelden. Der Owner kann weiterhin ein Passwort nutzen, damit ein defekter IdP euch nicht aussperrt.", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index 63911b0..e7e32e5 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -112,16 +112,65 @@ "auth.sso.submit": "Continue", "channels.create": "Create channel", "channels.delete_confirm": "Delete this channel?", + "channels.field_access_token": "Access token", + "channels.field_api_key": "API key", + "channels.field_api_url": "API URL", + "channels.field_app_token": "Application token", + "channels.field_bot_token": "Bot token", + "channels.field_channel": "Channel", + "channels.field_chat_id": "Chat ID", + "channels.field_config_key": "Configuration key", + "channels.field_device": "Device", + "channels.field_homeserver_url": "Homeserver URL", + "channels.field_number": "Sender number", + "channels.field_priority": "Priority", + "channels.field_recipients": "Recipients (comma-separated)", + "channels.field_region": "Region", + "channels.field_room_id": "Room ID", + "channels.field_routing_key": "Integration key", + "channels.field_server_url": "Server URL", + "channels.field_severity": "Severity", + "channels.field_thread_id": "Topic ID (forum groups)", + "channels.field_topic": "Topic", + "channels.field_urls": "Apprise URLs", + "channels.field_user_key": "User key", + "channels.field_webhook_url": "Webhook URL", + "channels.help_apprise": "Reaches over 100 services through an Apprise API server: give Apprise URLs or the key of a configuration stored there.", + "channels.help_opsgenie": "The alert closes when the incident is resolved.", + "channels.help_pagerduty": "Use the integration key of an Events API v2 integration; resolving closes the PagerDuty incident.", + "channels.help_signal": "Needs a signal-cli REST API server (bbernhard/signal-cli-rest-api) with a registered number.", + "channels.help_teams": "Use the URL of a Teams workflow \"Post to a channel when a webhook request is received\".", + "channels.help_telegram": "Create a bot with @BotFather; the chat ID of a group starts with -100.", "channels.intro": "Every enabled channel is notified when a monitor goes down in all of its regions and when it recovers.", "channels.language": "Language", "channels.new_email": "New email channel", + "channels.new_service": "Other services", "channels.new_webhook": "New webhook", + "channels.optional": "optional", "channels.secret_now": "Signing secret: verify the X-Uptimesebi-Signature header with it. It will not be shown again.", + "channels.service": "Service", + "channels.service_intro": "Chat, push and paging services. Tokens and keys are stored encrypted and never shown again.", "channels.test": "Send test", "channels.test_ok": "Test notification delivered.", "channels.title": "Notifications", "channels.to": "Recipients", + "channels.type_apprise": "Apprise", + "channels.type_discord": "Discord", "channels.type_email": "Email", + "channels.type_googlechat": "Google Chat", + "channels.type_gotify": "Gotify", + "channels.type_matrix": "Matrix", + "channels.type_mattermost": "Mattermost", + "channels.type_ntfy": "ntfy", + "channels.type_opsgenie": "Opsgenie", + "channels.type_pagerduty": "PagerDuty", + "channels.type_pushbullet": "Pushbullet", + "channels.type_pushover": "Pushover", + "channels.type_rocketchat": "Rocket.Chat", + "channels.type_signal": "Signal", + "channels.type_slack": "Slack", + "channels.type_teams": "Microsoft Teams", + "channels.type_telegram": "Telegram", "channels.type_webhook": "Webhook", "channels.url": "Webhook URL", "checkers.avg_latency": "Average latency", @@ -189,6 +238,7 @@ "error.invalid_assertion_path": "A condition path is invalid. Use keys separated by dots and [n] for array elements.", "error.invalid_assertion_value": "Comparisons with <, >, ≤ and ≥ need a number.", "error.invalid_assertions": "Add between 1 and 10 conditions.", + "error.invalid_channel_settings": "Fill in the required fields; addresses must be https URLs.", "error.invalid_code": "Invalid code.", "error.invalid_config": "The check settings are not valid.", "error.invalid_credentials": "Wrong email or password.", @@ -595,6 +645,11 @@ "monitors.type_tls": "TLS certificate", "monitors.uptime_chart": "Uptime per period", "monitors.verify_tls": "Verify TLS certificate", + "notify.duration": "Down for {{.Duration}}", + "notify.test_body": "If you can read this, the channel works.", + "notify.title_opened": "{{.Monitor}} is down", + "notify.title_resolved": "{{.Monitor}} is up again", + "notify.title_test": "Test from UptimeSebi", "org.policy": "Sign-in policy", "org.require_sso": "Require SSO", "org.require_sso_hint": "Members must sign in through this organization's identity provider. The owner can still use a password so a broken IdP cannot lock you out.", diff --git a/internal/migrations/sql/00034_notification_providers.sql b/internal/migrations/sql/00034_notification_providers.sql new file mode 100644 index 0000000..18e5697 --- /dev/null +++ b/internal/migrations/sql/00034_notification_providers.sql @@ -0,0 +1,10 @@ +-- +goose Up +-- Channel types follow notify.Providers; the application validates them +-- and their settings, secrets of which are sealed in config. +ALTER TABLE notification_channels DROP CONSTRAINT notification_channels_type_check; +ALTER TABLE notification_channels ADD CONSTRAINT notification_channels_type_check CHECK (type ~ '^[a-z]{2,32}$'); + +-- +goose Down +DELETE FROM notification_channels WHERE type NOT IN ('webhook', 'email'); +ALTER TABLE notification_channels DROP CONSTRAINT notification_channels_type_check; +ALTER TABLE notification_channels ADD CONSTRAINT notification_channels_type_check CHECK (type IN ('webhook', 'email')); diff --git a/internal/web/monitors.templ b/internal/web/monitors.templ index 4db31a7..fe97e2a 100644 --- a/internal/web/monitors.templ +++ b/internal/web/monitors.templ @@ -766,6 +766,7 @@ type ChannelsView struct { EmailAvailable bool CanWrite bool Languages []string + Providers []ProviderOption } templ ChannelsPage(p Page, me Me, v ChannelsView) { @@ -834,11 +835,98 @@ templ ChannelsPage(p Page, me Me, v ChannelsView) {

{ i18n.T(ctx, "error.email_not_configured") }

} +
+ @sectionHeading("channels.new_service") +

{ i18n.T(ctx, "channels.service_intro") }

+
+
+ @formError() + + @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true) + +
+
+ for i, pr := range v.Providers { +
+ if pr.Help != "" { +

{ pr.Help }

+ } + for _, f := range pr.Fields { + @providerField(f) + } +
+ } + @submit(i18n.T(ctx, "channels.create")) +
+
+
} } } +// ProviderOption is a notification service the form offers. +type ProviderOption struct { + Type string + Help string + Fields []ProviderField +} + +// ProviderField is a setting of a service. +type ProviderField struct { + Name string + Label string + Required bool + Secret bool + Kind string + Options []string + Default string +} + +templ providerField(f ProviderField) { + +} + templ groupSelect(name string, groups []GroupOption, selected string, allowNone bool) { ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, pr := range v.Providers { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 350, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 353, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = valueField(i18n.T(ctx, "sso.field.name"), "name", "", "Ops", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 354, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for i, pr := range v.Providers { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 362, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if pr.Help != "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 367, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var204 string + templ_7745c5c3_Var204, templ_7745c5c3_Err = templ.JoinStringErrs(pr.Help) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 866, Col: 54} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var204)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 368, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + for _, f := range pr.Fields { + templ_7745c5c3_Err = providerField(f).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 369, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "channels.create")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 370, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4117,6 +4335,250 @@ func ChannelsPage(p Page, me Me, v ChannelsView) templ.Component { }) } +// ProviderOption is a notification service the form offers. +type ProviderOption struct { + Type string + Help string + Fields []ProviderField +} + +// ProviderField is a setting of a service. +type ProviderField struct { + Name string + Label string + Required bool + Secret bool + Kind string + Options []string + Default string +} + +func providerField(f ProviderField) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 371, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + func groupSelect(name string, groups []GroupOption, selected string, allowNone bool) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context @@ -4134,85 +4596,85 @@ func groupSelect(name string, groups []GroupOption, selected string, allowNone b } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 346, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 405, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4255,7 +4717,7 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var202 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var222 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -4267,20 +4729,20 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 356, "

← ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 406, "

← ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var203 string - templ_7745c5c3_Var203, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) + var templ_7745c5c3_Var223 string + templ_7745c5c3_Var223, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 873, Col: 115} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 961, Col: 115} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var203)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var223)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 357, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 407, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4289,69 +4751,69 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { return templ_7745c5c3_Err } if len(v.Groups) > 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 358, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 374, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 424, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if v.CanWrite { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 375, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 425, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4459,7 +4921,7 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 376, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 426, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4471,20 +4933,20 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 377, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 429, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4500,14 +4962,14 @@ func GroupsPage(p Page, me Me, v GroupsView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 380, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 430, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var202), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var222), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4539,7 +5001,7 @@ func pingSection(url string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 381, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 431, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -4547,55 +5009,55 @@ func pingSection(url string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 382, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 432, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var214 string - templ_7745c5c3_Var214, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.ping_intro")) + var templ_7745c5c3_Var234 string + templ_7745c5c3_Var234, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.ping_intro")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 928, Col: 83} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 1016, Col: 83} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var214)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var234)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 383, "

")
+		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 433, "

")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		var templ_7745c5c3_Var215 string
-		templ_7745c5c3_Var215, templ_7745c5c3_Err = templ.JoinStringErrs("curl -fsS -m 10 --retry 3 " + url + "\n")
+		var templ_7745c5c3_Var235 string
+		templ_7745c5c3_Var235, templ_7745c5c3_Err = templ.JoinStringErrs("curl -fsS -m 10 --retry 3 " + url + "\n")
 		if templ_7745c5c3_Err != nil {
-			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 929, Col: 137}
+			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 1017, Col: 137}
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var215))
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var235))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		var templ_7745c5c3_Var216 string
-		templ_7745c5c3_Var216, templ_7745c5c3_Err = templ.JoinStringErrs("curl -fsS -m 10 --retry 3 --data-raw \"$output\" " + url + "/fail")
+		var templ_7745c5c3_Var236 string
+		templ_7745c5c3_Var236, templ_7745c5c3_Err = templ.JoinStringErrs("curl -fsS -m 10 --retry 3 --data-raw \"$output\" " + url + "/fail")
 		if templ_7745c5c3_Err != nil {
-			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 929, Col: 208}
+			return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 1017, Col: 208}
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var216))
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var236))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 384, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 434, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var217 string - templ_7745c5c3_Var217, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.ping_secret")) + var templ_7745c5c3_Var237 string + templ_7745c5c3_Var237, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.ping_secret")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 930, Col: 84} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/monitors.templ`, Line: 1018, Col: 84} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var217)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var237)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 385, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 435, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }