NSLU2-Linux
view · edit · print · history

HowTo.MakeSlugUseNailToSendAlerts History

Hide minor edits - Show changes to markup

March 02, 2007, at 10:00 AM by Lars Persson Fink -- change from-root... in .mailrc to from=root...
Changed line 14 from:

set from-root@<my.dommainname.com>@@

to:

set from=root@<my.dommainname.com>@@

October 08, 2006, at 04:35 PM by Nathan -- smtpclient is in /usr/sbin
Changed lines 31-32 from:

/usr/bin/smtpclient -s <subject> -f admin@<IP of slug> <to_address>

to:

/usr/sbin/smtpclient -s <subject> -f admin@<IP of slug> <to_address>

February 14, 2006, at 07:15 PM by Nathan --
Changed line 15 from:
  1. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper. I didn't want to store my wrapper script in the original location for first time I did that I forgot about it and my script got wiped out when I upgraded from Unslung 3.18 to 5.5. Script is listed below.
to:
  1. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/local/bin/nail_wrapper. I didn't want to store my wrapper script in the original location for first time I did that I forgot about it and my script got wiped out when I upgraded from Unslung 3.18 to 5.5. Script is listed below.
Changed lines 19-22 from:

ln -s /opt/bin/nail_wrapper /usr/sbin/smtpclient

/opt/bin/nail_wrapper script:

to:

ln -s /opt/local/bin/nail_wrapper /usr/sbin/smtpclient

You can test the new mechanism by calling set_log. E.g:

/usr/sbin/set_log backup 0 1

This will send you a bogus email alert about a backup failure. The "backup" keyword is the name of a stanza in /etc/cgi_msg. The last number, 1, is an index to the actual error message in the backup stanza. The second number, 0, tells set_log to send an email rather than just log a message in /var/log/server.log. If it were a 1, no email would be sent. Try man set_log for a few more details.

/opt/local/bin/nail_wrapper script:

February 14, 2006, at 06:56 PM by Nathan --
Changed lines 31-32 from:

The script logs what it does to /var/log/mail_alert.log. You can take this out if you don't like it. Also, because I was lazy and used getopts, the script requires bash to be installed.

to:

The script logs what it does to /var/log/mail_alert.log. You can take this out if you don't like it. Also, because I was lazy and used getopts, the script requires bash to be installed. Also, make sure the script has execute permissions. Mine is 755 owned by root.

February 14, 2006, at 06:54 PM by Nathan --
Changed lines 23-29 from:
 #!/bin/sh
 # bleah
 subject=$1
 /opt/bin/nail -s $subject
to:

This script needs to translate the arguments liblog.so provides to smtpclient to those appropriate for nail. liblog.so calls smtpclient like this, sending the text of the email on standard input:

/usr/bin/smtpclient -s <subject> -f admin@<IP of slug> <to_address>

where <subject> and <to_address> are provided in the NSLU2 Admin webpage. With this script I am basically throwing away the -f argument, which does something different with nail. E.g:

/opt/bin/nail -s <subject> <to_address>

The script logs what it does to /var/log/mail_alert.log. You can take this out if you don't like it. Also, because I was lazy and used getopts, the script requires bash to be installed.

I would appreciate any feedback if this Howto is useful to you. Enjoy!


#!/bin/bash

log_file=/var/log/mail_alert.log

while getopts s:f: arg; do
  case $arg in
    s) subject="$OPTARG";;
    f) from_addr="$OPTARG";;
    ?) echo "Syntax error"
       exit 1;;
  esac
done
shift $(($OPTIND - 1))
to_addr="$*"

date >> $log_file
echo "Subject: $subject" >> $log_file
echo "From: $from_addr" >> $log_file
echo "To: $to_addr" >> $log_file

cat - | tee -a $log_file | /opt/bin/nail -s "$subject" "$to_addr"
February 14, 2006, at 05:46 PM by nellswor -- How to make Slug use nail to send alerts in case your IP address is blocked
Changed lines 1-6 from:

Most sendmail servers block email sent by the standard NSLU2 smtpclient on my Slug because it appears Comcast-issued IP addresses are blocked in SPEWS. So to get around this I needed a way to have smtpclient use the Comcast smtp server to relay mail. I couldn't find a way to make the built-in smtpclient use a relay but nail, an available ipkg package, can. Here are the steps:

  1. Install nail: ipkg install nail
  2. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper. Script is listed below.
  3. Rename the original smtpclient program: mv /usr/sbin/smtpclient /usr/sbin/smtpclient.orig
  4. Create a symbolic link pointing to the new script: ln -s /opt/bin/nail_wrapper /usr/sbin/smtpclient
to:

You can configure the Slug to send you email alerts when bad things happen, like failed backups and full disks. This is done through the Admin webpage and you can specify the destination email address and the subject line of the email. However, I have never gotten my Slug to send me email with via the normal mechanisms. This is the alert process as I've gleaned from doing strings on various binaries and libraries:

  1. A script which wants to issue an email alert calls /usr/sbin/set_log
  2. set_log calls some library routine in /lib/liblog.so
  3. This library routine calls /usr/sbin/smtpclient which is a binary SMTP mail client.

The sendmail server at my ISP blocks email sent by the standard NSLU2 smtpclient on my Slug because it appears Comcast-issued IP addresses are spam black-listed. If the Linksys-provided smtpclient could be instructed to use a mail relay (Comcast provides one) it shouldn't be blocked as spam, but unfortunately the -S argument of smtpclient, to specify a mail relay host, is not supported. However, nail, an available ipkg package, does support mail relays. Here are the steps to use nail instead of the Linksys-provided smtpclient to send alerts:

  1. Install nail (I got these steps from Nail)
    ipkg install nail
  2. Create a .mailrc for root in /root/.mailrc (or where ever your root's homedir is) containing
    set smtp=smtp.comcast.net
    set from-root@<my.dommainname.com>
  3. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper. I didn't want to store my wrapper script in the original location for first time I did that I forgot about it and my script got wiped out when I upgraded from Unslung 3.18 to 5.5. Script is listed below.
  4. Rename the original smtpclient program
    mv /usr/sbin/smtpclient /usr/sbin/smtpclient.orig
  5. Create a symbolic link pointing to the new script
    ln -s /opt/bin/nail_wrapper /usr/sbin/smtpclient

/opt/bin/nail_wrapper script:

 #!/bin/sh
 # bleah
 subject=$1
 /opt/bin/nail -s $subject
February 14, 2006, at 05:07 PM by nellswor -- How to make Slug use nail to send alerts in case your IP address is blocked
Changed lines 3-8 from:
  1. Install nail

ipkg install nail

  1. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper.

@@

  1. !/bin/sh

@@

to:
  1. Install nail: ipkg install nail
  2. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper. Script is listed below.
  3. Rename the original smtpclient program: mv /usr/sbin/smtpclient /usr/sbin/smtpclient.orig
  4. Create a symbolic link pointing to the new script: ln -s /opt/bin/nail_wrapper /usr/sbin/smtpclient
February 14, 2006, at 04:56 PM by nellswor -- How to make Slug use nail to send alerts in case your IP address is blocked
Changed line 4 from:

typewriteripkg install nail

to:

ipkg install nail

Changed line 6 from:

typewriter

to:

@@

Added line 8:

@@

February 14, 2006, at 04:55 PM by nellswor -- How to make Slug use nail to send alerts in case your IP address is blocked
Added lines 1-7:

Most sendmail servers block email sent by the standard NSLU2 smtpclient on my Slug because it appears Comcast-issued IP addresses are blocked in SPEWS. So to get around this I needed a way to have smtpclient use the Comcast smtp server to relay mail. I couldn't find a way to make the built-in smtpclient use a relay but nail, an available ipkg package, can. Here are the steps:

  1. Install nail

typewriteripkg install nail

  1. Create wrapper script for nail which translates smtpclient parameters to nail parameters and passes along whatever comes through stdin. I store this script in /opt/bin/nail_wrapper.

typewriter

  1. !/bin/sh
view · edit · print · history · Last edited by Lars Persson Fink.
Based on work by Nathan and nellswor.
Originally by nellswor.
Page last modified on March 02, 2007, at 10:00 AM