jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [sensors/] [platform/] [linux.pm] - Rev 32 Go to most recent revision

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($_,"SENSOR") >= 0 ) {
      ($dev,$dbname,$description,$num,$scale,$add,$units)=split(/,/,$args{$_});
      
      open(FILE,"$dev | grep \"^$description\" | sed \'s/°/ /g\' |") || print time," ",$args{MODNAME},": Unable to open $dev.\n";
      $_=<FILE>;
      chomp;
      close FILE;

      @array=split;
      $value=$array[$num-1]*$scale+$add;
      #$value=$array[$num-1];
#    print "$dev $description $value\n";
      # build new database if needed
      if ( ! -e "rrd/$dbname.rrd" ) { system("./makerrd","$dbname","10000") }

      # update database
      RRDs::update "rrd/$dbname.rrd",time.":".$value;  
      if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},":  unable to update `$dbname.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;


Powered by WebSVN 2.2.1