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 {
my %args=@_;
$mtime=(stat("rrd"))[9];
$now=time;
utime $now,$now,"rrd";
$IWCONF = $args{IWCONFIG};
$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*10;
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 "Master" ) {
@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,0;
push @IFMACSNR,0;
if ($IFMACSNR[0] eq "") {
$IFMACSNR[0]=0;
}
if ($IFMACSNR[1] eq "") {
$IFMACSNR[1]=0;
}
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"); }
}
}
}
1;