Skip to content

Instantly share code, notes, and snippets.

@chetstone
Last active January 4, 2016 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetstone/8623265 to your computer and use it in GitHub Desktop.
Save chetstone/8623265 to your computer and use it in GitHub Desktop.
Forwarding Ubiquiti AirVision2 (linux) Motion Alerts based on regions
# Exim filter
# The first line above must be exactly like that.
#
# Since Airvision2 only has a provision to send email notifications for all regions or none,
# we add this kludge to forward emails based on the region name included in the email.
# Basic steps are these:
# 1. Install a mail server on your ubuntu/debian box if it's not there already. (Not as hard as it sounds.)
# 2. Configure it to forward nonlocal mail to a smarthost.
# 3. Add a user account to Airvision to send notifications to the admin account on the local host.
# 4. Install this file (.forward) in the admin account home directory. (Must be writeable only to the user.)
# 5. Test
# Detailed instructions.
# 1. Type "exim4" on the command line. If the command is there, go to the next step. If not, the OS will instruct you
# which apt-get command to run to get it. Get the "light" version of exim4.
# 2. If you're using a gmail smtp server for your smarthost, follow the instructions here to set it up:
# https://wiki.debian.org/GmailAndExim4 You should be able to easily adapt those instructions for hotmail/whatever.
# Since the exim filters only look at the first 500 characters of the mail by default, and the Airvision region
# name is buried quite deep in a large email, you need to modify the exim4 configuration.
# At the end of /etc/exim4/conf.d/main/02_exim4-config_options add the line:
# message_body_visible = 20000
#
# Then rerun the configuration update commands at the end of the GmailAndExim4 instructions.
#
# 3. Add a new Airvision user with the email address admin@localhost (or whatever your admin account login is)
# If you've already installed Airvision and the Super Administrator is a different email, don't try to
# change that email address. I did and I mistyped the new address and couldn't get back in. Had to
# completely purge my airvision installation and reinstall from scratch. Just play it safe and add a new
# airvision user.
# 4. Install this file as ~/.forward in your admin account and edit for what you want. Replace "Drivewayview"
# with the name of the region you want to forward to your email. And of course you put in your own email addresses.
# The "deliver" command just forwards the incoming email to the specified address. The "mail" command creates
# a new email. I use this to send a stripped-down version of the email with just the link to the video to
# the Prowl app on my iPhone. http://www.prowlapp.com/prowlmail.php
# More info on writing filters is here:
# http://www.exim.org/exim-html-current/doc/html/spec_html/filter_ch-exim_filter_files.html
# and here:
# http://www.exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html
#
# 5. Testing. You can test the filter without actually sending emails by creating a test message by saving an airvision
# email to a file and running the command:
# /usr/sbin/sendmail -bf .forward < test-message
#
# The code:
if $h_from contains "airvision"
then
if $message_body contains "Drivewayview"
then
mail to apikey@api.prowlapp.com subject "Aircam driveway motion" text ${sg{$message_body}{.*(http.*/player/.....).*}{\$1}}
# forward the original email to my main email address
deliver me@example.com
endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment