Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Register template funcs on the enhanced ntfy payload path

rcourtmana44e5513cabf
diff --git a/internal/notifications/webhook_enhanced.go b/internal/notifications/webhook_enhanced.go
index 43cff3c549..269e9ef2e4 100644
--- a/internal/notifications/webhook_enhanced.go
+++ b/internal/notifications/webhook_enhanced.go
@@ -167,7 +167,7 @@ func (n *NotificationManager) prepareEnhancedWebhookExecution(webhook EnhancedWe
webhook.WebhookConfig = canonical
if webhook.Service == "ntfy" && strings.TrimSpace(webhook.PayloadTemplate) != "" {
- tmpl, err := template.New("enhanced-webhook-ntfy").Parse(webhook.PayloadTemplate)
+ tmpl, err := template.New("enhanced-webhook-ntfy").Funcs(templateFuncMap()).Parse(webhook.PayloadTemplate)
if err != nil {
return webhook, nil, fmt.Errorf("parse ntfy payload template: %w", err)
}
diff --git a/internal/notifications/webhook_enhanced_test.go b/internal/notifications/webhook_enhanced_test.go
index cccfac116e..cbbf358f1d 100644
--- a/internal/notifications/webhook_enhanced_test.go
+++ b/internal/notifications/webhook_enhanced_test.go
@@ -664,6 +664,46 @@ func TestPrepareEnhancedWebhookExecution_NtfyPreservesPlainTextPayload(t *testin
assert.Equal(t, "Alert for vm-101 on pve-01", string(payload))
}
+func TestPrepareEnhancedWebhookExecution_NtfyRendersBuiltinPresetTemplate(t *testing.T) {
+ nm := NewNotificationManager("http://pulse.local")
+
+ var preset *WebhookTemplate
+ for i := range GetWebhookTemplates() {
+ tmpl := GetWebhookTemplates()[i]
+ if tmpl.Service == "ntfy" {
+ preset = &tmpl
+ break
+ }
+ }
+ require.NotNil(t, preset, "built-in ntfy webhook template missing")
+
+ webhook := EnhancedWebhookConfig{
+ WebhookConfig: WebhookConfig{
+ Name: "ntfy Preset Test",
+ URL: "https://example.com/topic",
+ },
+ Service: "ntfy",
+ PayloadTemplate: preset.PayloadTemplate,
+ }
+
+ alert := &alerts.Alert{
+ ID: "alert-123",
+ Type: "cpu",
+ Level: "warning",
+ ResourceName: "vm-101",
+ Node: "pve-01",
+ Message: "CPU usage above threshold",
+ Value: 92.5,
+ Threshold: 90,
+ }
+
+ prepared, payload, err := nm.prepareEnhancedWebhookExecution(webhook, alert)
+ require.NoError(t, err)
+ assert.Equal(t, "https://example.com/topic", prepared.URL)
+ assert.Contains(t, string(payload), "WARNING: vm-101 on pve-01")
+ assert.Contains(t, string(payload), "- Type: Cpu")
+}
+
func TestBuildEnhancedWebhookTestConfig_UsesServiceTemplateOwnership(t *testing.T) {
basic := WebhookConfig{
Name: "Discord test",