aboutsummaryrefslogtreecommitdiff
path: root/net-mgmt/flow-tools/files/flow_fanout.in
blob: fb0cbe986a83dee5fe53ad840c923a99af21b8c7 (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh

# PROVIDE: flow_fanout
# REQUIRE: DAEMON
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable flow-fanout:
# flow_fanout_enable (bool):	Set it to "YES" to enable flow-fanout daemon.
#				Set to "NO" by default.
# flow_fanout_ip (str):		IP address to bind to
#				Default is "0.0.0.0"
# flow_fanout_remoteip (str):	IP address to accept flows from
#				Default is "0.0.0.0" or all IPs
# flow_fanout_port (int):	Port to accept flow data on
#				Default is "8787"
# flow_fanout_export (str):	Where to send flows to. Default is "0/0/8788"
# flow_fanout_flags (str):	Custom additional arguments to be passed
#				to flow-collector (default "").
# flow_fanout_profiles (str):	A list of configuration	profiles to enable.
#				This allows you	to run several instances of
#				flow-fanout with different parameters.
#				Consider the following example:
#				flow_fanout_enable="YES"
#				flow_fanout_ip="85.172.168.9"
#				flow_fanout_profiles="r1 r2"
#				flow_fanout_r1_port="4444"
#				flow_fanout_r1_export="0/0/9500 0/10.5.5.5/9200"
#				flow_fanout_r2_port="4445"
#				flow_fanout_r2_export="0/0/9551 0/0/9101"
#
#				This will run two instances of the flow-fanout
#				with parameters taken from appropriate
#				flow_fanout_PROFILENAME_xxx variables. For
#				unspecified parameters flow_fanout_xxx
#				variables will be used.

. /etc/rc.subr

name="flow_fanout"
rcvar=flow_fanout_enable

setup_profile_vars()
{
	name=flow_fanout_$1
	eval ": \${flow_fanout_${1}_ip=${flow_fanout_ip}}"
	eval ": \${flow_fanout_${1}_remoteip=${flow_fanout_remoteip}}"
	eval ": \${flow_fanout_${1}_port=${flow_fanout_port}}"
	eval ": \${flow_fanout_${1}_export=${flow_fanout_export}}"
	eval ": \${flow_fanout_${1}_flags=${flow_fanout_flags}}"
	eval "pidfile=${flow_fanout_pid}.\${flow_fanout_${1}_port}"
	eval "command_args=\"-p ${flow_fanout_pid} \${flow_fanout_${1}_ip}/\${flow_fanout_${1}_remoteip}/\${flow_fanout_${1}_port} \${flow_fanout_${1}_export}\""
}

start_profiles()
{
	unset start_cmd
	for _profile in ${flow_fanout_profiles}; do
		setup_profile_vars $_profile
		run_rc_command "${rc_arg}"
	done
}

stop_profiles()
{
	unset stop_cmd
	for _profile in ${flow_fanout_profiles}; do
		setup_profile_vars $_profile
		run_rc_command "${rc_arg}"
	done
}

status_profiles()
{
	unset status_cmd
	for _profile in ${flow_fanout_profiles}; do
		setup_profile_vars $_profile
		run_rc_command "${rc_arg}"
	done
}

load_rc_config $name

: ${flow_fanout_enable="NO"}
: ${flow_fanout_ip="0.0.0.0"}
: ${flow_fanout_remoteip="0.0.0.0"}
: ${flow_fanout_port="8787"}
: ${flow_fanout_export="0/0/8788"}
: ${flow_fanout_pid="%%FLOW_CAPTURE_PIDDIR%%/flow-fanout.pid"}
: ${flow_fanout_user="flowtools"}
: ${flow_fanout_group="flowtools"}

pidfile="${flow_fanout_pid}.${flow_fanout_port}"

command="%%PREFIX%%/bin/flow-fanout"
command_args="-p ${flow_fanout_pid} ${flow_fanout_ip}/${flow_fanout_remoteip}/${flow_fanout_port} ${flow_fanout_export}"

cmd="$1"
if [ $# -gt 0 ]; then
	shift
fi

[ -n "$*" ] && flow_fanout_profiles="$*"

if [ "${flow_fanout_profiles}" ]; then
	start_cmd="start_profiles"
	stop_cmd="stop_profiles"
	status_cmd="status_profiles"
fi

run_rc_command "$cmd"