jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [iwconf/] [platform/] [default.pm.old02] - Rev 36 Go to most recent revision

Compare with Previous - Blame - Download


package HotSaNICmod::OSdep;

use RRDs;

sub version {
        ($VERSION = '$Revision: 1.0 $') =~ s/.*(\d+\.\d+).*/$1/;
        my $platform;
        foreach (keys(%INC)) { $platform=$_ if $_ =~ /platform/; }
        return "$platform $VERSION";
}

sub sample {


#$temp = "/opt/HotSaNIC/modules/iwconf/temp.txt";
#open (TEMPFILE,">$temp");
#open (STDERR,">&TEMPFILE")  || die ("open STDERR failed");
#open (STDOUT,">&TEMPFILE")  || die ("open STDOUT failed");


        my %args=@_;

        $mtime=(stat("rrd"))[9];
        $now=time;

        utime $now,$now,"rrd";

        $IWCONF = $args{IWCONFIG};
        $IWLIST = $args{IWLIST};
        $hostap = $args{HOSTAP};


        my @IFACES=();
        my @IFMACS=();

        foreach (keys(%args)) {
                if (index($_,"IFACE:") >=0 ) {
                        (undef,$device)=split /:/;
                        push @IFACES,$device;
                }
        }
        foreach (keys(%args)) {
                if (index($_,"MAC,") >=0 ) {
                        (undef,$dev,$mac)=split /,/;
                        push @IFMACS,"$dev,$mac";
                }
        }

        foreach $device (@IFACES) {
                my $rate = 0;
                my $quality = 0;
                my $signal = 0;
                my $noise = 0;
                my $mode = 0;

                $command = "$IWCONF $device";
                open (FILE,"$command|");
                while(<FILE>) {
                        $var=$_;
                        if ($var =~ /^.*Rate[=|:]+(.*)M.*/) {
                                $rate = $1;
                        } elsif ($var =~ /^.*Quality[=|:]+(.*)\/.*[=|:](.*)\sdBm.*[=|:](.*)\sdBm.*/) {
                                $quality = $1;
                                $signal = $2;
                                $noise = $3;
                                last;
                        } elsif ($var =~ /^.*Mode[=|:]+(.*)  Fre.*/ ) {
                                $mode=$1;
                        }
                }
                close(FILE);
                $rate=$rate*1;

                if ( $mode eq "Managed" ) {
                        if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
                        RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
                        if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
                }

                if ( $mode eq "Ad-Hoc" ) {
                        if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
                        RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
                        if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
                }


#print "$device\n";


                if (( $mode eq "Master" ) && ( $device =~ /ath(.*)/ )) {

                                $IFMACSNR[0]=1;
                                $IFMACSNR[1]=1;
#                       @IFMACSNR=();
                        $clients = 0;

                        $command = "$IWLIST $device peers | grep 00";
                        open (FILE,"$command|");
                        while(<FILE>) {
                            $var=$_;
                            $clients = $clients + 10; 
                                if ($var =~ /^\s*(.*)\s:\s.*Quality[=|:]+(.*)\/.*/) {
                                    $signal = $2;
                                    $mac = $1;
#                                   push @IFMACSNR,$2;
#print "$1 $2\n";
#print "@IFMACS\n";
                                    $nummac = 0;
                                    foreach $ifmac (@IFMACS) {
                                    ($ifmaci,$ifmacm)=split(/,/,$ifmac);
                                        if ($ifmaci eq $device ) {
                                            if ($ifmacm eq $mac) {
#print "$ifmaci $ifmacm $ifmac\n";
                                                $IFMACSNR[$nummac]=$signal;
                                            }
                                            $nummac = $nummac + 1;
                                        }

                                    }

                                }
                        } 
                        close(FILE);

                        if ($IFMACSNR[0] eq "") {
                                $IFMACSNR[0]=1;
                        }
                        if ($IFMACSNR[1] eq "") {
                                $IFMACSNR[1]=2;
                        }
#print "@IFMACSNR\n";




                        if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
                        RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
                        if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
                }

                if (( $mode eq "Master" )  && ( $device =~ /wlan(.*)/ )) {


                        @clients = glob( "/proc/net/hostap/$device/00*" );
                        $clients = @clients;
                        $clients = $clients*10;
                        $signal=0;
                        $noise=0;
                        @IFMACSNR=();
                        foreach $ifmac (@IFMACS)
                        {
                                ($ifmaci,$ifmacm)=split(/,/,$ifmac);
                                if ($ifmaci eq $device ) {
                                        $iwmsnr=0;
                                        if ( -r "/proc/net/hostap/$ifmaci/$ifmacm" )
                                        {
                                                open (FILE,"/proc/net/hostap/$ifmaci/$ifmacm");
                                                while(<FILE>)
                                                {
                                                        $var=$_;
                                                        if ($var =~ /^.*silence=+(.*) dBm.*signal=+(.*) dBm.*rate=.*/)
                                                        {
                                                                ($iwmsilence,undef)=split(/ /,$1);
                                                                ($iwmsignal,undef)=split(/ /,$2);
                                                                $iwmsnr=$iwmsignal-$iwmsilence;
                                                                last;
                                                        }
                                                }
                                                close(FILE);
                                        }
                                        push @IFMACSNR,$iwmsnr;
                                }
                        }
                        push @IFMACSNR,15;
                        push @IFMACSNR,25;
                        if ($IFMACSNR[0] eq "") {
                                $IFMACSNR[0]=11;
                        }
                        if ($IFMACSNR[1] eq "") {
                                $IFMACSNR[1]=22;
                        }

                        if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
                        RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
                        if ($ERROR = RRDs::error) { dupe_control("warn",$ARGS{"MODNAME"},"unable to update `$device.rrd': $ERROR"); }
                }
        }
#       close (TEMPFILE);
#       close (STDERR);
#       close (STDOUT);
}
1;

Powered by WebSVN 2.2.1