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

Custom notificator implementation example (Pushbullet/JoinPushover etc) #4497

Closed
markcs opened this issue Mar 10, 2020 · 0 comments
Closed

Comments

@markcs
Copy link

markcs commented Mar 10, 2020

This is not a bug or feature request, but more of a how-to.

I wanted to be able to send push notifications without compiling my own apps and wasn't really interested in receiving email notifications (too many emails already!). I already use Join on Android and have used Pushover and Pushbullet in the past, so thought I could use these.

I did this by defining a local email address which will receive Traccar notifications and then use procmail and a custom script to send the notification. I use Debian, but I assume this should work on any system that supports procmail.

  1. Define a local email address (traccar@localhost.localdomain) using the guide here: https://gist.github.com/raelgc/6031274 up to step 4

  2. In Traccar, create a user with that local email address and share the devices and geofences with that user OR change the email address of an existing user to the local email address

  3. Change the smtp server details in Traccer config or user attributes

<entry key='mail.smtp.host'>localhost</entry>
<entry key='mail.smtp.from'>traccar</entry>
<entry key='mail.smtp.auth'>false</entry>
  1. In Traccar, the notification type for events should be email.
  2. Install procmail (sudo apt-get install procmail mailutils)
  3. Create .forward file echo "|/usr/bin/procmail" > $HOME/.forward
  4. Create .procmailrc file in users home directory
# .procmailrc
# routes incoming mail to appropriate mailboxes
PATH=/usr/sbin:/usr/bin
MAILDIR=$HOME/mail

:0b:
* ^From:.*(traccar@localhost.localdomain)
| /opt/traccar/traccar_notifications.pl
  1. The file traccar_notifications.pl will be the script that will push the notification. I know that Pushbullet (https://docs.pushbullet.com/) and Pushover (https://pushover.net/api) have simple API's that can be used. This example is for Join (on Android).

Create the /opt/traccar/traccar_notifications.pl file

#!/usr/bin/perl
use LWP;
my $line = "";
while (<>) {
   $line = $line.$_;
}

my $join = LWP::UserAgent->new();
my %parameters = 
(
     "apikey" => "joinapikey",
     "deviceNames" => "join.device",
     "deviceId" => "join.deviceid",
     "title" => "Traccar",
     "icon" => "https://www.traccar.org/icon.png",
     "text" => $line,
);
my $url = URI->new("https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush");
$url->query_form(%parameters);
$join->get($url);
  1. chmod 755 /opt/traccar/traccar_notifications.pl

  2. Test notifications by executing the following command. Assuming you get a notification on your phone, continue. Otherwise, check the traccar_notifications.pl script.
    echo Test Notification | /opt/traccar/traccar_notifications.pl

  3. Change the Traccar templates so only simple text is sent.

mv /opt/traccar/templates/full /opt/traccar/templates/full-original
cp -r /opt/traccar/templates/short /opt/traccar/templates/full
  1. Restart Traccar and try to send a test notification
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

2 participants