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

Webhook alerts, several warnings #170

Open
woody4165 opened this issue Nov 3, 2024 · 17 comments
Open

Webhook alerts, several warnings #170

woody4165 opened this issue Nov 3, 2024 · 17 comments

Comments

@woody4165
Copy link

Hi

I have set webhook alerts and I get several WARN in the log

This is part of the log with warnings

2024/11/03 18:54:25 +0100 WRN util/httpclient.go:185 > HTTP Request failed, retries exceeded error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=66 with Body length 0" attempt=6 max_tries=6
2024/11/03 18:54:25 +0100 WRN notifier/webhook.go:53 > Unable to send alert error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=66 with Body length 0" event_id=1730656447.78467-smy8sq provider=Webhook
2024/11/03 18:54:25 +0100 WRN util/httpclient.go:192 > HTTP Request failed, retrying in 10 seconds... error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" attempt=4 max_tries=6
2024/11/03 18:54:25 +0100 WRN util/httpclient.go:192 > HTTP Request failed, retrying in 10 seconds... error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=67 with Body length 0" attempt=2 max_tries=6
2024/11/03 18:54:26 +0100 WRN util/httpclient.go:192 > HTTP Request failed, retrying in 10 seconds... error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" attempt=5 max_tries=6

and this is my configuration

frigate:
  server: xxxxxxxx:5000
  ignoressl: true
  startup_check:
    attempts: 5
    interval: 30

  mqtt: 
    enabled: true
    server: xxxxxx
    port: 1883
    clientid: frigate-notify
    username: user
    password: pass
    topic_prefix: frigate

  cameras:
    exclude:
      - patio
      - porta

alerts:
  general:
    title: Frigate Alert
    timeformat: 15:04:05 del 02 Gen 2006 
    nosnap:
    snap_bbox: true
    snap_timestamp:

    snap_crop:
    notify_once: true

  quiet:
    start:
    end:

  zones:
    unzoned: allow
    allow:
     - viale
     - scala
     - prato

  labels:
    min_score: 20
    allow:
     - person
     - car
     - motorcycle
     - bicycle
    block:
     - dog
     - cat

  telegram:
    enabled: true
    chatid: xxxxxx
    token: xxxxxxxx
    template: |
      Motion alle {{ .Extra.FormattedTime }}
      Camera: {{ .Camera }}
      Label: {{ .Label }} ({{ .Extra.TopScorePercent }})
      Links:
      {{ if ne .Extra.PublicURL "" }}{{if ge .Extra.FrigateMajorVersion 14 }} - Camera: {{ .Extra.PublicURL }}/#{{ .Camera }}{{else}} - Camera: {{ .Extra.PublicURL }}/cameras/{{ .Camera }}{{end}}
      {{ if .HasClip }} - Event Clip: {{ .Extra.PublicURL }}/api/events/{{ .ID }}/clip.mp4{{ end }}
      {{ else }}{{if ge .Extra.FrigateMajorVersion 14 }} - Camera: {{ .Extra.LocalURL }}/#{{ .Camera }}{{ else }} - Camera: {{ .Extra.LocalURL }}/cameras/{{ .Camera }}{{ end }}
      {{ if .HasClip }} - Event Clip: {{ .Extra.LocalURL }}/api/events/{{ .ID }}/clip.mp4{{ end }}
      {{ end }}

      {{ if not .HasSnapshot }}Nessuno snapshot disponibile.{{end}}

  webhook: 
    enabled: true
    server: http://xxxxxxx:1880/webhook-frigate
    header:
      Content-Type: "application/json"
    template: 
       camera: "{{ .Camera }}" 
       label: "{{ .Label }}" 
       id: "{{ .ID }}"   

What can I check/do?

Thanks

@woody4165 woody4165 changed the title Wehook alerts, several Wehook alerts, several warnings Nov 3, 2024
@woody4165 woody4165 changed the title Wehook alerts, several warnings Webhook alerts, several warnings Nov 3, 2024
@freefd
Copy link
Contributor

freefd commented Nov 3, 2024

What can I check/do?

You missed the pipe symbol for the template in the webhook notifier, it should look like:

...
  webhook: 
    enabled: true
    server: http://xxxxxxx:1880/webhook-frigate
    header:
      Content-Type: "application/json"
    template: |
       camera: "{{ .Camera }}" 
       label: "{{ .Label }}" 
       id: "{{ .ID }}"   

See more: https://yaml-multiline.info/

@woody4165
Copy link
Author

woody4165 commented Nov 3, 2024

Thanks @freefd

Strangely was working, not all the times maybe.
Now I've placed the pipe after the template: and I will check it asap

@woody4165
Copy link
Author

woody4165 commented Nov 3, 2024

@freefd
After adding the pipe I get this error while loading the config

Failed to load config from file! error="1 error(s) decoding:\n\n* 'alerts.webhook.template' expected a map, got 'string'"

I've also placed correctly the indentation

    template: |
      camera: "{{ .Camera }}"
      label: "{{ .Label }}"
      id: "{{ .ID }}"

If I remove the pipe, the config loads correctly and I get the proper webhook in nodered

@freefd
Copy link
Contributor

freefd commented Nov 3, 2024

'alerts.webhook.template' expected a map, got 'string'"

And now we need to summon @0x2142 here.

@0x2142
Copy link
Owner

0x2142 commented Nov 4, 2024

Hi,
So for the moment, there are two ways of configuring a custom webhook payload via template.

The first is what you've already tried - which is providing a mapping of key / value pairs:

    template: 
      camera: "{{ .Camera }}"

Which then generates a message like:

{ "camera": "test_cam" }

Alternatively, you can enter a full JSON string, but at the moment it must be on one line:

    template:  { "camera": "{{ .Camera }}" }

Which would generate the same payload as above.

Looks like because of the way I've implemented this, the typical YAML multiline string input isn't working - so I'll have to figure out a way to address that. I should also update the docs to add more info about this one, since it's a bit different than the other notification providers.

@woody4165
Copy link
Author

Ok, thanks @0x2142

So, my configutation, that is lile the first one, is correct

My issue, I don't know if is an issue, is the warning messages that I always get that are like

2024/11/04 19:18:02 +0100 WRN util/httpclient.go:192 > HTTP Request failed, retrying in 10 seconds... error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" attempt=4 max_tries=6
2024/11/04 19:18:03 +0100 WRN util/httpclient.go:192 > HTTP Request failed, retrying in 10 seconds... error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" attempt=5 max_tries=6
2024/11/04 19:18:04 +0100 WRN util/httpclient.go:185 > HTTP Request failed, retries exceeded error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" attempt=6 max_tries=6
2024/11/04 19:18:04 +0100 WRN notifier/webhook.go:53 > Unable to send alert error="Post \"http://192.168.1.160:1880/webhook-frigate\": http: ContentLength=70 with Body length 0" event_id=1730744265.934368-b50rn7 provider=Webhook

They are just warning or should I worry about?

@0x2142
Copy link
Owner

0x2142 commented Nov 4, 2024

Hi @woody4165 - So, there are two things going on here...

First, I tried spinning up a node red instance to see if I can replicate this - and sure enough it was pretty easy. I've never used node red before, so I added an "http in" for the incoming webhook, then some logic after to forward the request elsewhere. It looks like with this config, node red never responds to frigate-notify - so the app sits there until the request times out, which then initiates he retry errors you're seeing.

In order to fix this, I needed to add a "http response" with a status code of 200. Seems like without this, node red never responds with a status code - so the connection just hangs and times out.

Here's what my quick flow looks like:

image

So perhaps this might be your issue as well? If so, you should just need to add a response to the initial inbound webhook from frigate-notify.

Second - the warnings you are getting are in fact a bug in the HTTP retry logic. I'll get this resolved in the next release.

@freefd
Copy link
Contributor

freefd commented Nov 4, 2024

ContentLength=66 with Body length 0

@0x2142 I'm more worried about this one ^^^

@woody4165 can you please run your Frigate-notify instance in the trace logging mode (https://frigate-notify.0x2142.com/latest/config/options/) and provide more logs about the request?
Based on your configuration this code will be invoked: https://github.com/0x2142/frigate-notify/blob/main/notifier/webhook.go#L45
And thus the entire request will be logged by https://github.com/0x2142/frigate-notify/blob/main/util/httpclient.go#L158-L163 lines.

@0x2142
Copy link
Owner

0x2142 commented Nov 4, 2024

@freefd Yeah that's the issue I found. I'm not handling the request body properly in the retry, so once that first request is sent, subsequent retries are actually sending an empty body. I have a fix already in my current local branch & it will be out in the dev branch for you soon 😊

@freefd
Copy link
Contributor

freefd commented Nov 4, 2024

@0x2142, oh... got the problem. @woody4165, please ignore my request about the trace log level.

@woody4165
Copy link
Author

woody4165 commented Nov 5, 2024

So perhaps this might be your issue as well? If so, you should just need to add a response to the initial inbound webhook from frigate-notify.

Thanks @0x2142
I've just added an http response node with 200 and I'll check with next motion

My flow does not include http request node, since I get the data sent from the webhook directly from http in node

@freefd thanks for your suggestion, I'll wait for your fix

@woody4165
Copy link
Author

@0x2142 , @freefd It seems that all the webhook warnings are gone
So I've just added the http response node with 200 as value

Thanks !

@woody4165
Copy link
Author

Just one more question, not related to webhook, in case it's needed I'll open a new issue

Some times, most of the times, I get two telegram message for same event, one without the event clips link, one with.
The sent snapshots are almost the same, maybe some frame later the second message.
Is it possible to avoid the message without the clip?

Screenshot_20241105-131641

@freefd
Copy link
Contributor

freefd commented Nov 5, 2024

@woody4165 I wrote the message about this behavior but finally decided to ask you to create a new issue so as not to mix topics, please.

@woody4165
Copy link
Author

Hi @freefd

let me know if I can close this issue, since now it seems that everything is ok

@freefd
Copy link
Contributor

freefd commented Nov 5, 2024

@woody4165, perhaps @0x2142 might want to make some commits with this issue as the ref, and close it after fixing, idk.

@0x2142
Copy link
Owner

0x2142 commented Nov 5, 2024

I fixed the issue here and forgot to add a reference. But as far as I'm concerned, feel free to close it if you like - and thanks for reporting the issue!

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

No branches or pull requests

3 participants