1 | 1 | simandl | package sysrrcp; |
2 | | | |
3 | | | use lib "../../../lib"; |
4 | | | |
5 | | | sub version { |
6 | | | ($VERSION = '$Revision: 1.11 $') =~ s/.*(\d+\.\d+).*/$1/; |
7 | | | return "sysrrcp.pm $VERSION"; |
8 | | | } |
9 | | | |
10 | | | sub do_rrcp { |
11 | | | # print "###################################################################################\n"; |
12 | | | $rtlbin=""; |
13 | | | foreach (HotSaNICparser::read_settings(".")) { |
14 | | | my ($var,$value)=HotSaNICparser::parse_line($_); |
15 | | | if ($var eq "RTLBIN") { |
16 | | | $rtlbin= $value; |
17 | | | } |
18 | | | } |
19 | | | if (! -e "$rtlbin" ) { |
20 | | | # print "rtl binary $rtlbin not found!\n"; |
21 | | | } |
22 | | | |
23 | | | my (%targets) = @_; |
24 | | | foreach ( keys(%targets) ) { |
25 | | | my ($host, $com) = split /_/; |
26 | | | my ($res, $lastnic); |
27 | | | my %nics = (); |
28 | | | my $i = 0; |
29 | | | my $portnum = "none"; |
30 | | | |
31 | 18 | simandl | $res=`$rtlbin $com-$host\@eth0 show interface summary | grep ^eth | sed 's/://g' | sed 's/eth0\\///g'`; |
32 | 1 | simandl | #print "tu je res \n$res \n"; |
33 | | | @pole_res = split("\n",$res); |
34 | | | $pocet = scalar(@pole_res); |
35 | 2 | simandl | # print "Vysledek pro $_ je dlouhy $pocet \n"; |
36 | 1 | simandl | #vytvoreni asociativniho pole $nics s cislem portu a rychlostma |
37 | | | |
38 | | | for (@{$targets{$_}}) { |
39 | 2 | simandl | # print "0b $_\n"; |
40 | 1 | simandl | if($i == 0) { |
41 | | | $nics{$_} = 0; |
42 | | | $lastnic = $_; |
43 | | | $i++; |
44 | | | } else { |
45 | | | $nics{$lastnic} = $_; |
46 | | | $i = 0; |
47 | | | } |
48 | | | } # for |
49 | | | |
50 | 2 | simandl | # print "3 $host a $com b $lastnic\n"; |
51 | 1 | simandl | |
52 | | | foreach $port (keys(%nics) ){ |
53 | 2 | simandl | # print "3be $host $com $port $nics{$port}\n"; |
54 | 1 | simandl | my $resfound = 0; |
55 | | | my $rx = 0; |
56 | | | my $tx = 0; |
57 | | | #projdeme vysledek a pokud najdeme hodnoty pro port tak zapisem do rrd |
58 | | | foreach $linka (@pole_res) { |
59 | | | @polozky = split(" ", $linka); |
60 | | | $resport = $polozky[0]; |
61 | | | $resrx = $polozky[1]; |
62 | | | $restx = $polozky[2]; |
63 | | | |
64 | | | if ($port == $resport) { |
65 | | | $resfound = 1; |
66 | 2 | simandl | # print "Pro $port je $resrx a $restx\n"; |
67 | 1 | simandl | $rx = $resrx; |
68 | | | $tx = $restx; |
69 | | | } |
70 | | | } # foreach line in result |
71 | | | |
72 | | | #$host =~ s/://g; |
73 | | | |
74 | | | if ($resfound == 1) { |
75 | | | do_rrd($host."_".$port, $rx, $tx, $nics{$port}); |
76 | | | |
77 | | | } else { |
78 | 2 | simandl | # print "tady to je kdyz nejni spojeni tak se do rrd da undef\n"; |
79 | 1 | simandl | do_rrd($host."_".$port, "U", "U", $nics{$port}); |
80 | | | } |
81 | | | } # foreach port |
82 | | | } # foreach |
83 | | | } # sub |
84 | | | |
85 | | | sub do_rrd { |
86 | | | my ($name, $in, $out, $max) = @_; |
87 | | | #print "mam tu $max"; |
88 | | | if (! -e "rrd/$name.rrd" ) { |
89 | | | system("./makerrd","$name","$max") |
90 | | | } |
91 | | | |
92 | | | RRDs::update "rrd/$name.rrd",time.":".$in.":".$out; |
93 | | | if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
94 | | | } |
95 | | | |
96 | | | 1; |