Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions docs/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Ofelia includes presets for popular notification services:
| `discord` | Discord Webhooks | `id`, `secret` |
| `teams` | Microsoft Teams | `url` |
| `matrix` | Matrix (via hookshot bridge) | `url` |
| `ntfy` | ntfy.sh | `id` (topic) |
| `ntfy` | ntfy.sh (public topics) | `id` (topic) |
| `ntfy-token` | ntfy.sh (with Bearer auth) | `id` (topic), `secret` (access token) |
| `pushover` | Pushover | `id` (user key), `secret` (API token) |
| `pagerduty` | PagerDuty Events API v2 | `secret` (routing key) |
| `gotify` | Gotify | `url`, `secret` (app token) |
Expand Down Expand Up @@ -154,21 +155,36 @@ The optional `link` and `link-text` fields add a clickable link to your notifica

### ntfy

For public topics on ntfy.sh (no authentication):
```ini
[webhook "ntfy-notify"]
preset = ntfy
id = my-topic-name
trigger = always
```

For self-hosted ntfy:
For private topics or self-hosted ntfy with access tokens:
```ini
[webhook "ntfy-private"]
preset = ntfy-token
id = my-private-topic
secret = tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
trigger = always
```

For self-hosted ntfy with custom URL and authentication:
```ini
[webhook "ntfy-self-hosted"]
preset = ntfy
preset = ntfy-token
url = https://ntfy.example.com/my-topic
secret = tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
trigger = always
```

> **Note**: Use `ntfy` for public topics without authentication, and `ntfy-token` when
> Bearer token authentication is required (self-hosted instances with access control
> or private topics on ntfy.sh).

### Pushover

```ini
Expand Down
18 changes: 17 additions & 1 deletion middlewares/preset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ func (s *SuitePreset) TestPresetLoader_LoadBundledPreset_Ntfy(c *C) {
c.Assert(err, IsNil)
c.Assert(preset, NotNil)
c.Assert(preset.Name, Equals, "ntfy")
// ntfy preset is for public topics - should NOT have Authorization header
_, hasAuth := preset.Headers["Authorization"]
c.Assert(hasAuth, Equals, false)
}

func (s *SuitePreset) TestPresetLoader_LoadBundledPreset_NtfyToken(c *C) {
loader := NewPresetLoader(nil)
preset, err := loader.Load("ntfy-token")

c.Assert(err, IsNil)
c.Assert(preset, NotNil)
c.Assert(preset.Name, Equals, "ntfy-token")
// ntfy-token preset should have Bearer Authorization header
c.Assert(preset.Headers["Authorization"], Equals, "Bearer {secret}")
// Secret should be required
c.Assert(preset.Variables["secret"].Required, Equals, true)
}

func (s *SuitePreset) TestPresetLoader_LoadBundledPreset_Pushover(c *C) {
Expand Down Expand Up @@ -190,7 +206,7 @@ func (s *SuitePreset) TestListBundledPresets(c *C) {
loader := NewPresetLoader(nil)
presets := loader.ListBundledPresets()

c.Assert(len(presets) >= 7, Equals, true)
c.Assert(len(presets) >= 9, Equals, true)

// Check that expected presets are present
hasSlack := false
Expand Down
37 changes: 37 additions & 0 deletions middlewares/presets/ntfy-token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ntfy-token
description: "ntfy.sh push notifications with Bearer token authentication for self-hosted instances or private topics"
version: "1.0.0"

url_scheme: "https://ntfy.sh/{id}"

method: POST
headers:
Content-Type: "application/json"
Authorization: "Bearer {secret}"

variables:
id:
description: "ntfy topic name"
required: true
example: "ofelia-alerts"
secret:
description: "ntfy access token (required for private topics)"
required: true
sensitive: true
example: "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2"

body: |
{
"topic": "{{.Job.Name}}",
"title": "Ofelia: {{.Job.Name}} - {{.Execution.Status}}",
"message": "Job {{.Job.Name}} {{if .Execution.Failed}}failed{{else if .Execution.Skipped}}was skipped{{else}}completed successfully{{end}} in {{.Execution.Duration}}{{if .Execution.Failed}}\n\nError: {{.Execution.Error}}{{end}}",
"priority": {{if .Execution.Failed}}5{{else if .Execution.Skipped}}3{{else}}3{{end}},
"tags": [
{{- if .Execution.Failed }}"warning","x"
{{- else if .Execution.Skipped }}"hourglass"
{{- else }}"white_check_mark"
{{- end }}
],
"click": "",
"actions": []
}
11 changes: 3 additions & 8 deletions middlewares/presets/ntfy.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ntfy
description: "ntfy.sh push notifications"
version: "1.0.0"
description: "ntfy.sh push notifications for public topics (use ntfy-token for authenticated access)"
version: "1.0.1"

url_scheme: "https://ntfy.sh/{id}"

Expand All @@ -10,14 +10,9 @@ headers:

variables:
id:
description: "ntfy topic name"
description: "ntfy topic name (public topic, no authentication)"
required: true
example: "ofelia-alerts"
secret:
description: "ntfy access token (optional, for private topics)"
required: false
sensitive: true
example: "tk_..."

body: |
{
Expand Down
Loading