jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [packets/] [platform/] [netbsd.pm] - Rev 36 Go to most recent revision

Compare with Previous - Blame - Download


package HotSaNICmod::OSdep;

use lib "../../lib";
use RRDs;

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

sub version {
        ($VERSION = '$Revision: 1.6 $') =~ 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,"netstat -nib | grep Link |");
        while(<IN>) {
                chomp;
                @line  = split;
                $name  = $line[0];
                $devin{$name} = $line[$#line-1];
                $devout{$name}= $line[$#line];
                $sampletime{$name}=time;
        }
        close(IN);

        #
        # then query SNMP hosts and check interfaces
        #

        syssnmp::do_snmp(%snmpdev);

        #
        # save data
        #
        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