Closed IncognitoCoding closed 1 year ago
I had some spare time this evening, so I revised the code with all discussed changes with the exception of the folder structure with tokens since that piece is still being discussed.
Great - thanks! Apologies for the delay in updates, I was out of pocket the past week or so.
Great - thanks! Apologies for the delay in updates, I was out of pocket the past week or so.
No worries. Life can sometimes get in the way of hobbies.
Would that solve my question in #6 ?
Would that solve my question in #6 ?
Yes, this pull request (PR) will allow you to create one or multiple user-defined templates to send customized messages to Gotify. You can use any key (including: status
, generatorURL
, etc.) from the JSON sent from alertmanager. Depending on the product, some alerts may have more detail outside the annotations section, which user-defined templating would allow any usage of those keys/values.
You would have two options:
if/else
to set the status of firing
or resolved
based on the received status
.Firing
and Resolved
templates.You can read more details on the usage in this PR's ReadMe file under the Bridge Message Templating
section.
Would love to see that being incorporated.
Thanks so much for accepting and incorporating the feedback! I'll go ahead and release this version today!
Thanks for releasing it so quickly.
I am not able to get it working properly, maybe I miss something here. I like to have a very simple icon showing when alerts fire or are resolved, together with the actual title, then the description.
I've successfully mounted to /./templates
(using docker, should we document that this is root in case of the docker image or allow setting a path/env var?) and it's loading the templates (at least no error which I had before).
{{ define "MyGotifyToken" }}
{{ if eq (.Status) ("firing") }}🔥 {{else}}✅ {{end}}
{{ .Annotations.summary }}
{{ .GeneratorURL }}
{{end}}
I am sending the following request to my /gotify_webhook
url:
{ "alerts": [
{
"annotations": {
"description":"A description",
"summary":"hmmm test",
"priority":"critical"
},
"status": "firing",
"generatorURL": "http://foobar.com"
}
]}
I am not getting any icon, neither a generator URL.
Could you maybe outline a simple working example?
Thanks for releasing it so quickly.
I am not able to get it working properly, maybe I miss something here. I like to have a very simple icon showing when alerts fire or are resolved, together with the actual title, then the description.
I've successfully mounted to
/./templates
(using docker, should we document that this is root in case of the docker image or allow setting a path/env var?) and it's loading the templates (at least no error which I had before).{{ define "MyGotifyToken" }} {{ if eq (.Status) ("firing") }}🔥 {{else}}✅ {{end}} {{ .Annotations.summary }} {{ .GeneratorURL }} {{end}}
I am sending the following request to my
/gotify_webhook
url:{ "alerts": [ { "annotations": { "description":"A description", "summary":"hmmm test", "priority":"critical" }, "status": "firing", "generatorURL": "http://foobar.com" } ]}
I am not getting any icon, neither a generator URL.
Could you maybe outline a simple working example?
Using the bind mount with /./templates
is the correct way to mount your templates folder. I will make an edit to the ReadMe
.
../alertmanager_gotify_bridge/templates:/./templates
Your test case is correct as long as you have entered the correct MyGotifyToken
.
Since you are not getting an icon
or generator URL
, I assume you updated or set up your testing templates after the bridge was already running. All user-templates are loaded during startup. Any template changes will always require a restart or update to the service to see the changes reflect. Please restart or update the service and try again.
@IncognitoCoding Yes, I have restarted the service, actually I did down
and up
with docker-compose
, so that should be all OK. My gotify token is also correct, it's the same as I've used as in GOTIFY_TOKEN=
.
It doesn't seem to match. Doing a POST request to the /gotify_webhook
should always use that token, right, so not sure. It should be working.
@IncognitoCoding Yes, I have restarted the service, actually I did
down
andup
withdocker-compose
, so that should be all OK. My gotify token is also correct, it's the same as I've used as inGOTIFY_TOKEN=
.It doesn't seem to match. Doing a POST request to the
/gotify_webhook
should always use that token, right, so not sure. It should be working.
I figured out your issue. The problem is a variable being passed during the template process. A typo in the code had the token override
value as the only option to use the templates. You are likely using the default GOTIFY_TOKEN
set in the docker. This was a simple fix, and I am submitting a PR request for this fix today.
As a temporary workaround, use the token override in your URL. You can also keep the token you have set in your docker file. The token override will override any token in the docker-compose file. Once the PR is approved, your template will work with just the docker token.
Thanks. Works when passing via query parameter.
Yesterday, I added my NetApp storage array through Prometheus for metrics/alerting and realized the sending JSON would not be limited in data because of the fields used, and I would have no easy way of formatting the message since the alerts can not be set up through Grafana.
This got me thinking about how I could implement file templating into the bridge, and once I figured out a plan, I started drafting up the code.
This PR will allow dedicated user-defined templates based on the Gotify software token. This feature can enable alerts not sent from Grafana to have the ability to present to Gotify cleanly using any
key
value from the JSON.I had to shuffle around some of the code with a few if/else statements so that you will see a decent chunk of red, but a good amount of the code is just being shifted by
tab
.I added several checks to the code and set it up to prevent user-defined templates from crashing the bridge. Anything not done correctly in the templates will have the bridge revert the message to default alerting.
I did not update the docker-compose
ReadMe
section for the bind mount because I did not know how you wanted to add that into the docker, so I left it open for your edits.Let me know what you think.