jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-jablonecka/] [modules/] [traffic/] [platform/] [linux.pm.orig] - Rev 1

Compare with Previous - Blame - Download


package HotSaNICmod::OSdep;

use RRDs;

eval { require "platform/syssnmp.pm"; };
$NO_SNMP=1 if($@);

eval { require "platform/sysrrcp.pm"; };
$NO_RRCP=1 if($@);

sub version {
  ($VERSION = '$Revision: 1.7 $') =~ s/.*(\d+\.\d+).*/$1/;
  return "$^O.pm $VERSION";
  }

sub sample {
  my %args=@_;

  my %maxin;
  my %maxout;
  my %devin;
  my %devout;
  my %sampletime;
  my %snmpdev;

  foreach (keys(%args)) {
    if ( index($_,"DEV") >= 0) { 
      ($dev,$maxin,$maxout,$description)=split /,/,$args{$_};
      
      if(index($dev,"SNMP\:") >= 0) {
        (undef,$host,$community,$interface)=split /:/,$dev;

        my $max = $maxin;
        $max = $maxout if $maxin < $maxout;
        my @data = ( $interface, $max);
        if (defined $snmpdev{$host."_".$community}) {
          push @{$snmpdev{$host."_".$community}}, @data;
        } else { 
          $snmpdev{$host."_".$community} = [ @data ] ;
        }
      } else { 
        $dev =~ s/:/_/g; 
        $maxin{$dev}=$maxin;
        $maxout{$dev}=$maxout;
        $devin{$dev}="U";
        $devout{$dev}="U";
        $sampletime{$dev}=time;
      }
    }
  }

  open(IN,"/proc/net/dev");
  while(<IN>) {
    chomp;
    if ( /:/ ) {
      my ($combined, $a, undef, undef, undef, undef, undef, undef, $output, $e)=split;
      ($name, $input)=split(":",$combined);
      if(!$input) { ($input, $output) = ($a, $e); }
      $devin{$name}=$input;
      $devout{$name}=$output;
      $sampletime{$name}=time;
      }
    }
  close(IN);

  #
  # then query SNMP hosts and check interfaces
  #

  syssnmp::do_snmp(%snmpdev);

  foreach $name (keys %maxin) {

    # build new database if needed
    #
    if (! -e "rrd/$name.rrd" ) {
          
      # get max. transmission value
      #
      my $max=$maxin{$name};
      if ($max < $maxout{$name}) { $max=$maxout{$name} };
        
      # if max-transmission is not set, assume 100 MBit.
      #
      if ($max == 0) { $max=12500000; }
      system("./makerrd","$name","$max")
      }
        
    # update database
    RRDs::update "rrd/$name.rrd",$sampletime{$name}.":".$devin{$name}.":".$devout{$name};
    if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
    }

}

1;


Powered by WebSVN 2.2.1