jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [dnet/] [platform/] [default.pm] - Blame information for rev 34

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3sub version {
4 ($VERSION = '$Revision: 1.7 $') =~ s/.*(\d+\.\d+).*/$1/;
5 return "default.pm $VERSION";
6 }
7 
8sub sample {
9 
10#
11# TODO: DB rebuild
12#
13 
14 my %args=@_;
15 
16# exit if DBs were changed earlier than 1 day ago
17 my ($min,$max)=HotSaNICmod::get_last_DB_changes();
18 if ( ($min>=0) && ($min<86400) ) { return 0; }
19 
20 my %NETWORK;
21 my @NETWORKS;
22 my $OTHER;
23 
24# each configured address gets its configured name. the relation of IPs to names are stored in %NETWORKS.
25# this hash can easily be traversed to assign the correct names to IPs.
26#
27 foreach (@{$args{NETWORK}}) {
28 my ($name,$range)=split /:/;
29 push @NETWORKS,$name;
30 if ($range eq "*") { $OTHER=$name; }
31 else { for $subnet (split /,/,$range) { $NETWORK{$subnet}=$name; } }
32 }
33 
34 ($logdate,$date,$entrydate1,$entrydate2,$sampletime)=getdatestrings(1);
35 
36 foreach $type ("RC5","OGR","CSC","DES") {
37 
38 $filename=$args{LOGPATH}."/".$args{"LOGNAME_$type"}.$logdate.".log";
39 
40 foreach (@NETWORKS) { $results{$_}{$type}=0; }
41 
42 if ( -e $filename ) {
43 if (HotSaNIClog::check_debuglevel("MODULE_VERBOSE")) { HotSaNIClog::info("reading $filename ..."); }
44 open FILE,$filename;
45 while (<FILE>) {
46 chomp;
47 ($timestamp,$ip,undef,undef,$size)=split /,/,$_;
48 ($linedate)=split / /,$timestamp;
49 if (($linedate eq $entrydate1) || ($linedate eq $entrydate2)) {
50 $network=ip2name($ip,$OTHER,%NETWORK);
51 $results{$network}{$type}+=$size;
52 }
53 }
54 close FILE;
55 }
56 }
57 foreach (@NETWORKS) {
58 HotSaNICmod::do_rrd($_,"U",$sampletime,$results{$_}{RC5},$results{$_}{OGR},$results{$_}{CSC},$results{$_}{DES});
59 }
60 }
61 
62 
63# convert IP number to a configured network or host.
64#
65sub ip2name {
66 my ($ip,$OTHER,%NETWORK)=@_;
67 my $name=$OTHER;
68 foreach my $subnet (keys %NETWORK) {
69 if (index("$ip.",$subnet) == 0) { $name=$NETWORK{$subnet}; }
70 }
71 return $name;
72 }
73 
74 
75# calculate date-strings of "$days days ago"
76#
77sub getdatestrings {
78 my $days=shift;
79 my $sampletime=(int(time/86400)-$days)*86400;
80 (undef,undef,undef,my $mday,my $mon,my $year,undef,undef,undef) = localtime($sampletime);
81 
82 $year+=1900;
83 $mon++;
84 if ($mon < 10) { $mon="0$mon"; }
85 if ($mday < 10) { $mday = "0".$mday; }
86 
87 my $yyyymm="$year$mon";
88 my $yyyymmdd="$year$mon$mday";
89 my $entrydate1="$mon/$mday/".substr($year,2,2);
90 my $entrydate2="$year-$mon-$mday";
91 return ($yyyymm,$yyyymmdd,$entrydate1,$entrydate2,$sampletime);
92 }
93 
941;
95 

Powered by WebSVN 2.2.1