-
-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom webhook converters for Grafana, GitHub, ... (was: pretty grafana notifications?) #724
Comments
What you see there on the website is an "elaborate" fake 😄 It's not real. I have Grafana alerts set up on my phone as well, and I get a giant JSON blob to ntfy and I hate it. However, if I start adding endpoints for one thing, everything under the sun now wants to add endpoints too: GitHub, Grafana, Prometheus, Uptime Kuma, all the things. I suppose I could add a plugin-type thing that would allow incoming webhooks to be processed .... 🤔 |
Thinking out loud: Thoughts: curl -d '{"alert":"something is down"}` ntfy.sh/alerts/$converter e.g. curl -d '{"alert":"something is down"}` ntfy.sh/alerts/grafana
curl -d '{"alert":"something is down"}` ntfy.sh/alerts/github
curl -d '{"alert":"something is down"}` ntfy.sh/alerts/myconverter
... We could have built-in ones, and custom ones: message-converter-dir: /etc/ntfy/converter.d with scripts like this (e.g. #!/bin/bash
jq '{ message: .alert }' FYI: echo '{"alert":"hi there"}' | jq '{ message: .alert }'
{
"message": "hi there"
} The biggest problem with this is that this would run a subshell for every incoming message that uses an external converter, which can easily blow up the server. |
I guess we could use Go plugins (https://pkg.go.dev/plugin), though that would limit it to Go. Or we could use an IPC approach using STDIN/STDOUT. PowerDNS uses that for its A converter script would look like this. Reading messages on STDIN (one line per message, or whatever format we decide), and then output the converted message on STDOUT (in one line):
Here's an example usage (I manually typed the
The problem with that is that is not necessarily in our control how messages come in to ntfy. So if Grafana send the JSON as pretty-print the whole one line thing goes out the window. 🤔 |
What about using a library like this? https://github.com/buger/jsonparser It will let you specify a path to a specific value in the JSON object. And it does everything in Go. So you could set up a YAML config like this converters:
- grafana:
title: object.key
message: object.nested.nested.key Then you split the value of |
If you wanted to go further here, you could also check out https://github.com/hashicorp/go-plugin - this also might be useful. All the best, |
Btw I am unsure whether these kinds of conversions should happen in ntfy; or if this should be done e.g. in Caddy outside ntfy. |
Love ntfy.
For grafana it works, but shows just plain ugly json on its own.
I use Grafana-to-ntfy to make it look good.
But I just noticed that straight up on ntfy homepage demo pictures, theres pretty grafana notification. Did you use also grafana-to-ntfy to make it so, or is it build in and needs some enabling?
Feels kinda clunky to be running another container to get it working.
The text was updated successfully, but these errors were encountered: