net-nut: Add UPS notifications via sendmail
Add option to send email notification via sendmail (or replacement). Signed-off-by: Daniel Dickinson <lede@cshore.thecshore.com>
This commit is contained in:
parent
5503dac806
commit
c94e334c4e
3 changed files with 73 additions and 0 deletions
|
@ -152,6 +152,24 @@ define Package/nut-upsmon/install
|
|||
ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf
|
||||
endef
|
||||
|
||||
define Package/nut-upsmon-sendmail-notify
|
||||
$(call Package/nut/Default)
|
||||
TITLE+= (upsmon with notifications via sendmail)
|
||||
DEPENDS:=nut +nut-upsmon
|
||||
CONFLICTS:=nut-upssched
|
||||
endef
|
||||
|
||||
define Package/nut-upsmon-sendmail-notify/description
|
||||
$(call Package/nut/description/Default)
|
||||
upsmon with default notification via sendmail
|
||||
endef
|
||||
|
||||
define Package/nut-upsmon-sendmail-notify/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/nut-sendmail-notify $(1)/usr/bin/
|
||||
$(INSTALL_DATA) ./files/nut-sendmail-notify.default $(1)/etc/uci-defaults/nut-sendmail-notify
|
||||
endef
|
||||
|
||||
define Package/nut-upsc
|
||||
$(call Package/nut/Default)
|
||||
TITLE+= (upsc command)
|
||||
|
@ -504,6 +522,7 @@ $(eval $(call BuildPackage,nut))
|
|||
$(eval $(call BuildPackage,nut-common))
|
||||
$(eval $(call BuildPackage,nut-server))
|
||||
$(eval $(call BuildPackage,nut-upsmon))
|
||||
$(eval $(call BuildPackage,nut-upsmon-sendmail-notify))
|
||||
$(eval $(call BuildPackage,nut-upsc))
|
||||
$(eval $(call BuildPackage,nut-upscmd))
|
||||
$(eval $(call BuildPackage,nut-upslog))
|
||||
|
|
10
net/nut/files/nut-sendmail-notify
Executable file
10
net/nut/files/nut-sendmail-notify
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
/usr/sbin/sendmail root <<EOF
|
||||
From: root
|
||||
To: root
|
||||
Subject: UPS $NOTIFYTYPE Notification
|
||||
|
||||
$1
|
||||
.
|
||||
EOF
|
44
net/nut/files/nut-sendmail-notify.default
Normal file
44
net/nut/files/nut-sendmail-notify.default
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
REMOVEDEFAULTNOTIFY=0
|
||||
SKIPADDSYSLOG=0
|
||||
SKIPADDEXEC=0
|
||||
|
||||
upsmon() {
|
||||
local cfg="$1"
|
||||
local val
|
||||
|
||||
config_get val "$cfg" defaultnotify
|
||||
if [ -n "$val" ]; then
|
||||
if echo "$val" |grep -q "IGNORE"; then
|
||||
REMOVEDEFAULTNOTIFY=1
|
||||
else
|
||||
SKIPADDSYSLOG=1
|
||||
if echo "$val" |grep -q "EXEC"; then
|
||||
SKIPADDEXEC=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
config_load nut_monitor
|
||||
config_foreach upsmon upsmon
|
||||
|
||||
uci set nut_monitor.@upsmon[-1]=upsmon
|
||||
uci set nut_monitor.@upsmon[-1].notifycmd=/usr/bin/nut-sendmail-notify
|
||||
|
||||
if [ "$REMOVEDEFAULTNOTIFY" = "1" ]; then
|
||||
uci delete nut_monitor.@upsmon[-1].defaultnotify || true
|
||||
fi
|
||||
|
||||
if [ "$SKIPADDEXEC" != "1" ]; then
|
||||
uci add_list nut_monitor.@upsmon[-1].defaultnotify="EXEC"
|
||||
fi
|
||||
|
||||
if [ "$SKIPADDSYSLOG" != "1" ]; then
|
||||
uci add_list nut_monitor.@upsmon[-1].defaultnotify="SYSLOG"
|
||||
fi
|
||||
|
||||
uci commit nut_monitor
|
Loading…
Reference in a new issue