1 | 32 | 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,$port,$name)=split(/,/,$args{$_}); |
24 | | | |
25 | | | # print "zacatek: $_ $dev $oid $port $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.01; |
36 | | | my $scale3=0.001; |
37 | | | my $scale4=0.0000001; |
38 | | | my $add=0; |
39 | | | |
40 | | | my $ber=1; |
41 | | | my $temp=2; |
42 | | | my $rx1=3; |
43 | | | my $snr1=4; |
44 | | | my $rx2=5; |
45 | | | my $rx2=6; |
46 | | | my $preber=6; |
47 | | | my $isi1=7; |
48 | | | my $isi2=8; |
49 | | | #[root@jablonecka modules]# snmpwalk -c public -v 2c 10.33.154.1 .1.3.6.1.2.1.99.1.1.1.4 | grep 100349 |
50 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349201 = INTEGER: 606 |
51 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349202 = INTEGER: 325 |
52 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349203 = INTEGER: 1440 |
53 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349204 = INTEGER: 0 |
54 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349211 = INTEGER: 7137 |
55 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349212 = INTEGER: 1011 |
56 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349213 = INTEGER: 13413 |
57 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349214 = INTEGER: 1859 |
58 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349215 = INTEGER: 2270 |
59 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349216 = INTEGER: 2049 |
60 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349217 = INTEGER: 600 |
61 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349219 = INTEGER: 4 |
62 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349221 = INTEGER: 8727 |
63 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349222 = INTEGER: 1010 |
64 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349223 = INTEGER: 10281 |
65 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349224 = INTEGER: 1884 |
66 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349225 = INTEGER: 2270 |
67 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349226 = INTEGER: 2049 |
68 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349227 = INTEGER: 720 |
69 | | | #SNMPv2-SMI::mib-2.99.1.1.1.4.100349229 = INTEGER: 6 |
70 | | | #[root@jablonecka modules]# snmpwalk -c public -v 2c 10.33.154.1 1.3.6.1.2.1.47.1.1.1.1.2 | grep t49 |
71 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100100048 = STRING: "Ethernet49/1" |
72 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100100049 = STRING: "Ethernet49/2" |
73 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100100050 = STRING: "Ethernet49/3" |
74 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100100051 = STRING: "Ethernet49/4" |
75 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349100 = STRING: "Xcvr for Ethernet49" |
76 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349201 = STRING: "DOM Temperature Sensor for Ethernet49" |
77 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349202 = STRING: "DOM Voltage Sensor for Ethernet49" |
78 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349203 = STRING: "DOM Pre-FEC BER Sensor for Ethernet49" |
79 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349204 = STRING: "DOM Uncorrected BER Sensor for Ethernet49" |
80 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349210 = STRING: "Lane 0 for Xcvr for Ethernet49" |
81 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349211 = STRING: "DOM TX Bias Sensor for Ethernet49/1" |
82 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349212 = STRING: "DOM TX Power Sensor for Ethernet49/1" |
83 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349213 = STRING: "DOM RX Power Sensor for Ethernet49/1" |
84 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349214 = STRING: "DOM SNR Sensor for Ethernet49/1" |
85 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349215 = STRING: "DOM Residual ISI Sensor for Ethernet49/1" |
86 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349216 = STRING: "DOM Level Transition Sensor for Ethernet49/1" |
87 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349217 = STRING: "DOM TEC Current Sensor for Ethernet49/1" |
88 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349219 = STRING: "DOM Laser Temperature Error Sensor for Ethernet49/1" |
89 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349220 = STRING: "Lane 1 for Xcvr for Ethernet49" |
90 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349221 = STRING: "DOM TX Bias Sensor for Ethernet49/2" |
91 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349222 = STRING: "DOM TX Power Sensor for Ethernet49/2" |
92 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349223 = STRING: "DOM RX Power Sensor for Ethernet49/2" |
93 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349224 = STRING: "DOM SNR Sensor for Ethernet49/2" |
94 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349225 = STRING: "DOM Residual ISI Sensor for Ethernet49/2" |
95 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349226 = STRING: "DOM Level Transition Sensor for Ethernet49/2" |
96 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349227 = STRING: "DOM TEC Current Sensor for Ethernet49/2" |
97 | | | #SNMPv2-SMI::mib-2.47.1.1.1.1.2.100349229 = STRING: "DOM Laser Temperature Error Sensor for Ethernet49/2" |
98 | | | |
99 | | | # $command = "/usr/bin/snmpwalk -Os -c public -v 1 $dev $oid | grep 1.1.1.8.1.12.2"; |
100 | | | $command = "/usr/bin/snmpwalk -Cc -On -c public -v 1 $dev $oid | tr '\"' ' '"; |
101 | | | open (FILE,"$command|"); |
102 | | | while(<FILE>) { |
103 | | | $var=$_; |
104 | | | print ">>>>fiber>>>> : $_ \n"; |
105 | | | if ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}204 = INTEGER: +(.*)$/) { |
106 | | | $ber = $1*$scale2; |
107 | | | $ber=$ber; |
108 | | | print "ber : $ber \n"; |
109 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}213 = INTEGER: +(.*)$/) { |
110 | | | $rx1 = 10* log(1000*$1*$scale4)/log(10); |
111 | | | print "rx1 : $rx1 \n"; |
112 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}214 = INTEGER: +(.*)$/) { |
113 | | | $snr1 = $1*$scale2; |
114 | | | print "snr1 : $snr1 \n"; |
115 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}201 = INTEGER: +(.*)$/) { |
116 | | | $temp = $1*$scale1; |
117 | | | print "temp : $temp \n"; |
118 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}223 = INTEGER: +(.*)$/) { |
119 | | | $rx2 = 10* log(1000*$1*$scale4)/log(10); |
120 | | | print "rx2 : $rx2 \n"; |
121 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}224 = INTEGER: +(.*)$/) { |
122 | | | $snr2 = $1*$scale2; |
123 | | | print "snr2 : $snr2 \n"; |
124 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}203 = INTEGER: +(.*)$/) { |
125 | | | $preber = $1*$scale2; |
126 | | | print "preber : $preber \n"; |
127 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}215 = INTEGER: +(.*)$/) { |
128 | | | $isi1 = $1*$scale2; |
129 | | | print "isi1 : $isi1 \n"; |
130 | | | } elsif ($var =~ /^.1.3.6.1.2.1.99.1.1.1.4.1003${port}225 = INTEGER: +(.*)$/) { |
131 | | | $isi2 = $1*$scale2; |
132 | | | print "isi2 : $isi2 \n"; |
133 | | | } |
134 | | | } |
135 | | | close(FILE); |
136 | | | |
137 | | | # build new database if needed |
138 | | | if ( ! -e "rrd/$name.rrd" ) { system("./makerrd","$name","U") } |
139 | | | |
140 | | | # update database |
141 | | | RRDs::update "rrd/$name.rrd",time.":".$ber.":".$temp.":".$rx1.":".$snr1.":".$rx2.":".$snr2.":".$preber.":".$isi1.":".$isi2; |
142 | | | if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
143 | | | |
144 | | | } |
145 | | | } |
146 | | | #uncomment this for debug output to temp.txt |
147 | | | #all print will be done into the file |
148 | | | # close (TEMPFILE); |
149 | | | # close (STDERR); |
150 | | | # close (STDOUT); |
151 | | | } |
152 | | | |
153 | | | 1; |
154 | | | |