1 | 1 | 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 | | | foreach (keys(%args)) { |
14 | | | |
15 | | | if (index($_,"SENSOR") >= 0 ) { |
16 | | | ($dev,$dbname,undef,$num,$scale,$add,undef)=split(/,/,$args{$_}); |
17 | | | open(DEVFILE,"$dev") || print time," ",$args{MODNAME},": Unable to open $dev.\n"; |
18 | | | $_=<DEVFILE>; |
19 | | | chomp; |
20 | | | close DEVFILE; |
21 | | | @array=split; |
22 | | | $value=$array[$num-1]*$scale+$add; |
23 | | | |
24 | | | # build new database if needed |
25 | | | if ( ! -e "rrd/$dbname.rrd" ) { system("./makerrd","$dbname","10000") } |
26 | | | |
27 | | | # update database |
28 | | | RRDs::update "rrd/$dbname.rrd",time.":".$value; |
29 | | | if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$dbname.rrd': $ERROR\n"; } |
30 | | | } |
31 | | | } |
32 | | | } |
33 | | | |
34 | | | 1; |
35 | | | |