djdd87 / SynoAI

A Synology Surveillance Station notification system utilising DeepStack AI
GNU General Public License v3.0
209 stars 24 forks source link

webhook not working #185

Closed phui123 closed 1 year ago

phui123 commented 1 year ago

First of all, thanks a lot for such a great project. I installed both Deepstack and Synoai into docker and work successfully. Image is captured and analysed and can return telegram successfully. What I'm trying to do is to add another notifier, trigger SSS to start recording once synoai recognize a "person"

I set up webhook in action rules of SSS to trigger it, the url as follow: https://192.168.100.101:5008/webapi/entry.cgi?api=SYNO.SurveillanceStation.Webhook&method="Incoming"&version=1&token=tXdY4Z9C6CDQEuVgQ1DNl0ti2EsaDMn3WYVAn2Fg0t2MDckzbBEL8BWfx120yPkb

and I add notifier in appsettings.json as follow: "Notifiers": [ { "Type":"Webhook", "URL":"https://192.168.100.101:5008/webapi/entry.cgi?api=SYNO.SurveillanceStation.Webhook&method=Incoming&version=1&token=SCgasJbyxdn0us736Ra4goc4PNofpkTDx7D3beXer4T2TvRYoDChHP89yp9BjP01", "Device": ["Livingroom"] },

but once "person" is identified, I got the following errors in synoai docker log:

Unhandled exception. System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken) at SynoAI.Notifiers.Webhook.Webhook.SendAsync(Camera camera, Notification notification, ILogger logger) in /src/Notifiers/Webhook/Webhook.cs:line 128 at SynoAI.Controllers.CameraController.SendNotifications(Camera camera, Notification notification) in /src/Controllers/CameraController.cs:line 447 at SynoAI.Controllers.CameraController.Get(String id) in /src/Controllers/CameraController.cs:line 211 at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_1(Object state) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action1 callback, TState& state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() `

Any idea how to solve? Thanks. Pat

djdd87 commented 1 year ago

The error is due to your SSL setup. Set AllowInsecureUrl to false in your config as per the readme.

Let me know if you have any other issues.

phui123 commented 1 year ago

Thanks for the reply. I try add the following in appsettings.json:

"AllowInsecureUrl":"false",

But seems like the same error occur

I also try "AllowInsecureUrl":"true" but no luck

Not sure what I should do next .........

djdd87 commented 1 year ago

Try:

"AllowInsecureUrl": true

No quotes needed as it's a boolean. Also make sure you restart the app after changing the config values.

phui123 commented 1 year ago

Thanks for reply. But seems same result no matter I put "AllowInsecureUrl": true or "AllowInsecureUrl": false FYI: I start a new container in portainer for synoai everytime I change the value already

djdd87 commented 1 year ago

OK, I think I see why. The AllowInsecureUrl property is just for the connection to SSS for the snapshots. I need to add the same config for the Webhook notification itself.

phui123 commented 1 year ago

Thank you !!!!! Let me know if you have any solution or need me to help in testing anything. Thanks.

djdd87 commented 1 year ago

Pull latest and this should now work if you set AllowInsecureUrl against your Webhook notification (not the top level config).

Implemented in 1.2.2.

phui123 commented 1 year ago

Try pull the latest and test. Seems all error message gone, but the recording webhook doesn't triggered. Verified he webhook URL via google chrome and it work :(

djdd87 commented 1 year ago

I'm guessing you've setup your Webhook notification incorrectly then. The default method is "POST" and if you're verifying it by opening a URL Chrome and it works, then you should be using "GET".

{ "Type":"Webhook", "URL":"https://192.168.100.101:5008/webapi/entry.cgi?api=SYNO.SurveillanceStation.Webhook&method=Incoming&version=1&token=SCgasJbyxdn0us736Ra4goc4PNofpkTDx7D3beXer4T2TvRYoDChHP89yp9BjP01", "Device": ["Livingroom"] },

No method is specified, therefor it uses the default. Please see the docs.

image

phui123 commented 1 year ago

By changing the Method to "GET", the recording action rule can be triggered successfully. But another strange behaviour occur, I have 4 recording action rules with different webhook token respectively, but once anyone of them triggered, all are triggered and so all 4 cam will start recording once any cam detect any "person".

I think I have found the problem, it should be "Cameras" instead of "device" in webhook notifier. Everything works now.

Thanks again for the great work !!!

djdd87 commented 1 year ago

Then you've done something wrong with your configuration.