summaryrefslogtreecommitdiff
path: root/package/wprobe/files/wprobe.init
blob: 11a5bf6e14b5b672d559e53811ee3c36a8977ec1 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh /etc/rc.common
START=90
EXPORTER=/usr/sbin/wprobe-ipfix
UTIL=/sbin/wprobe-util

wprobe_ssd() {
	local cmd="$1"; shift
	local type="$1"; shift
	local app="$1"; shift
	start-stop-daemon "$cmd" -p "/var/run/wprobe-$type.pid" -b ${app:+-x "$app"} -m -- "$@"
}

stop_wprobe() {
	local type="$1"
	[ -f "/var/run/wprobe-$type.pid" ] && wprobe_ssd -K "$type"
	rm -f "/var/run/wprobe-$type.pid"
}

config_wprobe() {
	config_get ifname "$cfg" ifname
	config_get interval "$cfg" interval
	[ -n "$interval" ] || interval=100
	$UTIL "$ifname" -i "$interval" 2>/dev/null >/dev/null
}

start_proxy() {
	config_get port "$cfg" port
	wprobe_ssd -S proxy "$UTIL" -P -p "${port:-19770}"
}

start_ipfix() {
	local cfg="$1"
	config_get ifname "$cfg" interface
	config_get host "$cfg" host
	config_get port "$cfg" port
	config_get proto "$cfg" proto
	case "$proto" in
		sctp) proto="-s";;
		tcp) proto="-t";;
		udp) proto="-u";;
		*) proto="-t";;
	esac
	[ -z "$ifname" -o -z "$host" ] && {
		echo "wprobe-export: missing host or interface name in config $cfg"
		return
	}
	config_wprobe "$cfg"
	wprobe_ssd -S "export-$cfg" "$EXPORTER" "$proto" -i "$ifname" -c "$host" -p "${port:-4739}"
}

start_export() {
	local cfg="$1"
	config_get export_type "$cfg" type
	case "$export_type" in 
		ipfix) [ -x "$EXPORTER" ] && start_ipfix "$cfg";;
		wprobe) start_proxy "$cfg";;
	esac
}

stop() {
	for f in /var/run/wprobe-*.pid; do
		CFG="${f%%.pid}"
		CFG="${CFG##/var/run/wprobe-}"
		stop_wprobe "$CFG"
	done
}

start() {
	config_load wprobe
	config_foreach config_wprobe interface
	config_foreach start_export export
}