forked from Cacti/plugin_flowview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow-capture
More file actions
86 lines (72 loc) · 2.04 KB
/
Copy pathflow-capture
File metadata and controls
86 lines (72 loc) · 2.04 KB
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
#!/usr/bin/php
<?php
/*
# description: Start Flow-Capture
# chkconfig: 2345 95 00
*/
/* we are not talking to the browser */
$no_http_headers = true;
$cacti_base = '/var/www/html/cacti';
include_once($cacti_base . '/include/global.php');
$tools_path = read_config_option('path_flowtools');
if (isset($_SERVER['argv'][1])) {
switch (strtolower($_SERVER['argv'][1])) {
case 'start':
start();
break;
case 'stop':
stop();
break;
case 'restart':
restart();
break;
default:
echo "Usage: /etc/init.d/flow-capture {start|stop|restart}\n";
break;
}
}
function start() {
global $tools_path, $cacti_base;;
echo "NOTE: Starting Flow Tools\n";
$devices = db_fetch_assoc('SELECT * FROM plugin_flowview_devices');
if (!empty($devices)) {
$path = db_fetch_cell("SELECT value FROM `settings` WHERE name = 'path_flows_dir'");
if ($path == '') {
return;
}
/* removing trailing slash and anything else */
$path = rtrim($path, "/ \n\t");
foreach ($devices as $device) {
$port = $device['port'];
$folder = $device['folder'];
$nest = $device['nesting'];
$v = $device['version'];
$from = $device['allowfrom'];
$comp = $device['compression'];
$rotate = $device['rotation'];
$expire = $device['expire'] * ($rotate + 1);
if (!is_dir("$path/$folder")) {
echo "NOTE: Making directory '$path/$folder'\n";
mkdir("$path/$folder", 0777, true);
}
if (is_dir("$path/$folder")) {
echo "NOTE: Launching flow-capture as '$tools_path/flow-capture -w $path/$folder 0/$from/$port -S5 -V$v -z $comp -n $rotate -e $expire -N $nest'\n";
shell_exec($tools_path . "/flow-capture -w $path/$folder 0/$from/$port -S5 -V$v -z $comp -n $rotate -e $expire -N $nest");
}
}
}else{
echo "WARNING: No flows configured\n";
}
}
function stop() {
global $tools_path, $cacti_base;;
echo "NOTE: Stopping Flow Tools\n";
$devices = db_fetch_assoc("SELECT * FROM plugin_flowview_devices");
if (!empty($devices)) {
shell_exec('killall -9 ' . $tools_path . '/flow-capture');
}
}
function restart() {
stop();
start();
}