jablonka.czprosek.czf

hotsanic

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

 

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

Powered by WebSVN 2.2.1