hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::OSdep;
sub version {
($VERSION = '$Revision: 1.7 $') =~ s/.*(\d+\.\d+).*/$1/;
return "default.pm $VERSION";
}
sub sample {
#
# TODO: DB rebuild
#
my %args=@_;
# exit if DBs were changed earlier than 1 day ago
my ($min,$max)=HotSaNICmod::get_last_DB_changes();
if ( ($min>=0) && ($min<86400) ) { return 0; }
my %NETWORK;
my @NETWORKS;
my $OTHER;
# each configured address gets its configured name. the relation of IPs to names are stored in %NETWORKS.
# this hash can easily be traversed to assign the correct names to IPs.
#
foreach (@{$args{NETWORK}}) {
my ($name,$range)=split /:/;
push @NETWORKS,$name;
if ($range eq "*") { $OTHER=$name; }
else { for $subnet (split /,/,$range) { $NETWORK{$subnet}=$name; } }
}
($logdate,$date,$entrydate1,$entrydate2,$sampletime)=getdatestrings(1);
foreach $type ("RC5","OGR","CSC","DES") {
$filename=$args{LOGPATH}."/".$args{"LOGNAME_$type"}.$logdate.".log";
foreach (@NETWORKS) { $results{$_}{$type}=0; }
if ( -e $filename ) {
if (HotSaNIClog::check_debuglevel("MODULE_VERBOSE")) { HotSaNIClog::info("reading $filename ..."); }
open FILE,$filename;
while (<FILE>) {
chomp;
($timestamp,$ip,undef,undef,$size)=split /,/,$_;
($linedate)=split / /,$timestamp;
if (($linedate eq $entrydate1) || ($linedate eq $entrydate2)) {
$network=ip2name($ip,$OTHER,%NETWORK);
$results{$network}{$type}+=$size;
}
}
close FILE;
}
}
foreach (@NETWORKS) {
HotSaNICmod::do_rrd($_,"U",$sampletime,$results{$_}{RC5},$results{$_}{OGR},$results{$_}{CSC},$results{$_}{DES});
}
}
# convert IP number to a configured network or host.
#
sub ip2name {
my ($ip,$OTHER,%NETWORK)=@_;
my $name=$OTHER;
foreach my $subnet (keys %NETWORK) {
if (index("$ip.",$subnet) == 0) { $name=$NETWORK{$subnet}; }
}
return $name;
}
# calculate date-strings of "$days days ago"
#
sub getdatestrings {
my $days=shift;
my $sampletime=(int(time/86400)-$days)*86400;
(undef,undef,undef,my $mday,my $mon,my $year,undef,undef,undef) = localtime($sampletime);
$year+=1900;
$mon++;
if ($mon < 10) { $mon="0$mon"; }
if ($mday < 10) { $mday = "0".$mday; }
my $yyyymm="$year$mon";
my $yyyymmdd="$year$mon$mday";
my $entrydate1="$mon/$mday/".substr($year,2,2);
my $entrydate2="$year-$mon-$mday";
return ($yyyymm,$yyyymmdd,$entrydate1,$entrydate2,$sampletime);
}
1;