| 1 | 28 | 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 | | | ($dev,$oid,$name)=split(/,/,$args{$_}); |
| 24 | | | |
| 25 | | | 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 open $dev.\n"; |
| 26 | | | $_=<FILE>; |
| 27 | | | chomp; |
| 28 | | | close FILE; |
| 29 | | | |
| 30 | | | @array=split; |
| 31 | | | $num=4; |
| 32 | | | $scale=1; |
| 33 | | | $add=0; |
| 34 | | | |
| 35 | | | $freq=1; |
| 36 | | | $mcs=2; |
| 37 | | | $signal=3; |
| 38 | | | $txsec=4; |
| 39 | | | $rate=5; |
| 40 | | | |
| 41 | | | $rssi=$array[$num-1]*$scale+$add; |
| 42 | | | |
| 43 | | | print "$dev $name $rssi\n"; |
| 44 | | | |
| 45 | | | # build new database if needed |
| 46 | | | if ( ! -e "rrd/$name.rrd" ) { system("./makerrd","$name","U") } |
| 47 | | | |
| 48 | | | # update database |
| 49 | | | RRDs::update "rrd/$name.rrd",time.":".$freq.":".$mcs.":".$signal.":".$txsec.":".$rssi.":".$rate; |
| 50 | | | if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; } |
| 51 | | | |
| 52 | | | } |
| 53 | | | } |
| 54 | | | #uncomment this for debug output to temp.txt |
| 55 | | | #all print will be done into the file |
| 56 | | | # close (TEMPFILE); |
| 57 | | | # close (STDERR); |
| 58 | | | # close (STDOUT); |
| 59 | | | } |
| 60 | | | |
| 61 | | | 1; |
| 62 | | | |