1 | 10 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | use RRDs; |
4 | | | |
5 | | | use lib "../../lib"; |
6 | | | |
7 | | | sub version { |
8 | | | ($VERSION = '$Revision: 1.7 $') =~ s/.*(\d+\.\d+).*/$1/; |
9 | | | return "default.pm $VERSION"; |
10 | | | } |
11 | | | |
12 | | | sub sample { |
13 | | | |
14 | | | my %args=@_; |
15 | | | my ($loadpct,$bcharge,$timeleft,$outputv,$itemp,$battv)=("nan","nan","nan","nan","nan","nan"); |
16 | | | my ($onbatt,$replacebatt)=(-1,-1); |
17 | | | |
18 | | | open FILE,"$args{APCACCESS}|" || print time," ",$MODNAME,": unable to run '$args{APCACCESS}': $!\n"; |
19 | | | while (<FILE>) { |
20 | | | chomp; |
21 | | | ($name,$value,undef)=split / *: */; |
22 | | | ($firstvalue = $value) =~ s/ .*$//g; |
23 | | | if ($name eq "LOADPCT") { $loadpct=$firstvalue; } |
24 | | | if (($name eq "BCHARGE") || ($name eq "BATTPCT")) { $bcharge=$firstvalue; } |
25 | | | if ($name eq "TIMELEFT") { $timeleft=$firstvalue; } |
26 | | | if (($name eq "OUTPUTV") || ($name eq "OUTVOLT")) { $outputv=$firstvalue; } |
27 | | | if (($name eq "ITEMP") || ($name eq "UPSTEMP")) { $itemp=$firstvalue; } |
28 | | | if (($name eq "BATTV") || ($name eq "BATTVOLT")) { $battv=$firstvalue; } |
29 | | | if ($name eq "STATUS") { |
30 | | | if (index ($value,"ONBATT") >= 0 ) { $onbatt=1; } |
31 | | | if (index ($value,"REPLACEBATT") >= 0 ) { $replacebatt=1; } |
32 | | | } |
33 | | | } |
34 | | | close FILE; |
35 | | | |
36 | | | # build new database if needed |
37 | | | if ( ! -e "rrd/usv.rrd") { system "./makerrd usv"; } |
38 | | | |
39 | | | # update database |
40 | | | RRDs::update "rrd/usv.rrd", time.":".$loadpct.":".$bcharge.":".$timeleft.":".$outputv.":".$itemp.":".$battv.":".$onbatt.":".$replacebatt; |
41 | | | if ($ERROR = RRDs::error) { die time," ",$args{MODNAME},": unable to update usv.rrd: $ERROR\n"; } |
42 | | | |
43 | | | } |
44 | | | |
45 | | | 1; |
46 | | | |
47 | | | |