hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::OSdep;
use RRDs;
use lib "../../lib";
sub version {
($VERSION = '$Revision: 1.7 $') =~ s/.*(\d+\.\d+).*/$1/;
return "default.pm $VERSION";
}
sub sample {
my %args=@_;
my ($loadpct,$bcharge,$timeleft,$outputv,$itemp,$battv)=("nan","nan","nan","nan","nan","nan");
my ($onbatt,$replacebatt)=(-1,-1);
open FILE,"$args{APCACCESS}|" || print time," ",$MODNAME,": unable to run '$args{APCACCESS}': $!\n";
while (<FILE>) {
chomp;
($name,$value,undef)=split / *: */;
($firstvalue = $value) =~ s/ .*$//g;
if ($name eq "LOADPCT") { $loadpct=$firstvalue; }
if (($name eq "BCHARGE") || ($name eq "BATTPCT")) { $bcharge=$firstvalue; }
if ($name eq "TIMELEFT") { $timeleft=$firstvalue; }
if (($name eq "OUTPUTV") || ($name eq "OUTVOLT")) { $outputv=$firstvalue; }
if (($name eq "ITEMP") || ($name eq "UPSTEMP")) { $itemp=$firstvalue; }
if (($name eq "BATTV") || ($name eq "BATTVOLT")) { $battv=$firstvalue; }
if ($name eq "STATUS") {
if (index ($value,"ONBATT") >= 0 ) { $onbatt=1; }
if (index ($value,"REPLACEBATT") >= 0 ) { $replacebatt=1; }
}
}
close FILE;
# build new database if needed
if ( ! -e "rrd/usv.rrd") { system "./makerrd usv"; }
# update database
RRDs::update "rrd/usv.rrd", time.":".$loadpct.":".$bcharge.":".$timeleft.":".$outputv.":".$itemp.":".$battv.":".$onbatt.":".$replacebatt;
if ($ERROR = RRDs::error) { die time," ",$args{MODNAME},": unable to update usv.rrd: $ERROR\n"; }
}
1;