jablonka.czprosek.czf

hotsanic

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

 

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 
14 
15#$temp = "/opt/HotSaNIC/modules/iwconf/temp.txt";
16#open (TEMPFILE,">$temp");
17#open (STDERR,">&TEMPFILE") || die ("open STDERR failed");
18#open (STDOUT,">&TEMPFILE") || die ("open STDOUT failed");
19 
20 
21 my %args=@_;
22 
23 $mtime=(stat("rrd"))[9];
24 $now=time;
25 
26 utime $now,$now,"rrd";
27 
28 $IWCONF = $args{IWCONFIG};
29 $IWLIST = $args{IWLIST};
30 $hostap = $args{HOSTAP};
31 
32 
33 my @IFACES=();
34 my @IFMACS=();
35 
36 foreach (keys(%args)) {
37 if (index($_,"IFACE:") >=0 ) {
38 (undef,$device)=split /:/;
39 push @IFACES,$device;
40 }
41 }
42 foreach (keys(%args)) {
43 if (index($_,"MAC,") >=0 ) {
44 (undef,$dev,$mac)=split /,/;
45 push @IFMACS,"$dev,$mac";
46 }
47 }
48 
49 foreach $device (@IFACES) {
50 my $rate = 0;
51 my $quality = 0;
52 my $signal = 0;
53 my $noise = 0;
54 my $mode = 0;
55 
56 $command = "$IWCONF $device";
57 open (FILE,"$command|");
58 while(<FILE>) {
59 $var=$_;
60 if ($var =~ /^.*Rate[=|:]+(.*)M.*/) {
61 $rate = $1;
62 } elsif ($var =~ /^.*Quality[=|:]+(.*)\/.*[=|:](.*)\sdBm.*[=|:](.*)\sdBm.*/) {
63 $quality = $1;
64 $signal = $2;
65 $noise = $3;
66 last;
67 } elsif ($var =~ /^.*Mode[=|:]+(.*) Fre.*/ ) {
68 $mode=$1;
69 }
70 }
71 close(FILE);
72 $rate=$rate*1;
73 
74 if ( $mode eq "Managed" ) {
75 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
76 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
77 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
78 }
79 
80 if ( $mode eq "Ad-Hoc" ) {
81 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
82 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
83 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
84 }
85 
86 
87#print "$device\n";
88 
89 
90 if (( $mode eq "Master" ) && ( $device =~ /ath(.*)/ )) {
91 
92 $IFMACSNR[0]=1;
93 $IFMACSNR[1]=1;
94# @IFMACSNR=();
95 $clients = 0;
96 
97 $command = "$IWLIST $device peers | grep 00";
98 open (FILE,"$command|");
99 while(<FILE>) {
100 $var=$_;
101 $clients = $clients + 10;
102 if ($var =~ /^\s*(.*)\s:\s.*Quality[=|:]+(.*)\/.*/) {
103 $signal = $2;
104 $mac = $1;
105# push @IFMACSNR,$2;
106#print "$1 $2\n";
107#print "@IFMACS\n";
108 $nummac = 0;
109 foreach $ifmac (@IFMACS) {
110 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
111 if ($ifmaci eq $device ) {
112 if ($ifmacm eq $mac) {
113#print "$ifmaci $ifmacm $ifmac\n";
114 $IFMACSNR[$nummac]=$signal;
115 }
116 $nummac = $nummac + 1;
117 }
118 
119 }
120 
121 }
122 }
123 close(FILE);
124 
125 if ($IFMACSNR[0] eq "") {
126 $IFMACSNR[0]=1;
127 }
128 if ($IFMACSNR[1] eq "") {
129 $IFMACSNR[1]=2;
130 }
131#print "@IFMACSNR\n";
132 
133 
134 
135 
136 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
137 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
138 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
139 }
140 
141 if (( $mode eq "Master" ) && ( $device =~ /wlan(.*)/ )) {
142 
143 
144 @clients = glob( "/proc/net/hostap/$device/00*" );
145 $clients = @clients;
146 $clients = $clients*10;
147 $signal=0;
148 $noise=0;
149 @IFMACSNR=();
150 foreach $ifmac (@IFMACS)
151 {
152 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
153 if ($ifmaci eq $device ) {
154 $iwmsnr=0;
155 if ( -r "/proc/net/hostap/$ifmaci/$ifmacm" )
156 {
157 open (FILE,"/proc/net/hostap/$ifmaci/$ifmacm");
158 while(<FILE>)
159 {
160 $var=$_;
161 if ($var =~ /^.*silence=+(.*) dBm.*signal=+(.*) dBm.*rate=.*/)
162 {
163 ($iwmsilence,undef)=split(/ /,$1);
164 ($iwmsignal,undef)=split(/ /,$2);
165 $iwmsnr=$iwmsignal-$iwmsilence;
166 last;
167 }
168 }
169 close(FILE);
170 }
171 push @IFMACSNR,$iwmsnr;
172 }
173 }
174 push @IFMACSNR,15;
175 push @IFMACSNR,25;
176 if ($IFMACSNR[0] eq "") {
177 $IFMACSNR[0]=11;
178 }
179 if ($IFMACSNR[1] eq "") {
180 $IFMACSNR[1]=22;
181 }
182 
183 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
184 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
185 if ($ERROR = RRDs::error) { dupe_control("warn",$ARGS{"MODNAME"},"unable to update `$device.rrd': $ERROR"); }
186 }
187 }
188# close (TEMPFILE);
189# close (STDERR);
190# close (STDOUT);
191}
1921;

Powered by WebSVN 2.2.1