From 796c4468e84f0d7e21f0feddeba7f0c2e13b45ce Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Mon, 1 Sep 2025 22:08:07 +0000 Subject: [PATCH] enhance: make Gotify and ntfy notifications as rich as Discord/Telegram MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - added color-coded emoji indicators (šŸ”“/🟔/🟢) for alert levels - enriched message formatting with better structure and emojis - improved titles to show resource name and alert type clearly - ntfy now has dynamic headers for priority and tags based on alert level - both services now match the detail level of Discord and Telegram --- internal/notifications/webhook_templates.go | 28 +++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/notifications/webhook_templates.go b/internal/notifications/webhook_templates.go index 570e3c0c3..fb8a6d074 100644 --- a/internal/notifications/webhook_templates.go +++ b/internal/notifications/webhook_templates.go @@ -237,8 +237,8 @@ func GetWebhookTemplates() []WebhookTemplate { Method: "POST", Headers: map[string]string{"Content-Type": "application/json"}, PayloadTemplate: `{ - "message": "**{{.ResourceName}}** on node **{{.Node}}**\n\n{{.Message}}\n\nšŸ“Š **Details:**\n- Type: {{.Type | title}}\n- Current: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.1f" .Value}} MB/s{{else}}{{printf "%.1f" .Value}}%{{end}}\n- Threshold: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.0f" .Threshold}} MB/s{{else}}{{printf "%.0f" .Threshold}}%{{end}}\n- Duration: {{.Duration}}\n\n[View in Pulse]({{.Instance}})", - "title": "{{.Level | title}}: {{.ResourceName}}", + "message": "{{if eq .Level "critical"}}šŸ”“ **CRITICAL**{{else if eq .Level "warning"}}🟔 **WARNING**{{else}}🟢 **INFO**{{end}}: **{{.ResourceName}}** on **{{.Node}}**\n\n{{.Message}}\n\nšŸ“Š **Alert Details:**\n• šŸ–„ļø **Resource:** {{.ResourceName}}\n• šŸ—„ļø **Node:** {{.Node}}\n• šŸ“ˆ **Type:** {{.Type | title}}\n• šŸŽÆ **Current:** {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.1f" .Value}} MB/s{{else}}{{printf "%.1f" .Value}}%{{end}}\n• āš ļø **Threshold:** {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.0f" .Threshold}} MB/s{{else}}{{printf "%.0f" .Threshold}}%{{end}}\n• ā±ļø **Duration:** {{.Duration}}\n• šŸ†” **Alert ID:** {{.ID}}\n\nšŸ”— [View in Pulse]({{.Instance}})", + "title": "{{if eq .Level "critical"}}šŸ”“{{else if eq .Level "warning"}}🟔{{else}}🟢{{end}} {{.ResourceName}} - {{.Type | title}} Alert", "priority": {{if eq .Level "critical"}}10{{else if eq .Level "warning"}}5{{else}}2{{end}}, "extras": { "client::display": { @@ -266,22 +266,24 @@ func GetWebhookTemplates() []WebhookTemplate { Method: "POST", Headers: map[string]string{ "Content-Type": "text/plain", - "Title": "Pulse Alert", - "Priority": "urgent", - "Tags": "pulse,monitoring", + "Title": "{{if eq .Level \"critical\"}}šŸ”“ CRITICAL{{else if eq .Level \"warning\"}}🟔 WARNING{{else}}🟢 INFO{{end}}: {{.ResourceName}}", + "Priority": "{{if eq .Level \"critical\"}}urgent{{else if eq .Level \"warning\"}}high{{else}}default{{end}}", + "Tags": "{{if eq .Level \"critical\"}}rotating_light{{else if eq .Level \"warning\"}}warning{{else}}white_check_mark{{end}},pulse,{{.Type}}", }, - PayloadTemplate: `🚨 {{.Level | title}} Alert: {{.ResourceName}} + PayloadTemplate: `{{if eq .Level "critical"}}šŸ”“ CRITICAL{{else if eq .Level "warning"}}🟔 WARNING{{else}}🟢 INFO{{end}}: {{.ResourceName}} on {{.Node}} {{.Message}} -šŸ“Š Details: -• Node: {{.Node}} -• Type: {{.Type | title}} -• Value: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.1f" .Value}} MB/s{{else}}{{printf "%.1f" .Value}}%{{end}} -• Threshold: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.0f" .Threshold}} MB/s{{else}}{{printf "%.0f" .Threshold}}%{{end}} -• Duration: {{.Duration}} +šŸ“Š Alert Details: +• šŸ–„ļø Resource: {{.ResourceName}} +• šŸ—„ļø Node: {{.Node}} +• šŸ“ˆ Type: {{.Type | title}} +• šŸŽÆ Current: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.1f" .Value}} MB/s{{else}}{{printf "%.1f" .Value}}%{{end}} +• āš ļø Threshold: {{if or (eq .Type "diskRead") (eq .Type "diskWrite")}}{{printf "%.0f" .Threshold}} MB/s{{else}}{{printf "%.0f" .Threshold}}%{{end}} +• ā±ļø Duration: {{.Duration}} +• šŸ†” Alert ID: {{.ID}} -View in Pulse: {{.Instance}}`, +šŸ”— View in Pulse: {{.Instance}}`, Instructions: "1. Choose a topic name (e.g., 'my-pulse-alerts')\n2. URL format: https://ntfy.sh/YOUR_TOPIC\n Or for self-hosted: https://your-ntfy-server/YOUR_TOPIC\n3. Optional: Add authentication token in headers if required\n4. Subscribe to the topic in your ntfy app using the same topic name", }, {