jablonka.czprosek.czf

hotsanic

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

Compare with Previous - Blame - Download


package sysrrcp;

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

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

sub do_rrcp {
#    print "###################################################################################\n";
$rtlbin="";
foreach (HotSaNICparser::read_settings(".")) {
  my ($var,$value)=HotSaNICparser::parse_line($_);
  if ($var eq "RTLBIN") {
    $rtlbin= $value;
    }
}
    if (! -e "$rtlbin" ) {
#       print "rtl binary $rtlbin not found!\n";
    }
    
  my (%targets) = @_;
    foreach ( keys(%targets) ) {
                my ($host, $com) = split /_/;
                my ($res, $lastnic);    
                my %nics = ();          
                my $i = 0;
                my $portnum = "none";

        $res=`$rtlbin $com-$host\@eth0 counters | grep ^eth | sed 's/://g' | sed 's/eth0\\///g'`;       
                #print "tu je res \n$res \n";
                @pole_res = split("\n",$res);
                $pocet = scalar(@pole_res);     
                print "Vysledek pro $_ je dlouhy $pocet \n";
                #vytvoreni asociativniho pole $nics s cislem portu a rychlostma

                for (@{$targets{$_}}) {
                    print "0b $_\n";
                        if($i == 0) {
                                $nics{$_} = 0;
                                $lastnic = $_;
                                $i++;
                        } else {
                                $nics{$lastnic} = $_;
                                $i = 0;
                        }
                } # for

                    print "3 $host a $com b $lastnic\n";

                foreach $port (keys(%nics) ){
                    print "3be $host $com $port $nics{$port}\n";
                    my $resfound = 0;
                    my $rx = 0;
                    my $tx = 0;
                    #projdeme vysledek a pokud najdeme hodnoty pro port tak zapisem do rrd
                    foreach $linka (@pole_res) {
                        @polozky = split(" ", $linka);
                        $resport = $polozky[0];
                        $resrx = $polozky[1];
                        $restx = $polozky[2];

                        if ($port == $resport) {
                            $resfound = 1;
                            print "Pro $port je $resrx a $restx\n";
                            $rx = $resrx;
                            $tx = $restx;
                        }
                    } # foreach line in result
                    
                    #$host =~ s/://g;
                        
                    if ($resfound == 1) {
                        do_rrd($host."_".$port, $rx, $tx, $nics{$port});
                    
                    } else {
                        print "tady to je kdyz nejni spojeni tak se do rrd da undef\n";
                        do_rrd($host."_".$port, "U", "U", $nics{$port});
                    }
                } # foreach port
    } # foreach
} # sub

sub do_rrd {
        my ($name, $in, $out, $max) = @_;
#print "mam tu $max";
        if (! -e "rrd/$name.rrd" ) {
                system("./makerrd","$name","$max")
        }

        RRDs::update "rrd/$name.rrd",time.":".$in.":".$out;
        if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
}

1;

Powered by WebSVN 2.2.1