Forward events to PHP application

f1cscari3 years ago

Can someone give me some hands and hints how to set Neo's script up?
i have gotify localy on my traccar server installed, but can't find out where to put this script and how to set it up.

Actually, i have it for testing in the traccar root folder and get in the logs

WARN: Event forwarding failed - MessageBodyReader not found for media type=application/octet-stream, type=class java.lang.Object,... 
f1cscari3 years ago

After 200 and 1 Tests, google searches, back and forward with or without quotes or semicolons here and there, this is the closest variant.... but it is not working.

</entry>
<entry key='event.forward.enable'>true</entry>
    <entry key='event.forward.url'>http://localhost:90/message?token=myApptokenYXZ</entry>
    <entry key='event.forward.header'>content-type: application/json, authorization: Basic myApptokenYXZ, message: my message, priority: 5, title: my title</entry>

Result:

Traccar Server-Log: WARN: Event forwarding failed - HTTP 400 Bad Request - BadRequestException (...)
Gotify-Log: 1.4718ms |       127.0.0.1 | POST     "/message?token=[masked]"
f1cscari3 years ago
<entry key='event.forward.enable'>true</entry>
    <entry key='event.forward.url'>http://localhost:90/message?token=myApptokenYXZ</entry>
    <entry key='event.forward.header'>"content-type: application/json; charset=utf-8",
    "title:" "Hello World",
    "message:" "Test push",
    "priority:" 5</entry>

According to Gotify Source: https://gotify.net/docs/more-pushmsg

This variant shows in the Traccar-Log: Event forwarding failed - Connection reset - SocketException (...)
The Header seems now correct? This issue was also here discussed - https://www.traccar.org/forums/topic/event-forwarding-throws-error/
Issue solved by "Ok i tried it completely without the header lines and now it works." - deleting it...

f1cscari3 years ago
    <entry key='event.forward.url'>http://localhost:90/message?token=MyApptomenXYZ</entry>
    <entry key='event.forward.header'>
        content-type: application/json,
        title: "Hello World",
        message: "Test push",
        priority: 5
    </entry>

According from macphisto Help in this thread - https://www.traccar.org/forums/topic/event-forward-enable-event-forward-url/page/2/

Result:

error - Index 1 out of bounds for length 1 - ArrayIndexOutOfBoundsException (EventForwarder:61 < NotificationManager:119 < *:125 < BaseEventHandler:31 < ...)

i tried with comas and without, i tried also with quotes, no luck. I use Traccar to not feed further the google data-octopus. I am rly baffled Traccar is not working with gotify - every event Traccar records goes to google, as soon forwarding is enabled, else, notification would not work. Any suggestions?

Anton Tananaev3 years ago

What you are trying to do doesn't look right to me. Why is data (title, message etc) part of headers? It should not be in headers according to the Gotify documentation, as far as I can tell.

f1cscari3 years ago

It seems, i am with this issue (gotify/traccar) a complete pioneer, there is no further Information on the web explaining how to solve this. Neo´s PHP Script does also not work - see first post from me here - https://www.traccar.org/forums/topic/forward-events-to-php-application/page/2/#post-65940

For example this works:

<entry key='sms.http.template'>
    {
        "to": "{phone}",
        "message": "{message}"
    }

Is there something like a 'event.http.template' ? Or how do i solve this header/data push&POST for gotify in Traccar?
see here - https://www.domoticz.com/forum/viewtopic.php?t=32528

Anton Tananaev3 years ago

There's no template for event forwarding. It's a fixed JSON format. If you want to change it, you either have to change the code or have some external script that converts Traccar JSON format to whatever you need. The latter is what most people do.

f1cscari3 years ago

Thanks for clarifying this. So i went back trying Neo´s Script, the latter option cause i am either a scripter nor a programmer.
event.forward.url does not work, so i test forward.url

    <entry key='forward.enable'>true</entry>
    <entry key='forward.url'>http://localhost:8082/teste.php</entry>
    <entry key='forward.json'>true</entry>

No datas, no entrys in the traccar server log. only thin air. same like these two:
https://www.traccar.org/forums/topic/forwardurl-does-not-send-data/
https://www.traccar.org/forums/topic/warn-position-forwarding-failed-0-pending/

It seems i can drop this notifying feature/wish, the forum is full of unsolved requests about this problem for years.
Best answer was - https://www.traccar.org/forums/topic/warn-position-forwarding-failed-0-pending/#post-53924
"It probably means that there was an error." :D

Anton Tananaev3 years ago

A lot of things have changed since the threads you are referring to. For example, error messages should now include original network errors.

In general forum threads have a survival bias. Only people who can't get it working post here. I can tell you that forwarding works for majority of people we work with.

f1cscari3 years ago

Holy cow.... i cant take it... after 40 hours and more, i went back to the very early basics and now its working!!!!!
The only thing i changed is disabling

<entry key='notificator.traccar.key'>eyJkYXRhdfsgdsfgdsfgsdfgdsfhgdshfdghdfghfdghfgdhfdghfdghfsdafsdafdfggfdhdsfg</entry>

...and started from scratch with -

<entry key='event.forward.url'>http://localhost:90/message?token=myApptokenYXZ</entry>

unbelievable.... its working...

f1cscari3 years ago

Yes Anton, it would be more helpful, if these Users gave feedbacks how they solve their problems, sharing is caring ;)

f1cscari3 years ago

Ahhh, nooo my sorry.... it was the SMS client which i enabled again and they look very similar... (delete my misguiding happy post) i still have:

WARN: Position forwarding failed: 0 pending - Status code 2xx expected - RuntimeException (WebDataHandler:261 < *:186 < ...)
Anton Tananaev3 years ago

Seems like the service you are forwarding to is returning an error.

f1cscari3 years ago

Yes - i am to long on this problem, overtired - i start doing mistakes so i settle it till someone can help, maybe here -
https://github.com/gotify/server/issues/444

f1cscari3 years ago

Neo gave me a Hand for hes script - see https://github.com/neo7530/traccar_pusher/issues/1
Now i am stuck with the Warning

WARN: Event forwarding failed - MessageBodyReader not found for media type=text/html;charset=utf-8, type=class java.lang.Object, genericType=class java.lang.Object. - MessageBodyProviderNotFoundException (...)

My Server Log shows at start

2021-10-25 03:16:36  INFO: Character encoding: Cp1252 charset: windows-1252
2021-10-25 03:16:36  INFO: Version: 4.13
2021-10-25 03:16:36  INFO: Starting server...

It hangs now with the charset. Enforcing Traccar using:

<entry key='event.forward.header'>Content-Type: application/json; charset=windows-1252</entry>

does not help...