Skip to content
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

feature(markdown): Enables markdown notifications support #32

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

thomas-maurice
Copy link
Contributor

@thomas-maurice thomas-maurice commented Feb 4, 2024

This pull request enables the support for markdown being rendered properly on the client side via a --markdown flag (or the corresponding MARKDOWN environment variable). This also removes the support for HTML as it is not supported on gotify mobile.

This has the side effect of not allowing to add colours in the notifications, but that didn't work initially anyways.

Similarly it allows to set a --click_to_generator flag (CLICK_TO_GENERATOR environment variable) that allows to make the client notification clickable when opened on mobile. Previously this behaviour implied the use of --extended_details, but this would also force the use of HTML, which is not supported (as per #31 and my own testing).

End result, the following alert would show up as follows

{
  "receiver": "webhook",
  "status": "firing",
  "alerts": [
    {
      "status": "firing",
      "labels": {
        "alertname": "TestAlertName",
        "dc": "eu-west-1",
        "instance": "somehost.fr",
        "job": "prometheus"
      },
      "annotations": {
        "description": "some description **but with** _markdown_ ~~test~~ [a link](https://google.fr)",
        "summary": "This is the alert summary, something is really bad",
        "priority": "critical"
      },
      "startsAt": "2018-08-03T09:52:26.739266876+02:00",
      "endsAt": "0001-01-01T00:00:00Z",
      "generatorURL": "https://google.fr"                                                                                  
    }
  ],
  "externalURL": "http://example.com:9093",
  "version": "4",
  "groupKey": "{}:{alertname=\"Test\", job=\"prometheus\"}"
}

On web:
Screenshot from 2024-02-17 12-29-23

On the app:
image

The notification sends me to the generator URL specified in the alert when I click on it on mobile, and nothing happens when the generator URL is absent from the json.

For reproducibility, the templates I used are:
title.tmpl:

{{ define "title=TOKEN" }}
{{- if eq (.Status) ("firing") }}🔥 {{ .Labels.alertname }}{{else}}✅ {{ .Labels.alertname }}{{end}}
{{end}}

main.tmpl:

{{- define "TOKEN" -}}
{{- .Annotations.summary }}

{{ .Annotations.description }}

**Labels**:
{{ range $key, $value := .Labels -}}
{{ $key }} = {{ $value }}
{{ end }}
{{- end }}

Copy link
Owner

@DRuggeri DRuggeri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea - thanks for the PR!

There's just one structural thing to take care of regarding the nil check and maybe a tweak to the help line

I'd also like to float an idea out there... any interest in just replacing the extendedDetails HTML implementation with markdown while in the neighborhood? It was added in #7 but I didn't realize HTML is not supported. #31 further confirms what your own testing shows... it doesn't work. I was planning to modify it to replace the HTML with markdown where it can be done but have the limitation that all my own alerts are boring and simple plaintext so I'd have to set up some test cases (which isn't hard to do, I just haven't gotten to it yet).

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@thomas-maurice
Copy link
Contributor Author

thomas-maurice commented Feb 16, 2024

Thanks for the review!

I'd also like to float an idea out there... any interest in just replacing the extendedDetails HTML implementation with markdown while in the neighborhood?

I can definitely do that.

My alerts are also pretty vanilla but it is nice to add some markdown in the templates for links, highlighting important labels and so on, so i figured why not add a bit of style to my notifications saying that my homelab is down

I'll get to it over the weekend :)

@thomas-maurice
Copy link
Contributor Author

@DRuggeri fixed, and updated the pull request description to reflect the change/give you all you need to test it on your side if you want to !

@DRuggeri DRuggeri merged commit 91bccff into DRuggeri:master Feb 19, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants