hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::OSdep;
use RRDs;
sub version {
($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/;
return "$^O.pm $VERSION";
}
sub sample {
my %args=@_;
#uncomment this for debug output to temp.txt
#all print will be done into the file
#$temp = "/opt/HotSaNIC/modules/sensors/temp.txt";
#open (TEMPFILE,">$temp");
#open (STDERR,">&TEMPFILE") || die ("open STDERR failed");
#open (STDOUT,">&TEMPFILE") || die ("open STDOUT failed");
foreach (keys(%args)) {
if (index($_,"IP") >= 0 ) {
my ($dev,$oid,$name)=split(/,/,$args{$_});
# print "zacatek: $_ $dev $oid $name \n";
# 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";
# $_=<FILE>;
# chomp;
# close FILE;
# @array=split;
my $num=4;
my $scale1=0.1;
my $scale2=0.000001;
my $add=0;
my $freq=1;
my $power=2;
my $signal=3;
my $temp=4;
my $snr=5;
my $qam=0;
my $bw=0;
#5 signal .1.3.6.1.4.1.193.223.2.7.1.1.1.110101 = STRING: "-29.8"
#6 snr .1.3.6.1.4.1.193.223.2.7.1.1.43.110101 = STRING: "30.3"
#7 ber
#8 temp
#9 max speed
#10 speed
#12 tx freq SNMPv2-SMI::enterprises.193.223.2.7.1.1.13.110101 = INTEGER: 83000000
#13 rx freq
#14 tx speed
#15 rx speed
#18 atpc en dis
#19 tx power .1.3.6.1.4.1.193.223.2.7.1.1.2.110101 = STRING: "10.8"
#20 acm en dis
#21 tx qam SNMPv2-SMI::enterprises.193.223.2.7.1.1.3.110101 = STRING: "128_QAM"
#22 rx qam
#23 tx bw SNMPv2-SMI::enterprises.193.223.2.7.1.1.9.110101 = INTEGER: 302
#24 rx bw
# $command = "/usr/bin/snmpwalk -Os -c public -v 1 $dev $oid | grep 1.1.1.8.1.12.2";
# print "/usr/bin/snmpwalk -Os -c public -v 1 $dev $oid | grep 1.1.1.8.1.12.2";
$command = "/usr/bin/snmpwalk -Cc -On -c public -v 1 $dev $oid | tr '\"' ' '";
open (FILE,"$command|");
while(<FILE>) {
$var=$_;
# print ">>>>>>>> : $name \n";
# print ">>>>>>>> : $_ \n";
if ($var =~ /^.*.193.223.2.7.1.1.13.110101 = INTEGER: +(.*)$/) {
$freq = $1;
$freq=$freq*$scale2;
# print "freq : $freq \n";
} elsif ($var =~ /^.*.193.223.2.7.1.1.2.110101 = STRING: +(.*)$/) {
$power = $1*1;
# print "power : $power \n";
} elsif ($var =~ /^.*.193.223.2.7.1.1.1.110101 = STRING: +(.*)$/) {
$signal = $1 * 1;
# print "signal : $signal \n";
} elsif ($var =~ /^.*.23688.1.1.8.. = INTEGER: +(.*)$/) {
$temp = $1*1;
# print "temp : $temp \n";
} elsif ($var =~ /^.*.193.223.2.7.1.1.43.110101 = STRING: +(.*)$/) {
$snr = $1*1;
# print "snr : $snr \n";
} elsif ($var =~ /^.*.193.223.2.7.1.1.3.110101 = STRING: +(.*)$/) {
$qam = $1;
$qam=~ s/_QAM//g;
$qam= log($qam)/log(2);
# print "qam : $qam \n";
} elsif ($var =~ /^.*.193.223.2.7.1.1.9.110101 = INTEGER: +(.*)$/) {
if ($1 == 302) {$bw=2};
if ($1 == 300) {$bw=1.5};
if ($1 == 298) {$bw=1};
if ($1 == 273) {$bw=.75};
if ($1 == 272) {$bw=.5};
if ($1 == 271) {$bw=.25};
if ($1 == 270) {$bw=.125};
if ($1 == 302) {$bw=2};
# print "bw : $bw \n";
}
}
close(FILE);
# build new database if needed
if ( ! -e "rrd/$name.rrd" ) { system("./makerrd","$name","U") }
# update database
RRDs::update "rrd/$name.rrd",time.":".$freq.":".$power.":".$signal.":".$temp.":".$snr.":".$qam.":".$bw;
if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
}
}
#uncomment this for debug output to temp.txt
#all print will be done into the file
# close (TEMPFILE);
# close (STDERR);
# close (STDOUT);
}
1;