-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflowd.pl
More file actions
executable file
·58 lines (51 loc) · 1.35 KB
/
flowd.pl
File metadata and controls
executable file
·58 lines (51 loc) · 1.35 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
#! /usr/bin/perl
use DBI;
use POSIX;
#use strict;
sub dsn { return "DBI:mysql:flow:localhost"; }
sub user { return "stat"; }
sub passwd { return "my_password"; }
my($dbh, $table, $msg, $stamp);
sub startwrite
{
unless ($dbh = DBI->connect(dsn, user, passwd, { PrintError => 1 }))
{
die "Can't connect to MySQL server: $DBI::err ($DBI::errstr)\n";
}
$table = strftime("flow_%Y_%m", localtime());
$stamp = strftime("%Y%m%d%H%M%S", localtime());
unless ($dbh->do("CREATE TABLE IF NOT EXISTS $table (
date TIMESTAMP NOT NULL,
user VARCHAR(20),
bytes_in BIGINT UNSIGNED NOT NULL,
bytes_out BIGINT UNSIGNED NOT NULL,
INDEX (user), UNIQUE (date, user)
)")) {
$msg="Can't create table $table: $DBI::err ($DBI::errstr)";
$dbh->disconnect();
die "$msg\n";
}
}
sub stopwrite
{
$dbh->disconnect();
undef($dbh);
}
sub writestat
{
# $user, $bytes_in, $bytes_out
die "Not connected\n" unless $dbh;
unless($dbh->do("INSERT IGNORE $table VALUES($stamp, '$user', $bytes_in, $bytes_out)")) {
$msg="Can't insert to $table: $DBI::err ($DBI::errstr)";
$dbh->disconnect();
die "$msg\n";
}
}
sub recv_pkt
{
# $router, $srcip, $dstip, $direction, $nexthop, $len, $pkts, $input, $output,
# $src_as, $dst_as, $proto, $src_port, $dst_port, $src_class, $dst_class
# Any of this variables can be changed
# Return link name or empty string
return '';
}