1 | 35 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | use RRDs; |
4 | | | |
5 | | | sub version { |
6 | | | ($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/; |
7 | | | return "$^O.pm $VERSION"; |
8 | | | } |
9 | | | |
10 | | | sub sample { |
11 | | | my %args=@_; |
12 | | | |
13 | | | #uncomment this for debug output to temp.txt |
14 | | | #all print will be done into the file |
15 | | | #$temp = "/opt/HotSaNIC/modules/sensors/temp.txt"; |
16 | | | #open (TEMPFILE,">$temp"); |
17 | | | #open (STDERR,">&TEMPFILE") || die ("open STDERR failed"); |
18 | | | #open (STDOUT,">&TEMPFILE") || die ("open STDOUT failed"); |
19 | | | |
20 | | | foreach (keys(%args)) { |
21 | | | |
22 | | | if (index($_,"IP") >= 0 ) { |
23 | | | my ($dev,$oid,$name)=split(/,/,$args{$_}); |
24 | | | |
25 | | | # print "zacatek: $_ $dev $oid $name \n"; |
26 | | | |
27 | | | # open(FILE,"/usr/bin/snmpwalk -Os -c public -v 1 $dev $oid | grep 1.1.1.8.1.12.2 ") || print time," ",$args{MODNAME},": Unable to tady open $dev $oid $name .\n"; |
28 | | | # $_=<FILE>; |
29 | | | # chomp; |
30 | | | # close FILE; |
31 | | | |
32 | | | # @array=split; |
33 | | | my $num=4; |
34 | | | my $scale1=0.1; |
35 | | | my $scale2=0.001; |
36 | | | my $add=0; |
37 | | | |
38 | | | my $freq=1; |
39 | | | my $power=2; |
40 | | | my $signal=3; |
41 | | | my $temp=4; |
42 | | | my $snr=5; |
43 | | | my $qam=0; |
44 | | | my $bw=0; |
45 | | | #5 signal |
46 | | | #6 snr |
47 | | | #7 ber |
48 | | | #8 temp |
49 | | | #9 max speed |
50 | | | #10 speed |
51 | | | #12 tx freq |
52 | | | #13 rx freq |
53 | | | #14 tx speed |
54 | | | #15 rx speed |
55 | | | #18 atpc en dis |
56 | | | #19 tx power |
57 | | | #20 acm en dis |
58 | | | #21 tx qam |
59 | | | #22 rx qam |
60 | | | #23 tx bw |
61 | | | #24 rx bw |
62 | | | |
63 | | | |
64 | | | # $command = "/usr/bin/snmpwalk -Os -c public -v 1 $dev $oid | grep 1.1.1.8.1.12.2"; |
65 | | | $command = "/usr/bin/snmpwalk -Cc -On -c public -v 1 $dev $oid | tr '\"' ' '"; |
66 | | | open (FILE,"$command|"); |
67 | | | while(<FILE>) { |
68 | | | $var=$_; |
69 | | | # print ">>>>>>>> : $_ \n"; |
70 | | | if ($var =~ /^.*.23688.1.1.12.. = STRING: +(.*)$/) { |
71 | | | $freq = $1; |
72 | | | $freq =~ s/ MHz //g; |
73 | | | $freq=$freq*$scale2; |
74 | | | # print "freq : $freq \n"; |
75 | | | } elsif ($var =~ /^.*.23688.1.1.19.. = INTEGER: +(.*)$/) { |
76 | | | $power = $1; |
77 | | | # print "power : $power \n"; |
78 | | | } elsif ($var =~ /^.*.23688.1.1.5.. = Gauge32: +(.*)$/) { |
79 | | | $signal = $1 * -1; |
80 | | | # print "signal : $signal \n"; |
81 | | | } elsif ($var =~ /^.*.23688.1.1.8.. = INTEGER: +(.*)$/) { |
82 | | | $temp = $1; |
83 | | | # print "temp : $temp \n"; |
84 | | | } elsif ($var =~ /^.*.23688.1.1.6.. = Gauge32: +(.*)$/) { |
85 | | | $snr = $1; |
86 | | | $snr=$1*$scale1+$add; |
87 | | | # print "snr : $snr \n"; |
88 | | | } elsif ($var =~ /^.*.23688.1.1.21.. = INTEGER: +(.*)$/) { |
89 | | | $qam = $1; |
90 | | | $rate=$1*$scale1+$add; |
91 | | | # print "qam : $qam \n"; |
92 | | | } elsif ($var =~ /^.*.23688.1.1.23.. = Gauge32: +(.*)$/) { |
93 | | | $bw = $1; |
94 | | | # print "bw : $bw \n"; |
95 | | | } |
96 | | | } |
97 | | | close(FILE); |
98 | | | |
99 | | | # build new database if needed |
100 | | | if ( ! -e "rrd/$name.rrd" ) { system("./makerrd","$name","U") } |
101 | | | |
102 | | | # update database |
103 | | | RRDs::update "rrd/$name.rrd",time.":".$freq.":".$power.":".$signal.":".$temp.":".$snr.":".$qam.":".$bw; |
104 | | | if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
105 | | | |
106 | | | } |
107 | | | } |
108 | | | #uncomment this for debug output to temp.txt |
109 | | | #all print will be done into the file |
110 | | | # close (TEMPFILE); |
111 | | | # close (STDERR); |
112 | | | # close (STDOUT); |
113 | | | } |
114 | | | |
115 | | | 1; |
116 | | | |