Koozali.org: home of the SME Server

How do I have nut send me an email?

Offline dtech

  • **
  • 70
  • +0/-0
How do I have nut send me an email?
« on: December 31, 2006, 10:58:29 PM »
Hi All;

I have a remote SME7 server set up with nut and an APC UPS, and it works well; the power goes off, SME shuts down nicely. The problem is that it doesn't come back on when the power comes back on. I'd like to have the server send me an email so I know when this has happened. Of course it won't do to have an email sent to root, since webmail won't be available to me if the server is off. So, I was thinking a little mail command shooting an email out to my gmail account in the shutdown script would do the trick. I'mjust not sure where the shutdown script is, or if this is the right way to go about it. Any advice?

Thanks,

-P

Offline gordonr

  • *
  • 646
  • +0/-0
    • http://www.smeserver.com.au/
Re: How do I have nut send me an email?
« Reply #1 on: December 31, 2006, 11:42:24 PM »
Quote from: "dtech"
Hi All;

I have a remote SME7 server set up with nut and an APC UPS, and it works well; the power goes off, SME shuts down nicely. The problem is that it doesn't come back on when the power comes back on. I'd like to have the server send me an email so I know when this has happened. Of course it won't do to have an email sent to root, since webmail won't be available to me if the server is off. So, I was thinking a little mail command shooting an email out to my gmail account in the shutdown script would do the trick. I'mjust not sure where the shutdown script is, or if this is the right way to go about it. Any advice?

Thanks,

-P

The simple solution is to also forward admin mail to your external account, but that may not be what you want to do.

A script in /etc/e-smith/events/halt should do it.

Please also raise a New Feature Request in SME Server Future. I think the idea of having an "AlternateEmail" property to notify is a good idea.
............

Offline christian

  • *
  • 369
  • +0/-0
    • http://www.szpilfogel.com
How do I have nut send me an email?
« Reply #2 on: December 31, 2006, 11:42:39 PM »
It should be just a matter of modifying the following file (assume it is similar to R6.x structure):

/sbin/e-smith/nutUPS.notify

to include the commands you want. For example, mine looks like this:

Quote

#! /bin/sh
# UPS notify script. This is a placeholder.

/bin/mail -s "$*" admin < /dev/null
/bin/mail -s "$*" mobile < /dev/null


where admin and mobile are defined users.

Also verify that
/etc/e-smith/templates/etc/ups/upsmon.conf/NOTIFYFLAG
looks like this (I can't remember if it was modified; I suspect it wasn't):
Quote
{
# --------------------------------------------------------------------------
# NOTIFYFLAG - change behavior of upsmon when NOTIFY events occur
#
# By default, upsmon sends walls (global messages to all logged in users)
# and writes to the syslog when things happen.  You can change this.
#
# NOTIFYFLAG <notify type> <flag>[+<flag>][+<flag>] ...
#
# NOTIFYFLAG ONLINE SYSLOG
# NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
#
# Possible values for the flags:
#
# SYSLOG - Write the message in the syslog
# WALL   - Write the message to all users on the system
# EXEC   - Execute NOTIFYCMD (see above) with the message
# IGNORE - Don't do anything
#
# If you use IGNORE, don't use any other flags on the same line.
    my %def_action = (
        ONLINE => "SYSLOG+EXEC",
        ONBATT => "SYSLOG+EXEC",
        LOWBATT => "SYSLOG+EXEC",
        FSD => "SYSLOG+EXEC",
        COMMOK => "SYSLOG+EXEC",
        COMMBAD => "SYSLOG+EXEC",
        SHUTDOWN => "SYSLOG+EXEC",
        REPLBATT => "SYSLOG+EXEC",
        NOCOMM => "SYSLOG+EXEC",
    );
    foreach my $event (keys %def_action)
    {
        my $flag = ucfirst lc $event;
        $flag .= "Flag";
        my $action = $nut{$flag} || $def_action{$event};
        $OUT .= "NOTIFYFLAG $event $action\n";
    }
}
SME since 2003

Offline gordonr

  • *
  • 646
  • +0/-0
    • http://www.smeserver.com.au/
How do I have nut send me an email?
« Reply #3 on: December 31, 2006, 11:46:32 PM »
Quote from: "christian"
It should be just a matter of modifying the following file (assume it is similar to R6.x structure):

/sbin/e-smith/nutUPS.notify

No, please don't.

That file will be overwritten next time the e-smith-nutUPS package is upgraded (for example right now, when the 7.1 packages hit the mirror sites).

The correct fix is to raise a New Feature Request so that this sensible change gets into a later release.

Quote from: "christian"

Also verify that
/etc/e-smith/templates/etc/ups/upsmon.conf/NOTIFYFLAG
looks like this (I can't remember if it was modified; I suspect it wasn't):


And please don't edit templates. They too will be overwritten on upgrades. See the developers guide section on custom templates. You can also run /sbin/e-smith/audittoosl/templates to tell you if templates have been modified.
............

Offline christian

  • *
  • 369
  • +0/-0
    • http://www.szpilfogel.com
How do I have nut send me an email?
« Reply #4 on: December 31, 2006, 11:47:13 PM »
re-reading your question and Gordon's response. I have a similar problem so I use this mechanism to get an email on current status. What I usually get are occasional messages saying "UPS On Battery" or "UPS Online" when state transitions.
SME since 2003

Offline christian

  • *
  • 369
  • +0/-0
    • http://www.szpilfogel.com
How do I have nut send me an email?
« Reply #5 on: December 31, 2006, 11:49:48 PM »
ok. what about creating a custom template for "upsmon.conf" then in the mean time?

Quote
No, please don't.

That file will be overwritten next time the e-smith-nutUPS package is upgraded (for example right now, when the 7.1 packages hit the mirror sites).
SME since 2003

Offline gordonr

  • *
  • 646
  • +0/-0
    • http://www.smeserver.com.au/
How do I have nut send me an email?
« Reply #6 on: December 31, 2006, 11:51:53 PM »
Quote from: "christian"
ok. what about creating a custom template for "upsmon.conf" then in the mean time?


Yep. And when you have it working nicely, raise a New Feature Request so we can look at including it. NFRs with attached code/patches tend to get faster attention than simple requests for features.

Happy New Year - I hope the skating season improves :-(
............

Offline christian

  • *
  • 369
  • +0/-0
    • http://www.szpilfogel.com
How do I have nut send me an email?
« Reply #7 on: December 31, 2006, 11:54:18 PM »
not a chance. +8 tomorrow!!! January in Ottawa. yeesh.
SME since 2003

Offline dtech

  • **
  • 70
  • +0/-0
Re: How do I have nut send me an email?
« Reply #8 on: January 01, 2007, 12:37:23 AM »
Quote from: "gordonr"
A script in /etc/e-smith/events/halt should do it.


Hi Gordon;

This will work fine for me until a built in solution comes along. I've filed an RFE here: http://forums.contribs.org/index.php?topic=35043.msg152423#msg152423.

Thanks,

-P

Offline gordonr

  • *
  • 646
  • +0/-0
    • http://www.smeserver.com.au/
Re: How do I have nut send me an email?
« Reply #9 on: January 01, 2007, 12:39:19 AM »
Quote from: "dtech"

This will work fine for me until a built in solution comes along. I've filed an RFE here: http://forums.contribs.org/index.php?topic=35043.msg152423#msg152423.

Straight to the bug tracker, please. Thanks.
............

Offline dtech

  • **
  • 70
  • +0/-0
How do I have nut send me an email?
« Reply #10 on: January 01, 2007, 12:43:26 AM »

Offline del

  • *
  • 765
  • +0/-0
How do I have nut send me an email?
« Reply #11 on: January 01, 2007, 03:39:45 AM »
Hi dtech,

I also had a similar problem with my remote server and what I did was to go in to the server BIOS and there is a setting that tells the PC what to do when power is resumed and I set mine to startup, I am assuming that this is available in all or most of the modern BIOS settings. This has nothing to do with the OS, just the PC. It works for me, power goes off, battery takes over, server shuts down, power comes on and the server restarts :D I hope this helps.

Regards,
Del
If at first you don't succeed, then sky-diving is not for you!
"Life is like a coin. You can spend it anyway you wish, but you can only spend it once." --Author Unknown

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How do I have nut send me an email?
« Reply #12 on: January 14, 2007, 04:30:35 AM »
Quote from: "dtech"

I have a remote SME7 server set up with nut and an APC UPS, and it works well; the power goes off, SME shuts down nicely. The problem is that it doesn't come back on when the power comes back on.


As someone else suggested, you should fix that in the BIOS of your server.

Quote

I'd like to have the server send me an email so I know when this has happened.


If the power fails, there's no way to guarantee that an email is sent before the power goes off.

Offline dtech

  • **
  • 70
  • +0/-0
Re: How do I have nut send me an email?
« Reply #13 on: January 14, 2007, 07:01:01 PM »
Quote from: "CharlieBrady"
Quote from: "dtech"

I have a remote SME7 server set up with nut and an APC UPS, and it works well; the power goes off, SME shuts down nicely. The problem is that it doesn't come back on when the power comes back on.


As someone else suggested, you should fix that in the BIOS of your server.


Charlie;

I've set the BIOS to power on after a power failure, but of course it doesn't power the server back on after a clean shutdown by nut. Unless I'm missing something here, that behavior would be a little ridiculous. I'll take a look at it again.

-P

Offline stiperstones

  • *
  • 177
  • +0/-0
    • http://www.stiperstones.com
How do I have nut send me an email?
« Reply #14 on: January 14, 2007, 07:34:49 PM »
dtech
If i remember rightly when nut shutdowns the server it also sends a signal to your ups to shutdown as well at which point it will not power up your server. The ups needs to stay in stand-by mode then when the power is restored it will signal the server to power up this is what i found with the belkin ups unit correct me if i are wrong.
Stiperstones

http://wiki.contribs.org/Koozali_Foundation
Try the Wiki some great how's there

"My Licence".........

Don't report security issues here - Contact security at contribs dot org
Don't report problems here - Please report bugs @ http://bugs.contribs.org/
Don't ask the same question twice - Please search the forums, your question may have been asked before - Thank You.