PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FEATURE (notifiers): Add receiving notification types for webhook
Rostislav Duginea3898256cb1
diff --git a/backend/internal/features/backups/backups/backuping/logical/backuper.go b/backend/internal/features/backups/backups/backuping/logical/backuper.goindex e5c0a18d..2aafb7ce 100644--- a/backend/internal/features/backups/backups/backuping/logical/backuper.go+++ b/backend/internal/features/backups/backups/backuping/logical/backuper.go@@ -301,11 +301,11 @@ func (b *Backuper) SendBackupNotification(}title := ""- sentNotificationType := notifier_models.NotificationTypeSuccess+ sentNotificationType := notifier_models.NotificationTypeBackupSuccessswitch notificationType {case backups_config_logical.NotificationBackupFailed:- sentNotificationType = notifier_models.NotificationTypeFailure+ sentNotificationType = notifier_models.NotificationTypeBackupFailedtitle = fmt.Sprintf("❌ Backup failed for database \"%s\" (workspace \"%s\")",database.Name,diff --git a/backend/internal/features/backups/backups/backuping/logical/backuper_test.go b/backend/internal/features/backups/backups/backuping/logical/backuper_test.goindex 0baa1991..9db2c833 100644--- a/backend/internal/features/backups/backups/backuping/logical/backuper_test.go+++ b/backend/internal/features/backups/backups/backuping/logical/backuper_test.go@@ -64,7 +64,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {mockNotificationSender.On("SendNotification",mock.Anything,mock.MatchedBy(func(notification notifier_models.Notification) bool {- return notification.Type == notifier_models.NotificationTypeFailure &&+ return notification.Type == notifier_models.NotificationTypeBackupFailed &&strings.Contains(notification.Heading, "❌ Backup failed") &&strings.Contains(notification.Message, "backup failed")}),@@ -96,7 +96,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {mockNotificationSender.On("SendNotification",mock.Anything,mock.MatchedBy(func(notification notifier_models.Notification) bool {- return notification.Type == notifier_models.NotificationTypeSuccess &&+ return notification.Type == notifier_models.NotificationTypeBackupSuccess &&strings.Contains(notification.Heading, "✅ Backup completed") &&strings.Contains(notification.Message, "Backup completed successfully")}),@@ -142,7 +142,7 @@ func Test_BackupExecuted_NotificationSent(t *testing.T) {mockNotificationSender.AssertExpectations(t)// Additional detailed assertions- assert.Equal(t, notifier_models.NotificationTypeSuccess, capturedNotification.Type)+ assert.Equal(t, notifier_models.NotificationTypeBackupSuccess, capturedNotification.Type)assert.Contains(t, capturedNotification.Heading, "✅ Backup completed")assert.Contains(t, capturedNotification.Heading, database.Name)assert.Contains(t, capturedNotification.Message, "Backup completed successfully")diff --git a/backend/internal/features/backups/backups/backuping/physical/backuper.go b/backend/internal/features/backups/backups/backuping/physical/backuper.goindex eb0ee8b0..8d63eb15 100644--- a/backend/internal/features/backups/backups/backuping/physical/backuper.go+++ b/backend/internal/features/backups/backups/backuping/physical/backuper.go@@ -582,10 +582,10 @@ func toNotificationType(backupNotificationType backups_config_physical.BackupNotificationType,) notifier_models.NotificationType {if backupNotificationType == backups_config_physical.NotificationBackupSuccess {- return notifier_models.NotificationTypeSuccess+ return notifier_models.NotificationTypeBackupSuccess}- return notifier_models.NotificationTypeFailure+ return notifier_models.NotificationTypeBackupFailed}func classifyFullBackupNotification(diff --git a/backend/internal/features/backups/backups/backuping/physical/backuper_test.go b/backend/internal/features/backups/backups/backuping/physical/backuper_test.goindex 0c971877..7498745a 100644--- a/backend/internal/features/backups/backups/backuping/physical/backuper_test.go+++ b/backend/internal/features/backups/backups/backuping/physical/backuper_test.go@@ -415,7 +415,7 @@ func Test_SendFullBackupNotification_WhenEnabled_FansOutToAllNotifiers(t *testinassert.Contains(t, notifiedIDs, firstNotifierID)assert.Contains(t, notifiedIDs, secondNotifierID)assert.Contains(t, sender.sentNotifications[0].Notification.Heading, "completed")- assert.Equal(t, notifier_models.NotificationTypeSuccess, sender.sentNotifications[0].Notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeBackupSuccess, sender.sentNotifications[0].Notification.Type)}func Test_LoadBackupContext_WhenNotEncrypted_LeavesMasterKeyEmpty(t *testing.T) {@@ -554,7 +554,7 @@ func Test_RunFullBackup_WhenExecutorResultErrorStatus_PersistsErrorAndSendsFailerequire.Len(t, sender.sentNotifications, 1)assert.Contains(t, sender.sentNotifications[0].Notification.Heading, "failed")- assert.Equal(t, notifier_models.NotificationTypeFailure, sender.sentNotifications[0].Notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeBackupFailed, sender.sentNotifications[0].Notification.Type)}func Test_RunFullBackup_WhenExecutorResultChainBroken_PersistsChainBrokenAndSendsChainBrokenNotification(t *testing.T) {@@ -577,7 +577,7 @@ func Test_RunFullBackup_WhenExecutorResultChainBroken_PersistsChainBrokenAndSendrequire.Len(t, sender.sentNotifications, 1)assert.Contains(t, sender.sentNotifications[0].Notification.Heading, "chain-broken")- assert.Equal(t, notifier_models.NotificationTypeFailure, sender.sentNotifications[0].Notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeBackupFailed, sender.sentNotifications[0].Notification.Type)}func Test_RunIncrementalBackup_WhenParentManifestMissing_FlipsToChainBrokenBeforeExecutor(t *testing.T) {@@ -627,7 +627,7 @@ func Test_RunIncrementalBackup_WhenExecutorResultErrorStatus_PersistsErrorAndSenrequire.Len(t, sender.sentNotifications, 1)assert.Contains(t, sender.sentNotifications[0].Notification.Heading, "INCR failed")- assert.Equal(t, notifier_models.NotificationTypeFailure, sender.sentNotifications[0].Notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeBackupFailed, sender.sentNotifications[0].Notification.Type)}func Test_ReleaseOwned_WhenForeignBackupHoldsClaim_LeavesItIntact(t *testing.T) {diff --git a/backend/internal/features/backups/backups/backuping/physical/wal_supervisor.go b/backend/internal/features/backups/backups/backuping/physical/wal_supervisor.goindex f39a2bc4..43cb034e 100644--- a/backend/internal/features/backups/backups/backuping/physical/wal_supervisor.go+++ b/backend/internal/features/backups/backups/backuping/physical/wal_supervisor.go@@ -329,7 +329,7 @@ func (s *PhysicalWalStreamSupervisor) gapNotifier(}notification := notifier_models.Notification{- Type: notifier_models.NotificationTypeFailure,+ Type: notifier_models.NotificationTypeBackupFailed,Heading: fmt.Sprintf("Physical WAL gap detected for %q", db.Name),Message: fmt.Sprintf("database_id=%s gap=[%s, %s)", db.ID, gapStart.String(), gapEnd.String()),}diff --git a/backend/internal/features/healthcheck/attempt/check_database_health_uc.go b/backend/internal/features/healthcheck/attempt/check_database_health_uc.goindex 11947595..1534d063 100644--- a/backend/internal/features/healthcheck/attempt/check_database_health_uc.go+++ b/backend/internal/features/healthcheck/attempt/check_database_health_uc.go@@ -236,14 +236,14 @@ func (uc *CheckDatabaseHealthUseCase) sendDbStatusNotification(}notification := notifier_models.Notification{- Type: notifier_models.NotificationTypeFailure,+ Type: notifier_models.NotificationTypeHealthcheckFailed,Heading: fmt.Sprintf("❌ [%s] DB is unavailable", database.Name),Message: fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name),}if newHealthStatus == databases.HealthStatusAvailable {notification = notifier_models.Notification{- Type: notifier_models.NotificationTypeSuccess,+ Type: notifier_models.NotificationTypeHealthcheckSuccess,Heading: fmt.Sprintf("✅ [%s] DB is online", database.Name),Message: fmt.Sprintf("✅ [%s] DB is back online", database.Name),}diff --git a/backend/internal/features/healthcheck/attempt/check_database_health_uc_test.go b/backend/internal/features/healthcheck/attempt/check_database_health_uc_test.goindex d7855bf7..b22287ce 100644--- a/backend/internal/features/healthcheck/attempt/check_database_health_uc_test.go+++ b/backend/internal/features/healthcheck/attempt/check_database_health_uc_test.go@@ -21,7 +21,7 @@ import (func unavailableNotification(databaseName string) notifier_models.Notification {return notifier_models.Notification{- Type: notifier_models.NotificationTypeFailure,+ Type: notifier_models.NotificationTypeHealthcheckFailed,Heading: fmt.Sprintf("❌ [%s] DB is unavailable", databaseName),Message: fmt.Sprintf("❌ [%s] DB is currently unavailable", databaseName),}@@ -29,7 +29,7 @@ func unavailableNotification(databaseName string) notifier_models.Notification {func onlineNotification(databaseName string) notifier_models.Notification {return notifier_models.Notification{- Type: notifier_models.NotificationTypeSuccess,+ Type: notifier_models.NotificationTypeHealthcheckSuccess,Heading: fmt.Sprintf("✅ [%s] DB is online", databaseName),Message: fmt.Sprintf("✅ [%s] DB is back online", databaseName),}diff --git a/backend/internal/features/notifiers/models/email_notifier/model_test.go b/backend/internal/features/notifiers/models/email_notifier/model_test.goindex f6855a83..12523175 100644--- a/backend/internal/features/notifiers/models/email_notifier/model_test.go+++ b/backend/internal/features/notifiers/models/email_notifier/model_test.go@@ -75,7 +75,7 @@ func Test_EmailNotifierSend_WhenSmtpServerAccepts_DeliversMessageToRecipient(t *encryption.GetFieldEncryptor(),logger.GetLogger(),notifier_models.Notification{- Type: notifier_models.NotificationTypeSuccess,+ Type: notifier_models.NotificationTypeAll,Heading: "Backup completed",Message: "<b>All good</b>",},diff --git a/backend/internal/features/notifiers/models/enums.go b/backend/internal/features/notifiers/models/enums.goindex 958361c1..45b9fff4 100644--- a/backend/internal/features/notifiers/models/enums.go+++ b/backend/internal/features/notifiers/models/enums.go@@ -3,6 +3,14 @@ package notifier_modelstype NotificationType stringconst (- NotificationTypeSuccess NotificationType = "SUCCESS"- NotificationTypeFailure NotificationType = "FAILURE"+ NotificationTypeAll NotificationType = "ALL"++ NotificationTypeBackupSuccess NotificationType = "BACKUP_SUCCESS"+ NotificationTypeBackupFailed NotificationType = "BACKUP_FAILED"++ NotificationTypeHealthcheckSuccess NotificationType = "HEALTHCHECK_SUCCESS"+ NotificationTypeHealthcheckFailed NotificationType = "HEALTHCHECK_FAILED"++ NotificationTypeVerificationSuccess NotificationType = "VERIFICATION_SUCCESS"+ NotificationTypeVerificationFailed NotificationType = "VERIFICATION_FAILED")diff --git a/backend/internal/features/notifiers/models/webhook/model.go b/backend/internal/features/notifiers/models/webhook/model.goindex c307d460..d0e89ab7 100644--- a/backend/internal/features/notifiers/models/webhook/model.go+++ b/backend/internal/features/notifiers/models/webhook/model.go@@ -10,6 +10,7 @@ import ("log/slog""net/http""net/url"+ "slices""strings""github.com/google/uuid"@@ -24,18 +25,17 @@ type WebhookHeader struct {Value string `json:"value"`}-// Before both WebhookURL, BodyTemplate and HeadersJSON were considered-// as sensetive data and it was causing issues. Now only headers values-// considered as sensetive data, but we try to decrypt webhook URL and-// body template for backward combabilitytype WebhookNotifier struct {NotifierID uuid.UUID `json:"notifierId" gorm:"primaryKey;column:notifier_id"`WebhookURL string `json:"webhookUrl" gorm:"not null;column:webhook_url"`WebhookMethod WebhookMethod `json:"webhookMethod" gorm:"not null;column:webhook_method"`BodyTemplate *string `json:"bodyTemplate" gorm:"column:body_template;type:text"`- HeadersJSON string `json:"-" gorm:"column:headers;type:text"`- Headers []WebhookHeader `json:"headers" gorm:"-"`+ HeadersJSON string `json:"-" gorm:"column:headers;type:text"`+ Headers []WebhookHeader `json:"headers" gorm:"-"`++ AcceptNotificationTypes []notifier_models.NotificationType `json:"acceptNotificationTypes" gorm:"-"`+ AcceptNotificationTypesJSON string `json:"-" gorm:"column:accept_notification_types;type:text"`}func (t *WebhookNotifier) TableName() string {@@ -54,6 +54,19 @@ func (t *WebhookNotifier) BeforeSave(_ *gorm.DB) error {t.HeadersJSON = "[]"}+ if len(t.AcceptNotificationTypes) == 0 {+ t.AcceptNotificationTypes = []notifier_models.NotificationType{+ notifier_models.NotificationTypeAll,+ }+ }++ serializedAcceptTypes, err := json.Marshal(t.AcceptNotificationTypes)+ if err != nil {+ return err+ }++ t.AcceptNotificationTypesJSON = string(serializedAcceptTypes)+return nil}@@ -64,6 +77,12 @@ func (t *WebhookNotifier) AfterFind(_ *gorm.DB) error {}}+ if t.AcceptNotificationTypesJSON != "" {+ if err := json.Unmarshal([]byte(t.AcceptNotificationTypesJSON), &t.AcceptNotificationTypes); err != nil {+ return err+ }+ }+encryptor := encryption.GetFieldEncryptor()if t.WebhookURL != "" {@@ -98,6 +117,10 @@ func (t *WebhookNotifier) Send(logger *slog.Logger,notification notifier_models.Notification,) error {+ if !t.isNotificationTypeAccepted(notification.Type) {+ return nil+ }+if err := t.decryptHeadersForSending(encryptor); err != nil {return err}@@ -123,6 +146,7 @@ func (t *WebhookNotifier) Update(incoming *WebhookNotifier) {t.WebhookMethod = incoming.WebhookMethodt.BodyTemplate = incoming.BodyTemplatet.Headers = incoming.Headers+ t.AcceptNotificationTypes = incoming.AcceptNotificationTypes}func (t *WebhookNotifier) EncryptSensitiveData(encryptor encryption.FieldEncryptor) error {@@ -140,6 +164,17 @@ func (t *WebhookNotifier) EncryptSensitiveData(encryptor encryption.FieldEncryptreturn nil}+// NotificationTypeAll is a wildcard on both sides: on the accept-list it accepts every type, and as+// an incoming type (carried by test notifications) it bypasses the filter so tests always deliver.+func (t *WebhookNotifier) isNotificationTypeAccepted(notificationType notifier_models.NotificationType) bool {+ if len(t.AcceptNotificationTypes) == 0 || notificationType == notifier_models.NotificationTypeAll {+ return true+ }++ return slices.Contains(t.AcceptNotificationTypes, notifier_models.NotificationTypeAll) ||+ slices.Contains(t.AcceptNotificationTypes, notificationType)+}+func (t *WebhookNotifier) sendGET(webhookURL, heading, message string, logger *slog.Logger) error {reqURL := fmt.Sprintf("%s?heading=%s&message=%s",webhookURL,diff --git a/backend/internal/features/notifiers/models/webhook/model_test.go b/backend/internal/features/notifiers/models/webhook/model_test.gonew file mode 100644index 00000000..1e98530b--- /dev/null+++ b/backend/internal/features/notifiers/models/webhook/model_test.go@@ -0,0 +1,309 @@+package webhook_notifier++import (+ "encoding/json"+ "io"+ "log/slog"+ "net/http"+ "net/http/httptest"+ "net/url"+ "sync"+ "testing"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"++ notifier_models "databasus-backend/internal/features/notifiers/models"+)++type passthroughEncryptor struct{}++func (p passthroughEncryptor) Encrypt(plaintext string) (string, error) {+ return plaintext, nil+}++func (p passthroughEncryptor) Decrypt(ciphertext string) (string, error) {+ return ciphertext, nil+}++type capturedRequest struct {+ method string+ query url.Values+ headers http.Header+ body string+}++type requestRecorder struct {+ mu sync.Mutex+ requests []capturedRequest+}++func (r *requestRecorder) add(request capturedRequest) {+ r.mu.Lock()+ defer r.mu.Unlock()++ r.requests = append(r.requests, request)+}++func (r *requestRecorder) GetRequestCount() int {+ r.mu.Lock()+ defer r.mu.Unlock()++ return len(r.requests)+}++func (r *requestRecorder) GetLastRequest() capturedRequest {+ r.mu.Lock()+ defer r.mu.Unlock()++ return r.requests[len(r.requests)-1]+}++func startRecordingWebhook(t *testing.T, statusCode int) (string, *requestRecorder) {+ recorder := &requestRecorder{}++ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {+ body, _ := io.ReadAll(req.Body)+ recorder.add(capturedRequest{+ method: req.Method,+ query: req.URL.Query(),+ headers: req.Header.Clone(),+ body: string(body),+ })++ w.WriteHeader(statusCode)+ }))+ t.Cleanup(server.Close)++ return server.URL, recorder+}++func send(t *testing.T, notifier *WebhookNotifier, notificationType notifier_models.NotificationType) error {+ t.Helper()++ return notifier.Send(+ passthroughEncryptor{},+ slog.New(slog.NewTextHandler(io.Discard, nil)),+ notifier_models.Notification{+ Type: notificationType,+ Heading: "Backup completed",+ Message: "All good",+ },+ )+}++func acceptAll() []notifier_models.NotificationType {+ return []notifier_models.NotificationType{notifier_models.NotificationTypeAll}+}++func Test_Send_WithPOSTAndNoBodyTemplate_SendsDefaultJSONBody(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: acceptAll(),+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))++ require.Equal(t, 1, recorder.GetRequestCount())+ request := recorder.GetLastRequest()+ assert.Equal(t, http.MethodPost, request.method)+ assert.Equal(t, "application/json", request.headers.Get("Content-Type"))++ var payload map[string]string+ require.NoError(t, json.Unmarshal([]byte(request.body), &payload))+ assert.Equal(t, "Backup completed", payload["heading"])+ assert.Equal(t, "All good", payload["message"])+}++func Test_Send_WithPOSTAndBodyTemplate_SubstitutesAndEscapesPlaceholders(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ template := `{"title":"{{heading}}","text":"{{message}}"}`+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ BodyTemplate: &template,+ AcceptNotificationTypes: acceptAll(),+ }++ err := notifier.Send(+ passthroughEncryptor{},+ slog.New(slog.NewTextHandler(io.Discard, nil)),+ notifier_models.Notification{+ Type: notifier_models.NotificationTypeBackupSuccess,+ Heading: `He said "hi"`,+ Message: "line1\nline2",+ },+ )+ require.NoError(t, err)++ var payload map[string]string+ require.NoError(t, json.Unmarshal([]byte(recorder.GetLastRequest().body), &payload))+ assert.Equal(t, `He said "hi"`, payload["title"])+ assert.Equal(t, "line1\nline2", payload["text"])+}++func Test_Send_WithCustomContentTypeHeader_DoesNotOverrideIt(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ Headers: []WebhookHeader{{Key: "Content-Type", Value: "application/xml"}},+ AcceptNotificationTypes: acceptAll(),+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))++ assert.Equal(t, "application/xml", recorder.GetLastRequest().headers.Get("Content-Type"))+}++func Test_Send_WithGET_SendsHeadingAndMessageAsQueryParams(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodGET,+ AcceptNotificationTypes: acceptAll(),+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))++ request := recorder.GetLastRequest()+ assert.Equal(t, http.MethodGet, request.method)+ assert.Equal(t, "Backup completed", request.query.Get("heading"))+ assert.Equal(t, "All good", request.query.Get("message"))+ assert.Empty(t, request.body)+}++func Test_Send_WithCustomHeaders_AppliesThemToRequest(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ Headers: []WebhookHeader{{Key: "X-Api-Key", Value: "secret-value"}},+ AcceptNotificationTypes: acceptAll(),+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))++ assert.Equal(t, "secret-value", recorder.GetLastRequest().headers.Get("X-Api-Key"))+}++func Test_Send_WhenServerReturnsNon2xx_ReturnsError(t *testing.T) {+ webhookURL, _ := startRecordingWebhook(t, http.StatusInternalServerError)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: acceptAll(),+ }++ require.Error(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))+}++func Test_Send_WhenURLUnreachable_ReturnsError(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))+ unreachableURL := server.URL+ server.Close()++ notifier := &WebhookNotifier{+ WebhookURL: unreachableURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: acceptAll(),+ }++ require.Error(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))+}++func Test_Send_WhenAcceptTypesEmpty_SendsEveryType(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))+ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeHealthcheckFailed))++ assert.Equal(t, 2, recorder.GetRequestCount())+}++func Test_Send_WhenAcceptContainsAll_SendsEveryType(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: acceptAll(),+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))+ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeVerificationFailed))++ assert.Equal(t, 2, recorder.GetRequestCount())+}++func Test_Send_WhenNarrowedToBackupSuccess_SkipsOtherTypes(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: []notifier_models.NotificationType{notifier_models.NotificationTypeBackupSuccess},+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupFailed))+ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeHealthcheckSuccess))+ assert.Equal(t, 0, recorder.GetRequestCount())++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeBackupSuccess))+ assert.Equal(t, 1, recorder.GetRequestCount())+}++func Test_Send_WhenNarrowed_StillSendsWildcardTestNotification(t *testing.T) {+ webhookURL, recorder := startRecordingWebhook(t, http.StatusOK)+ notifier := &WebhookNotifier{+ WebhookURL: webhookURL,+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: []notifier_models.NotificationType{notifier_models.NotificationTypeBackupFailed},+ }++ require.NoError(t, send(t, notifier, notifier_models.NotificationTypeAll))++ assert.Equal(t, 1, recorder.GetRequestCount())+}++func Test_BeforeSave_WhenAcceptTypesEmpty_DefaultsToAll(t *testing.T) {+ notifier := &WebhookNotifier{+ WebhookURL: "https://example.com/webhook",+ WebhookMethod: WebhookMethodPOST,+ }++ require.NoError(t, notifier.BeforeSave(nil))++ assert.Equal(t, `["ALL"]`, notifier.AcceptNotificationTypesJSON)+ assert.Equal(t, acceptAll(), notifier.AcceptNotificationTypes)+}++func Test_BeforeSave_WithSingleType_SerializesOnlyThatType(t *testing.T) {+ notifier := &WebhookNotifier{+ WebhookURL: "https://example.com/webhook",+ WebhookMethod: WebhookMethodPOST,+ AcceptNotificationTypes: []notifier_models.NotificationType{notifier_models.NotificationTypeBackupSuccess},+ }++ require.NoError(t, notifier.BeforeSave(nil))++ assert.Equal(t, `["BACKUP_SUCCESS"]`, notifier.AcceptNotificationTypesJSON)+}++func Test_AfterFind_WithSerializedTypes_RestoresSlice(t *testing.T) {+ notifier := &WebhookNotifier{+ AcceptNotificationTypesJSON: `["VERIFICATION_FAILED"]`,+ }++ require.NoError(t, notifier.AfterFind(nil))++ assert.Equal(+ t,+ []notifier_models.NotificationType{notifier_models.NotificationTypeVerificationFailed},+ notifier.AcceptNotificationTypes,+ )+}diff --git a/backend/internal/features/notifiers/service.go b/backend/internal/features/notifiers/service.goindex 14e106e8..0ac6c153 100644--- a/backend/internal/features/notifiers/service.go+++ b/backend/internal/features/notifiers/service.go@@ -276,7 +276,7 @@ func (s *NotifierService) SendTestNotificationToNotifier(func newTestNotification() notifier_models.Notification {return notifier_models.Notification{- Type: notifier_models.NotificationTypeSuccess,+ Type: notifier_models.NotificationTypeAll,Heading: "Test message",Message: "This is a test message",}diff --git a/backend/internal/features/verification/runs/notification_test.go b/backend/internal/features/verification/runs/notification_test.goindex 89b1eea9..32a6b87e 100644--- a/backend/internal/features/verification/runs/notification_test.go+++ b/backend/internal/features/verification/runs/notification_test.go@@ -159,7 +159,7 @@ func Test_SubmitReport_WhenBackupRejected_SendsFailureNotification(t *testing.T)sent := recorder.waitForNotification(t, 2*time.Second)require.NotNil(t, sent.notifier)assert.Equal(t, notifier.ID, sent.notifier.ID, "must dispatch to the database's notifier")- assert.Equal(t, notifier_models.NotificationTypeFailure, sent.notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeVerificationFailed, sent.notification.Type)assert.Contains(t, sent.notification.Heading, database.Name, "title must name the database")assert.Contains(t, sent.notification.Heading, "failed", "title must convey failure")assert.Contains(t, sent.notification.Message, failMessage,@@ -211,7 +211,7 @@ func Test_SubmitReport_WhenRestoredTooSmall_SendsFailureNotification(t *testing.sent := recorder.waitForNotification(t, 2*time.Second)require.NotNil(t, sent.notifier)assert.Equal(t, notifier.ID, sent.notifier.ID)- assert.Equal(t, notifier_models.NotificationTypeFailure, sent.notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeVerificationFailed, sent.notification.Type)assert.Contains(t, sent.notification.Heading, "failed", "size-guard terminal must be reported as a failure")assert.Contains(t, sent.notification.Message, "less than 20%","notification body must explain why the restore was rejected")@@ -275,7 +275,7 @@ func Test_SubmitReport_WhenAgentSetupFailedRepeatedly_SendsFailureNotificationOnsent := recorder.waitForNotification(t, 2*time.Second)assert.Equal(t, notifier.ID, sent.notifier.ID)- assert.Equal(t, notifier_models.NotificationTypeFailure, sent.notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeVerificationFailed, sent.notification.Type)assert.Contains(t, sent.notification.Heading, "failed")assert.Equal(t, 1, recorder.count(), "exactly one notification on terminal — not one per attempt")}@@ -334,7 +334,7 @@ func Test_ReapStaleRuns_WhenAgentLostContact_SendsFailureNotificationOnlyAtTermisent := recorder.waitForNotification(t, 2*time.Second)assert.Equal(t, notifier.ID, sent.notifier.ID)- assert.Equal(t, notifier_models.NotificationTypeFailure, sent.notification.Type)+ assert.Equal(t, notifier_models.NotificationTypeVerificationFailed, sent.notification.Type)assert.Contains(t, sent.notification.Heading, "failed")assert.Contains(t, sent.notification.Message, "agent went silent")diff --git a/backend/internal/features/verification/runs/service.go b/backend/internal/features/verification/runs/service.goindex 08ca6181..c7b53195 100644--- a/backend/internal/features/verification/runs/service.go+++ b/backend/internal/features/verification/runs/service.go@@ -692,9 +692,9 @@ func (s *VerificationService) notifyTerminal(title, body := buildNotificationCopy(verification, database, terminalStatus, failMessage)- sentNotificationType := notifier_models.NotificationTypeSuccess+ sentNotificationType := notifier_models.NotificationTypeVerificationSuccessif wantedType == verification_config.NotificationVerificationFailed {- sentNotificationType = notifier_models.NotificationTypeFailure+ sentNotificationType = notifier_models.NotificationTypeVerificationFailed}notification := notifier_models.Notification{diff --git a/backend/migrations/20260711065943_add_accept_notification_types_to_webhook_notifiers.sql b/backend/migrations/20260711065943_add_accept_notification_types_to_webhook_notifiers.sqlnew file mode 100644index 00000000..1c74a3e6--- /dev/null+++ b/backend/migrations/20260711065943_add_accept_notification_types_to_webhook_notifiers.sql@@ -0,0 +1,15 @@+-- +goose Up+-- +goose StatementBegin++ALTER TABLE webhook_notifiers+ ADD COLUMN accept_notification_types TEXT NOT NULL DEFAULT '["ALL"]';++-- +goose StatementEnd++-- +goose Down+-- +goose StatementBegin++ALTER TABLE webhook_notifiers+ DROP COLUMN accept_notification_types;++-- +goose StatementEnddiff --git a/frontend/src/entity/notifiers/index.ts b/frontend/src/entity/notifiers/index.tsindex 65e7798e..4143817f 100644--- a/frontend/src/entity/notifiers/index.ts+++ b/frontend/src/entity/notifiers/index.ts@@ -1,6 +1,7 @@export { notifierApi } from './api/notifierApi';export type { Notifier } from './models/Notifier';export { NotifierType } from './models/NotifierType';+export { NotificationType } from './models/NotificationType';export type { EmailNotifier } from './models/email/EmailNotifier';export { validateEmailNotifier } from './models/email/validateEmailNotifier';diff --git a/frontend/src/entity/notifiers/models/NotificationType.ts b/frontend/src/entity/notifiers/models/NotificationType.tsnew file mode 100644index 00000000..15021e52--- /dev/null+++ b/frontend/src/entity/notifiers/models/NotificationType.ts@@ -0,0 +1,9 @@+export enum NotificationType {+ ALL = 'ALL',+ BACKUP_SUCCESS = 'BACKUP_SUCCESS',+ BACKUP_FAILED = 'BACKUP_FAILED',+ HEALTHCHECK_SUCCESS = 'HEALTHCHECK_SUCCESS',+ HEALTHCHECK_FAILED = 'HEALTHCHECK_FAILED',+ VERIFICATION_SUCCESS = 'VERIFICATION_SUCCESS',+ VERIFICATION_FAILED = 'VERIFICATION_FAILED',+}diff --git a/frontend/src/entity/notifiers/models/webhook/WebhookNotifier.ts b/frontend/src/entity/notifiers/models/webhook/WebhookNotifier.tsindex ec6141a1..61f22b21 100644--- a/frontend/src/entity/notifiers/models/webhook/WebhookNotifier.ts+++ b/frontend/src/entity/notifiers/models/webhook/WebhookNotifier.ts@@ -1,3 +1,4 @@+import type { NotificationType } from '../NotificationType';import type { WebhookHeader } from './WebhookHeader';import type { WebhookMethod } from './WebhookMethod';@@ -6,4 +7,5 @@ export interface WebhookNotifier {webhookMethod: WebhookMethod;bodyTemplate?: string;headers?: WebhookHeader[];+ acceptNotificationTypes?: NotificationType[];}diff --git a/frontend/src/features/notifiers/lib/notificationTypeLabels.ts b/frontend/src/features/notifiers/lib/notificationTypeLabels.tsnew file mode 100644index 00000000..5cab4169--- /dev/null+++ b/frontend/src/features/notifiers/lib/notificationTypeLabels.ts@@ -0,0 +1,18 @@+import { NotificationType } from '../../../entity/notifiers';++export const NOTIFICATION_TYPE_LABELS: Record<NotificationType, string> = {+ [NotificationType.ALL]: 'All',+ [NotificationType.BACKUP_SUCCESS]: 'Backup success',+ [NotificationType.BACKUP_FAILED]: 'Backup failed',+ [NotificationType.HEALTHCHECK_SUCCESS]: 'Healthcheck success',+ [NotificationType.HEALTHCHECK_FAILED]: 'Healthcheck failed',+ [NotificationType.VERIFICATION_SUCCESS]: 'Verification success',+ [NotificationType.VERIFICATION_FAILED]: 'Verification failed',+};++export const NOTIFICATION_TYPE_OPTIONS = Object.values(NotificationType).map((value) => ({+ label: NOTIFICATION_TYPE_LABELS[value],+ value,+}));++export const DEFAULT_ACCEPT_NOTIFICATION_TYPES = [NotificationType.ALL];diff --git a/frontend/src/features/notifiers/ui/edit/notifiers/EditWebhookNotifierComponent.tsx b/frontend/src/features/notifiers/ui/edit/notifiers/EditWebhookNotifierComponent.tsxindex de87097f..24064808 100644--- a/frontend/src/features/notifiers/ui/edit/notifiers/EditWebhookNotifierComponent.tsx+++ b/frontend/src/features/notifiers/ui/edit/notifiers/EditWebhookNotifierComponent.tsx@@ -3,7 +3,12 @@ import { Button, Input, Select, Tooltip } from 'antd';import { useMemo } from 'react';import type { Notifier, WebhookHeader } from '../../../../../entity/notifiers';+import { NotificationType } from '../../../../../entity/notifiers';import { WebhookMethod } from '../../../../../entity/notifiers/models/webhook/WebhookMethod';+import {+ DEFAULT_ACCEPT_NOTIFICATION_TYPES,+ NOTIFICATION_TYPE_OPTIONS,+} from '../../../lib/notificationTypeLabels';interface Props {notifier: Notifier;@@ -41,17 +46,34 @@ export function EditWebhookNotifierComponent({ notifier, setNotifier, setUnsavedconst jsonError = useMemo(() => validateJsonTemplate(bodyTemplate), [bodyTemplate]);+ const acceptNotificationTypes =+ notifier?.webhookNotifier?.acceptNotificationTypes || DEFAULT_ACCEPT_NOTIFICATION_TYPES;+const updateWebhookNotifier = (updates: Partial<typeof notifier.webhookNotifier>) => {setNotifier({...notifier,webhookNotifier: {- ...(notifier.webhookNotifier || { webhookUrl: '', webhookMethod: WebhookMethod.POST }),+ ...(notifier.webhookNotifier || {+ webhookUrl: '',+ webhookMethod: WebhookMethod.POST,+ acceptNotificationTypes: [...DEFAULT_ACCEPT_NOTIFICATION_TYPES],+ }),...updates,},});setUnsaved();};+ const changeAcceptNotificationTypes = (selected: NotificationType[]) => {+ const isAllSelected =+ selected.length === 0 || selected[selected.length - 1] === NotificationType.ALL;+ updateWebhookNotifier({+ acceptNotificationTypes: isAllSelected+ ? [NotificationType.ALL]+ : selected.filter((type) => type !== NotificationType.ALL),+ });+ };+const addHeader = () => {updateWebhookNotifier({headers: [...headers, { key: '', value: '' }],@@ -102,6 +124,19 @@ export function EditWebhookNotifierComponent({ notifier, setNotifier, setUnsaved</div></div>+ <div className="mt-1 mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">+ <div className="mb-1 min-w-[150px] sm:mb-0">Send on</div>+ <Select+ mode="multiple"+ value={acceptNotificationTypes}+ onChange={(value) => changeAcceptNotificationTypes(value as NotificationType[])}+ size="small"+ className="w-full max-w-[250px]"+ options={NOTIFICATION_TYPE_OPTIONS}+ placeholder="Select notification types"+ />+ </div>+<div className="mt-3 mb-1 flex w-full flex-col items-start"><div className="mb-1 flex items-center"><span className="min-w-[150px]">diff --git a/frontend/src/features/notifiers/ui/show/notifier/ShowWebhookNotifierComponent.tsx b/frontend/src/features/notifiers/ui/show/notifier/ShowWebhookNotifierComponent.tsxindex ce53a112..5b5ab8d7 100644--- a/frontend/src/features/notifiers/ui/show/notifier/ShowWebhookNotifierComponent.tsx+++ b/frontend/src/features/notifiers/ui/show/notifier/ShowWebhookNotifierComponent.tsx@@ -1,5 +1,9 @@import type { Notifier, WebhookHeader } from '../../../../../entity/notifiers';import { WebhookMethod } from '../../../../../entity/notifiers';+import {+ DEFAULT_ACCEPT_NOTIFICATION_TYPES,+ NOTIFICATION_TYPE_LABELS,+} from '../../../lib/notificationTypeLabels';interface Props {notifier: Notifier;@@ -9,6 +13,9 @@ export function ShowWebhookNotifierComponent({ notifier }: Props) {const headers = notifier?.webhookNotifier?.headers || [];const hasHeaders = headers.filter((h: WebhookHeader) => h.key).length > 0;+ const acceptNotificationTypes =+ notifier?.webhookNotifier?.acceptNotificationTypes || DEFAULT_ACCEPT_NOTIFICATION_TYPES;+return (<><div className="flex items-center">@@ -21,6 +28,13 @@ export function ShowWebhookNotifierComponent({ notifier }: Props) {<div>{notifier?.webhookNotifier?.webhookMethod || '-'}</div></div>+ <div className="mt-1 mb-1 flex items-center">+ <div className="min-w-[110px]">Send on</div>+ <div>+ {acceptNotificationTypes.map((type) => NOTIFICATION_TYPE_LABELS[type]).join(', ') || '-'}+ </div>+ </div>+{hasHeaders && (<div className="mt-1 mb-1 flex items-start"><div className="min-w-[110px]">Headers</div>