jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-jablonecka/] [modules/] [iwconf/] [platform/] [default.pm.old] - Blame information for rev 21

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4 
5sub version {
6 ($VERSION = '$Revision: 1.0 $') =~ s/.*(\d+\.\d+).*/$1/;
7 my $platform;
8 foreach (keys(%INC)) { $platform=$_ if $_ =~ /platform/; }
9 return "$platform $VERSION";
10}
11 
12sub sample {
13 my %args=@_;
14 
15 $mtime=(stat("rrd"))[9];
16 $now=time;
17 
18 utime $now,$now,"rrd";
19 
20 $IWCONF = $args{IWCONFIG};
21 $hostap = $args{HOSTAP};
22 
23 my @IFACES=();
24 my @IFMACS=();
25 
26 foreach (keys(%args)) {
27 if (index($_,"IFACE:") >=0 ) {
28 (undef,$device)=split /:/;
29 push @IFACES,$device;
30 }
31 }
32 foreach (keys(%args)) {
33 if (index($_,"MAC,") >=0 ) {
34 (undef,$dev,$mac)=split /,/;
35 push @IFMACS,"$dev,$mac";
36 }
37 }
38 
39 foreach $device (@IFACES) {
40 my $rate = 0;
41 my $quality = 0;
42 my $signal = 0;
43 my $noise = 0;
44 my $mode = 0;
45 
46 $command = "$IWCONF $device";
47 open (FILE,"$command|");
48 while(<FILE>) {
49 $var=$_;
50 if ($var =~ /^.*Rate[=|:]+(.*)M.*/) {
51 $rate = $1;
52 } elsif ($var =~ /^.*Quality[=|:]+(.*)\/.*[=|:](.*)\sdBm.*[=|:](.*)\sdBm.*/) {
53 $quality = $1;
54 $signal = $2;
55 $noise = $3;
56 last;
57 } elsif ($var =~ /^.*Mode[=|:]+(.*) Fre.*/ ) {
58 $mode=$1;
59 }
60 }
61 close(FILE);
62 $rate=$rate*10;
63 
64 if ( $mode eq "Managed" ) {
65 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
66 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
67 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
68 }
69 
70 if ( $mode eq "Master" ) {
71 @clients = glob( "/proc/net/hostap/$device/00*" );
72 $clients = @clients;
73 $clients = $clients*10;
74 $signal=0;
75 $noise=0;
76 @IFMACSNR=();
77 foreach $ifmac (@IFMACS)
78 {
79 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
80 if ($ifmaci eq $device ) {
81 $iwmsnr=0;
82 if ( -r "/proc/net/hostap/$ifmaci/$ifmacm" )
83 {
84 open (FILE,"/proc/net/hostap/$ifmaci/$ifmacm");
85 while(<FILE>)
86 {
87 $var=$_;
88 if ($var =~ /^.*silence=+(.*) dBm.*signal=+(.*) dBm.*rate=.*/)
89 {
90 ($iwmsilence,undef)=split(/ /,$1);
91 ($iwmsignal,undef)=split(/ /,$2);
92 $iwmsnr=$iwmsignal-$iwmsilence;
93 last;
94 }
95 }
96 close(FILE);
97 }
98 push @IFMACSNR,$iwmsnr;
99 }
100 }
101 push @IFMACSNR,0;
102 push @IFMACSNR,0;
103 if ($IFMACSNR[0] eq "") {
104 $IFMACSNR[0]=0;
105 }
106 if ($IFMACSNR[1] eq "") {
107 $IFMACSNR[1]=0;
108 }
109 
110 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
111 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
112 if ($ERROR = RRDs::error) { dupe_control("warn",$ARGS{"MODNAME"},"unable to update `$device.rrd': $ERROR"); }
113 }
114 }
115}
1161;

Powered by WebSVN 2.2.1