jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-jablonecka/] [modules/] [networks/] [platform/] [linux.pm] - Blame information for rev 5

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4use lib "../../lib";
5 
6sub version {
7 ($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/;
8 return "$^O.pm $VERSION";
9 }
10 
11sub sample {
12 my %args=@_;
13 
14 my $IPTABLES=$args{IPTABLES};
15 
16 if ( (! -e "acct_int.dat") || (! -e "acct_ext.dat")) {
17 system("$IPTABLES -L acct_int -xvn > acct_int.dat");
18 system("$IPTABLES -L acct_ext -xvn > acct_ext.dat");
19 }
20 
21 my %acct_int_old=readfile("acct_int.dat",$IPTABLES);
22 my %acct_ext_old=readfile("acct_ext.dat",$IPTABLES);
23 system("$IPTABLES -L acct_int -xvn > acct_int.dat");
24 system("$IPTABLES -L acct_ext -xvn > acct_ext.dat");
25 my %acct_int=readfile("acct_int.dat",$IPTABLES);
26 my %acct_ext=readfile("acct_ext.dat",$IPTABLES);
27 
28 my $time=time;
29 
30 foreach my $nn (sort(keys(%acct_int))) {
31 $allin=$acct_int{$nn}[1]-$acct_int_old{$nn}[1];
32 $tcpin=$acct_int{$nn}[3]-$acct_int_old{$nn}[3];
33 $udpin=$acct_int{$nn}[5]-$acct_int_old{$nn}[5];
34 $icmpin=$acct_int{$nn}[7]-$acct_int_old{$nn}[7];
35 $allout=$acct_int{$nn}[2]-$acct_int_old{$nn}[2];
36 $tcpout=$acct_int{$nn}[4]-$acct_int_old{$nn}[4];
37 $udpout=$acct_int{$nn}[6]-$acct_int_old{$nn}[6];
38 $icmpout=$acct_int{$nn}[8]-$acct_int_old{$nn}[8];
39 updatedb($args{MODNAME},$time,"int$nn",$tcpin,$udpin,$icmpin,$tcpout,$udpout,$icmpout);
40 }
41 
42 foreach my $nn (sort(keys(%acct_ext))) {
43 $allin=$acct_ext{$nn}[1]-$acct_ext_old{$nn}[1];
44 $tcpin=$acct_ext{$nn}[3]-$acct_ext_old{$nn}[3];
45 $udpin=$acct_ext{$nn}[5]-$acct_ext_old{$nn}[5];
46 $icmpin=$acct_ext{$nn}[7]-$acct_ext_old{$nn}[7];
47 $allout=$acct_ext{$nn}[2]-$acct_ext_old{$nn}[2];
48 $tcpout=$acct_ext{$nn}[4]-$acct_ext_old{$nn}[4];
49 $udpout=$acct_ext{$nn}[6]-$acct_ext_old{$nn}[6];
50 $icmpout=$acct_ext{$nn}[8]-$acct_ext_old{$nn}[8];
51 updatedb($args{MODNAME},$time,"ext$nn",$tcpin,$udpin,$icmpin,$tcpout,$udpout,$icmpout);
52 }
53 }
54 
55sub readfile {
56 my ($file,$IPTABLES)=@_;
57 my $ip="";
58 undef my %hash;
59 open (FILE,$file);
60 while (<FILE>) {
61 chomp;
62 if (index($IPTABLES,"ipchains") >= 0 ) { ($pkt,$bytes,$target,$proto,$opt,$tosa,$tosx,$ifname,$src,$dst)=split; }
63 else { ($pkt,$bytes,$target,$proto,$opt,$in,$out,$src,$dst)=split; }
64 if ($pkt =~ /^[0-9]*$/ ) {
65 if ($dst eq "") { ($proto,$opt,$in,$out,$src,$dst)=($target,$proto,$opt,$in,$out,$src); }
66 if ($src eq "0.0.0.0/0") { $ip=$dst;$dir=1; } elsif ($dst eq "0.0.0.0/0") { $ip=$src;$dir=0; }
67 if ($proto eq "all") { $prt=1 };
68 if ($proto eq "tcp") { $prt=3 };
69 if ($proto eq "udp") { $prt=5 };
70 if ($proto eq "icmp") { $prt=7 };
71 if ($ip ne "") {$hash{"$ip"}[$prt+$dir]=$bytes;}
72 }
73 }
74 close (FILE);
75 return %hash;
76 }
77 
78sub updatedb {
79 my ($MODNAME,$time,$name,$tcpin,$udpin,$icmpin,$tcpout,$udpout,$icmpout)=@_;
80 $name =~ s/\//_/g;
81 if ( !-e "rrd/$name.rrd") { system "./makerrd $name U"; }
82 RRDs::update "rrd/$name.rrd",$time.":".$tcpin.":".$udpin.":".$icmpin.":".$tcpout.":".$udpout.":".$icmpout;
83 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$name.rrd': $ERROR\n"; }
84 }
85 
86 
871;
88 

Powered by WebSVN 2.2.1