3 # Called by upsmon when important things happen
4 # Env contains UPSNAME like "ups1@localhost",
5 # a NOTIFYTYPE like "ONLINE", and $1="My message"
6 # (C) 2000-2006,2016 by Jim Klimov
13 [ -s /etc
/nut
/notifyme.conf
] && .
/etc
/nut
/notifyme.conf
15 # By default, we send a message to root@localhost and a syslog event
16 [ -n "${MAILPROG-}" ] || MAILPROG
="mail"
17 [ -n "${UPSMONNAMELONG-}" ] || UPSMONNAMELONG
="the UPSMon-`hostname`"
19 [ -n "${UPSMON_SYSLOGPRIO_TROUBLE-}" ] || UPSMON_SYSLOGPRIO_TROUBLE
="daemon.emerg"
20 [ -n "${UPSMON_SYSLOGPRIO_GOODNOW-}" ] || UPSMON_SYSLOGPRIO_GOODNOW
="$UPSMON_SYSLOGPRIO_TROUBLE"
21 #[ -n "${UPSMON_SYSLOGPRIO_GOODNOW-}" ] || UPSMON_SYSLOGPRIO_GOODNOW="daemon.notice"
23 # Additionally, we can send a short SMS via email, if the admin has it set up
24 # SMSMAIL="sms2mail.account@mobile.operator"
25 [ -n "${SMSMAIL-}" ] || SMSMAIL
=""
26 [ -n "${UPSMONNAMESMS-}" ] || UPSMONNAMESMS
="UPSMon@`hostname`"
28 now
="`date -u '%Y-%m-%d %H:%M:%S'`"
31 [ x
"$NOTIFYTYPE" != xONLINE
-a x
"$NOTIFYTYPE" != xCOMMOK
] && plea
="
32 Please do something with power!
33 My shutdown will be clean, but...
36 # 1) Alert all consoles, syslog (and maybe email - depending on syslog daemon)
37 if [ -x /usr
/bin
/logger
]; then
39 SYSLOG_PRIO
="$UPSMON_SYSLOGPRIO_TROUBLE" || \
40 SYSLOG_PRIO
="$UPSMON_SYSLOGPRIO_GOODNOW"
41 /usr
/bin
/logger
-p "$SYSLOG_PRIO" -t "upsmon.notifyme.$$" "$UPSNAME: $NOTIFYTYPE : $message (at $now)" "$plea"
47 *) MAILPROG
="`which "$MAILPROG" | head -1 | egrep '^/'`" ;;
50 [ -n "$MAILPROG" ] ||
exit 0
51 [ -x "$MAILPROG" ] ||
{ echo "ERROR: MAILPROG='$MAILPROG' was specified but is not executable">&2; exit 1; }
53 # 2) send local mail so I know when the $it has hit the fan
54 # If it's local power trouble in the serverroom,
55 # I might go fix it before it's too late :^)
56 ${MAILPROG} root
-s "UPS status change: $NOTIFYTYPE" << EOF
59 UPS status change: $NOTIFYTYPE
63 Sincerely, $UPSMONNAMELONG
66 if [ -n "${SMSMAIL-}" ]; then
67 # 3) Send an SMS to the admin
68 ${MAILPROG} "$SMSMAIL" -s "UPS!" << EOF