summaryrefslogtreecommitdiffstats
path: root/net/nut/files/nut-sendmail-notify.default
blob: ebffba55322e080ec5a8b44348a87aa39f40ad0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

. "${IPKG_INSTROOT}"/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
	if [ "$SKIPADDSYSLOG" != "1" ]; then
		uci set nut_monitor.@upsmon[-1].defaultnotify="SYSLOG+EXEC"
	else
		uci set nut_monitor.@upsmon[-1].defaultnotify="EXEC"
	fi
else
	if [ "$SKIPADDSYSLOG" != "1" ]; then
		uci set nut_monitor.@upsmon[-1].defaultnotify="SYSLOG"
	fi
fi

uci commit nut_monitor