Buffalo Quad Pro – Nailing a New Email Notification Feature

The Buffalo Quad Pro has a built-in email notification feature and is capable of sending a NAS “hdd status” report at a pre-determined time…but I am sure all the users already know this. While I find this feature extremely useful, I am not too happy with the way the email is formatted, not to mention that it is not possible to include extra bit of system information regarding the NAS as part of the email. It is also not possible to use the built-in email notification to send automated message when say, an rsync backup is successfully done. There is just no way we can customize the built-in email notification feature.

Having said this, it is actually rather easy for us to roll our own email notification feature. We will just need 1 little program to do the job. Enter Nail – the superb console based email client. We do not need a GUI based email client to further complicate the matter. A command line email client is good enough in this case.

There are of course many other command line based email clients. Notable mention goes to mutt, pine, etc.But I chose nail for the simplicity it gives me. You should obviously use whatever suits you best.

Here are some good references about Nail. A must read in my opinion:

  1. Optware: http://forum.synology.com/wiki/index.php/A_short_list_of_the_more_useful_900%2B_ipkg_packages
  2. And here is the man page. http://linux.die.net/man/1/mail
  3. Setting up nail with ubuntu: http://klenwell.com/press/2009/03/ubuntu-email-with-nail/
  4. A good forum thread about Nail: http://ubuntuforums.org/showthread.php?t=780509

There are plenty more good info on the net. Google is your friend here.

Installing nail is really simple.

# ipkg install nail

The next step is to configuring Nail. This is also very simple.

# cd /opt/etc

# nano nail.rc

Append the “set hold” line with the # character; This will effectively make this line a comment. Like so:

The next thing to do is to add the following lines to the end of the file. My setup is relevant to setting up a gmail account. I am not sure what are the settings for the other email service providers. My settings may not be the most secure so if you are paranoid, you can fine tune this with a SSL certificate for instance. I wouldn’t bother usually.

$ Setting up Gmail
set smtp-use-starttls
set from=Jean-Luc_Picard@gmail.com
set smtp=smtp.gmail.com:587
set smtp-auth-user=Jean-Luc_Picard
set auth-login=Jean-Luc_Picard
set ssl-verify=ignore
set smtp-auth-password=12345678

Save the file and exit back to the console.

Create a dummy text file using nano. Put something simple in this text file like “This is the Captain speaking” or whatever. Something that amuses you perhaps. Name this textfile as “testmail” but anything will do here. Ignore the quotation marks of course.

Now we can test the email system.

# nail -V -s “Test Message” william.riker@gmail.com < testmail

The -V parameter allow us to see what nail is doing in the background and is helpful for troubleshooting.

Of course use whatever “real” email address in your testing. If the email setting is working, this will generate something like this:

If the setting is working, we will also get a new email message in the recipient account.

This is pretty much it! Plain simplicity.

Now that the email system is working, what can we do with it? Well, I use the system to do a couple of things:

1. Email notification when rsync has completed.

My Rsync backup script automatically generates a log file each time it is run. It is handy to be able to look at this log file in the morning to see if all the files are copied correctly (just in case for whatever reasons the backup of certain files are just not working). I can of course login into the NAS manually, and read the log file by navigating to the right directory. But looking at a log file is an extremely dry exercise; plus I am lazy. I want the log file to be pushed to my email automatically. I may or may not want to actually read the log file but I have the option of doing so. I will touch more on this section in a future blog entry.

2. Email notification to replace the original system – A more comprehensive status report.

As mentioned earlier, the linkstation is capable of delivering a hdd status report at a pre-determined time. This is all good but the functionality is very limited. I have been wanting to roll my own email notification for sometime now and Nail just serve the purpose really nicely. To do this, some perl/bash scripting are required.

First off, I created the following perl script. This can be downloaded here. I name the script nasstatus but you can obviously call it whatever you want. Just make sure that it is chmod to 755.

Running this script in the linkstation will give an output similar to this.

I think this is a more comprehensive report as compared to the standard linkstation report that I am getting everyday. And the good thing is that I can tailor the output how ever way I wanted. Now so can you.

This is not finished yet. We now need to push this report to an email account. This is where I have to say Nail is failing short. Ideally I would like to deliver the report in html format. This gives me even greater flexibility as I can insert the data in tabular format, change the text font, etc. Unfortunately, Nail does not support html as it is.

I am happy to be proven wrong here so if there is a better way to do this, please let me know.

I can “attach” a html report as part of the email but that is NOT what I wanted to do. I wanted to deliver the actual email in html format. The only way I know that can do this is via other email client such as sendmail, mutt, etc BUT they are more complicated to setup (and I have better things to do than investigating this further) so I have come to the compromise of not using html report and revert to using plain text report only.

To push the above report to the email account, I created a bash script to do the job. This looks like this:

#!/bin/sh
#
# Nas Status Cron Script by Joseph Lo 2011
# for Buffalo Linkstation LS-QVL/R5 Quad Pro
# https://josephlo.wordpress.com
#
# statusreport.sh
# This cron script should be used in conjection with the nasstatus perl script.

#Email address of recipient. Adjust to suit.
Email="Jean-Luc_Picard@gmail.com";

#Current Date
day=`date | awk '{print $3}'`;
month=`date | awk '{print $2}'`
year=`date | awk '{print $6}'`
date=$day.$month.$year;
cd /opt/bin
nasstatus > /tmp/report
cat /tmp/report | nail -s "Buffalo Linkstation Status Report [$date]" $Email
exit

If you like, you can just use this as the template for your own script. Just make sure that it is also chmod to 755. I called this script statusreport.sh but you can name it to suit.

If this is setup exactly the way I did, running statusreport.sh will generate an error at the console. It looks like this:

I have no idea why this is giving me this error message but I did not spend too much time to research this further. I just ignore the error as it seems Nail is working just fine.

Now it is time to check the email. If everything goes well, the email will look something like this. This screenshot is from my gmail.

The last thing we need to do is to setup a cron script to do this automatically. This is a simple thing to do.

# cd /etc/cron/crontabs

# nano root

Add an entry like this to the end of the file. I have chosen to send the report at 12pm everyday. Adjust the time if you like.

00 12 * * * /opt/bin/statusreport.sh

Lastly, I disabled the hdd status report on the web admin. Note that I only disable the HDD Status Report function. Reports such as fan failures, disk errors, etc should be sent automatically from the linkstation and I have no desire to override the stock functionality.

This is all there is! I personally find that this is a much better email notification system than the stock standard version. I hope you will find this useful.


			

Posted on August 21, 2011, in Buffalo Quad Pro NAS. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: