diff --git a/weed/notification/webhook/webhook_queue.go b/weed/notification/webhook/webhook_queue.go index a48b8a2aac..fc7c0e3efe 100644 --- a/weed/notification/webhook/webhook_queue.go +++ b/weed/notification/webhook/webhook_queue.go @@ -112,7 +112,7 @@ func namedTargetPrefixes(configuration util.Configuration, prefix string) []stri func buildTargets(configuration util.Configuration, prefix string) ([]*target, error) { var prefixes []string - if configuration.GetBool(prefix+"enabled") || configuration.GetString(prefix+"endpoint") != "" { + if configuration.GetBool(prefix + "enabled") { prefixes = append(prefixes, prefix) } prefixes = append(prefixes, namedTargetPrefixes(configuration, prefix)...) diff --git a/weed/notification/webhook/webhook_queue_test.go b/weed/notification/webhook/webhook_queue_test.go index e33a819442..fe15509959 100644 --- a/weed/notification/webhook/webhook_queue_test.go +++ b/weed/notification/webhook/webhook_queue_test.go @@ -653,3 +653,31 @@ func TestNamedTargets(t *testing.T) { t.Errorf("SendMessage() error = %v", err) } } + +// A disabled flat section keeps no target even when an endpoint is set — +// the scaffold ships exactly that combination, and a named target must not +// reactivate it. +func TestBuildTargetsDisabledFlat(t *testing.T) { + cfg := &mapConfig{values: map[string]interface{}{ + "notification.webhook": map[string]interface{}{ + "enabled": false, + "endpoint": "https://your-server.com/webhook", + "named": map[string]interface{}{ + "enabled": true, + "endpoint": "https://example.com/hook", + }, + }, + "notification.webhook.enabled": false, + "notification.webhook.endpoint": "https://your-server.com/webhook", + "notification.webhook.named.enabled": true, + "notification.webhook.named.endpoint": "https://example.com/hook", + }} + + targets, err := buildTargets(cfg, "notification.webhook.") + if err != nil { + t.Fatalf("buildTargets() error = %v", err) + } + if len(targets) != 1 || targets[0].name != "named" { + t.Fatalf("expected only the named target, got %v", targets) + } +}