1 | 17 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | use RRDs; |
4 | | | |
5 | | | sub 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 | | | |
12 | | | sub 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/bgp/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 | | | if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") } |
52 | | | } # foreach |
53 | | | |
54 | | | my $asnum = 0; |
55 | | | my $pathlen = 0; |
56 | | | my $refcnt = 0; |
57 | | | my $signal = 0; |
58 | | | my $voltage = 0; |
59 | | | |
60 | | | $command = "cat /tmp/bgp.txt"; |
61 | | | open (FILE,"$command|"); |
62 | | | while(<FILE>) { |
63 | | | $var=$_; |
64 | | | if ($var =~ /^10/) { |
65 | | | @path=split(" ",$var); |
66 | | | $pathlen=scalar(@path); |
67 | | | if ($pathlen > 2) { |
68 | | | # print "line: $pathlen"; |
69 | | | # print "line: $_"; |
70 | | | $asnum = $path[$pathlen-2]; |
71 | | | $pathlen = $pathlen-2; |
72 | | | # print "$asnum $pathlen\n"; |
73 | | | if ( ! -e "rrd/$asnum.rrd" ) { system("./makerrd","$asnum","U") } |
74 | | | RRDs::update "rrd/$asnum.rrd",time.":".$pathlen.":".$refcnt.":".$signal.":".$voltage; |
75 | | | # if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$asnum.rrd': $ERROR"; } |
76 | | | if ($ERROR = RRDs::error) { print time," bgp: unable to update `$asnum.rrd': $ERROR\n"; } |
77 | | | $pathlen = 0; |
78 | | | } |
79 | | | } |
80 | | | } # while |
81 | | | close(FILE); |
82 | | | |
83 | | | |
84 | | | #uncomment this for debug output to temp.txt |
85 | | | #all print will be done into the file |
86 | | | # close (TEMPFILE); |
87 | | | # close (STDERR); |
88 | | | # close (STDOUT); |
89 | | | } |
90 | | | 1; |