Project

General

Profile

Feature #4335

NUT send notifications via built in smtp notification feature

Added by Josh Stompro about 5 years ago. Updated about 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Nut
Target version:
-
Start date:
01/28/2015
Due date:
% Done:

0%

Estimated time:

Description

This is a wishlist feature request.

The NUT package should have a checkbox that allows it to use the built in notification features of pfsense. System -> Advanced -> Notification, The email and growl features.

On a power status change event or battery status change event an email should be sent or a growl notification sent.

This would help users that don't have centralize logging but who would like to be notified when a power event happens.

upsmon.conf has a NOTIFYCMD option to run a script when an event occurs. If someone can give me some pointers on how to tie into the built in notifications I could take a stab at creating something.

Thanks

History

#1 Updated by Josh Stompro about 5 years ago

I think I found the info needed to make this work. A command line tool for sending email via the notification system has already been (thoughtfully) included.

/usr/local/bin/mail.php which takes stdin as the message and an argument for the subject (-s="subject")

The subject should probably be something like "UPS Alert: <hostname>"

Maybe something like this? - I'll try it out.

NOTIFYCMD = "echo \"$*\" | /usr/local/bin/mail.php -s=\"UPS Alert: `hostname`\""

NOTIFYCMD command
upsmon calls this to send messages when things happen.
This command is called with the full text of the message as one argument. The environment string NOTIFYTYPE will contain the type string of whatever caused this event to happen.
If you need to use upssched(8), then you must make it your NOTIFYCMD by listing it here.
Note that this is only called for NOTIFY events that have EXEC set with NOTIFYFLAG. See NOTIFYFLAG below for more details.
Making this some sort of shell script might not be a bad idea. For more information and ideas, see docs/scheduling.txt
Remember, this command also needs to be one element in the configuration file, so if your command has spaces, then wrap it in quotes.
NOTIFYCMD "/path/to/script --foo --bar"
This script is run in the background—that is, upsmon forks before it calls out to start it. This means that your NOTIFYCMD may have multiple instances running simultaneously if a lot of stuff happens all at once. Keep this in mind when designing complicated notifiers.

#2 Updated by Josh Stompro about 5 years ago

The following seems to work pretty good.

Add to upsmon.conf

NOTIFYCMD "/usr/pbi/nut-amd64/etc/nut/sendalert.sh" 
NOTIFYFLAG ONLINE       SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT       SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT      SYSLOG+WALL+EXEC
NOTIFYFLAG FSD          SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK       SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD      SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN     SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT     SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM       SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT     SYSLOG+WALL+EXEC

sendalert.sh script

#! /bin/sh
        printf "UPS Alert from pfSense firewall `hostname`\n\n$*" | /usr/local/bin/mail.php -s="UPS Alert: `hostname`" 

I would like to also add the info from snmp system location and system contact to the email if that data exists but I need to learn how to grab config values from the command line.

Also available in: Atom PDF