In case it's of use to any other users, I thought I'd describe some work I did to allow me to get a notification to my android phone whenever a user downloads from my freenas ftp
Prerequisites:
the android "notify my android" application on your phone
https://play.google.com/store/apps/details?id=com.usk.app.notifymyandroid
you'll need your notifymyandroid api key - youll find the key in the My Account page here https://www.notifymyandroid.com/account.jsp
Perl needs to be installed on your freenas. Personally I run a jail, install perl into the jail.
(if unsure how to install perl in your jail, start reading up on the ports collection, portsnap, and portmaster)
The ftp log folder needs to be visible to the jail , so (in freenas 9.1) under jails>view storage, I set up a new storage with source of /var/log and destination of /ftplogs , mounted=true
you'll need the notifymyandroid perl script "nma.pl" here https://www.notifymyandroid.com/files/nma.pl
this script can be used to send notifications of any sort you like from your freenas box to your android phone. I've so far set it up to do so for ftp downloads.
I wrote the below script to do this job, and I invoke it from my jail with
tail -f /ftplogs/xferlog | perl ftpnotifications.pl &
which leaves it running in the background.
There's probably a better way of ensuring it runs on system startup than the above. (etc/init.d?)
This script relies on the above mentioned nma.pl , and invokes it, so make sure the path to nma.pl is correct. also set your own api key inside the script for notifymyandroid
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw(basename);
my $api_key = "Foo";
while (my $line = <>)
{
chomp ($line);
if ($line =~ /\* c\z/)
{
my @fields = split(/\s+/, $line);
my $basename = basename($fields[8]);
$basename =~ tr/_/ /;
my $mega_bytes = int ($fields[7] / (1024*1024));
my $secs = $fields[5];
my $minutes = int($secs/60);
my $bit_rate =
($secs ? sprintf("%.2f", $mega_bytes * 8 / $secs) : "Inf");
system(
"./nma.pl",
"-apikey=$api_key",
"-application=FTP",
"-event=Successful User Download",
"-notification=User $fields[-5] has successfully downloaded $basename (${mega_bytes}MB in $minutes minutes - a real $bit_rate Mbps)",
);
}
}
Prerequisites:
the android "notify my android" application on your phone
https://play.google.com/store/apps/details?id=com.usk.app.notifymyandroid
you'll need your notifymyandroid api key - youll find the key in the My Account page here https://www.notifymyandroid.com/account.jsp
Perl needs to be installed on your freenas. Personally I run a jail, install perl into the jail.
(if unsure how to install perl in your jail, start reading up on the ports collection, portsnap, and portmaster)
The ftp log folder needs to be visible to the jail , so (in freenas 9.1) under jails>view storage, I set up a new storage with source of /var/log and destination of /ftplogs , mounted=true
you'll need the notifymyandroid perl script "nma.pl" here https://www.notifymyandroid.com/files/nma.pl
this script can be used to send notifications of any sort you like from your freenas box to your android phone. I've so far set it up to do so for ftp downloads.
I wrote the below script to do this job, and I invoke it from my jail with
tail -f /ftplogs/xferlog | perl ftpnotifications.pl &
which leaves it running in the background.
There's probably a better way of ensuring it runs on system startup than the above. (etc/init.d?)
This script relies on the above mentioned nma.pl , and invokes it, so make sure the path to nma.pl is correct. also set your own api key inside the script for notifymyandroid
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw(basename);
my $api_key = "Foo";
while (my $line = <>)
{
chomp ($line);
if ($line =~ /\* c\z/)
{
my @fields = split(/\s+/, $line);
my $basename = basename($fields[8]);
$basename =~ tr/_/ /;
my $mega_bytes = int ($fields[7] / (1024*1024));
my $secs = $fields[5];
my $minutes = int($secs/60);
my $bit_rate =
($secs ? sprintf("%.2f", $mega_bytes * 8 / $secs) : "Inf");
system(
"./nma.pl",
"-apikey=$api_key",
"-application=FTP",
"-event=Successful User Download",
"-notification=User $fields[-5] has successfully downloaded $basename (${mega_bytes}MB in $minutes minutes - a real $bit_rate Mbps)",
);
}
}