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

Mute some types of notifications but always sending notifications when images update #1313

Open
gouku opened this issue Jul 3, 2022 · 5 comments

Comments

@gouku
Copy link

gouku commented Jul 3, 2022

Is your feature request related to a problem? Please describe.
We have some servers behind the cooperate proxy and the connection to the internet is not stable. So we always got spammed by the Could not do a head request... notifications:

Could not do a head request for "[index.docker.io/acme/image:latest](http://index.docker.io/acme/image:latest)", falling back to regular pull.
Reason: Get "https://index.docker.io/v2/": net/http: TLS handshake timeout
Unable to update container "/docker-image-1": Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers). Proceeding to next.

This is ok we can bear this type of network issues but there's no way to disable this type of notifications while we can receive the real image update notifications.

When we set WATCHTOWER_NOTIFICATIONS_LEVEL to warn or higher. The regular update notifications will also be muted.

Describe the solution you'd like
Add an option to always send the real update notifications even when WATCHTOWER_NOTIFICATIONS_LEVEL is set to warn or higher. ie. WATCHTOWER_NOTIFICATIONS_ALWAYS_SEND_UPDATES

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@github-actions
Copy link

github-actions bot commented Jul 3, 2022

Hi there! 👋🏼 As you're new to this repo, we'd like to suggest that you read our code of conduct as well as our contribution guidelines. Thanks a bunch for opening your first issue! 🙏

@piksel
Copy link
Member

piksel commented Jul 4, 2022

This is possible to do with the new "report" notification templates. To enable them, add --notification-report or WATCHTOWER_NOTIFICATION_REPORT=true.

The default template look like this:

shoutrrrDefaultTemplate = `
{{- if .Report -}}
{{- with .Report -}}
{{- if ( or .Updated .Failed ) -}}
{{len .Scanned}} Scanned, {{len .Updated}} Updated, {{len .Failed}} Failed
{{- range .Updated}}
- {{.Name}} ({{.ImageName}}): {{.CurrentImageID.ShortID}} updated to {{.LatestImageID.ShortID}}
{{- end -}}
{{- range .Fresh}}
- {{.Name}} ({{.ImageName}}): {{.State}}
{{- end -}}
{{- range .Skipped}}
- {{.Name}} ({{.ImageName}}): {{.State}}: {{.Error}}
{{- end -}}
{{- range .Failed}}
- {{.Name}} ({{.ImageName}}): {{.State}}: {{.Error}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{range .Entries -}}{{.Message}}{{"\n"}}{{- end -}}
{{- end -}}`

If you just put that template, but omitting the else clause

{{- else -}}
  {{range .Entries -}}{{.Message}}{{"\n"}}{{- end -}}
{{- end -}}`

it will only notify with the results of a session, not the individual log records. You can also modify the condition for when to send it, from {{- if ( or .Updated .Failed ) -}} to {{- if ( .Updated ) -}} to skip any reports about containers that could not be checked.

@piksel
Copy link
Member

piksel commented Jul 4, 2022

Something like this:

version: "3"
services:
  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      WATCHTOWER_NOTIFICATION_TEMPLATE: >
        {{- if .Report -}} 
          {{- with .Report -}} 
            {{- if ( .Updated ) -}} 
        {{len .Scanned}} Scanned, {{len .Updated}} Updated, {{len .Failed}} Failed 
              {{- range .Updated}} 
        - {{.Name}} ({{.ImageName}}): {{.CurrentImageID.ShortID}} updated to {{.LatestImageID.ShortID}} 
              {{- end -}} 
              {{- range .Fresh}} 
        - {{.Name}} ({{.ImageName}}): {{.State}} 
            {{- end -}} 
            {{- range .Skipped}} 
        - {{.Name}} ({{.ImageName}}): {{.State}}: {{.Error}} 
            {{- end -}} 
            {{- range .Failed}} 
        - {{.Name}} ({{.ImageName}}): {{.State}}: {{.Error}} 
            {{- end -}} 
            {{- end -}} 
          {{- end -}} 
        {{- end -}}

      WATCHTOWER_NOTIFICATION_REPORT: "true"

@Niek
Copy link

Niek commented May 13, 2023

Thanks @piksel! I was looking for this, Docker and other registries have multiple outages per day, so muting the errors is quite useful. Maybe it would be good to link to this issue in the documentation?

@Niek
Copy link

Niek commented Jun 12, 2023

I got this error when I tried to apply the custom template:

FATA[0001] Notification template error                   error="template: :1:7: executing \"\" at <.Report>: can't evaluate field Report in type []*logrus.Entry" notify=no

Edit: adding WATCHTOWER_NOTIFICATION_REPORT: "true" fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants