hotsanic |
Subversion Repositories: |
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 {
#uncomment this for debug output to temp.txt
#all print will be done into the file
#$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]=10;
$IFMACSNR[1]=1;
$clients = 0;
#getting all clients into variable
$command = "/usr/local/bin/wlanconfig $device list sta | grep ^0";
#processing all clients to get mac and signal
open (FILE,"$command|");
while(<FILE>) {
$var=$_;
@macline=split(" ",$var);
#print "tu som @macline \n";
$clients = $clients + 10;
$mac = shift(@macline);
$signal = shift(@macline);
$signal = shift(@macline);
$signal = shift(@macline);
$signal = shift(@macline);
#print "mac adresa : $mac ma signal $signal\n";
#print "mac adresy : @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;
} # if
} # foreach
} # while
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
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;