92_FileLog.pm 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. ##############################################
  2. # $Id: 92_FileLog.pm 14888 2017-08-13 12:07:12Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use IO::File;
  7. # This block is only needed when FileLog is loaded bevore FHEMWEB
  8. sub FW_pO(@);
  9. sub FW_pH(@);
  10. sub FW_addContent(;$);
  11. use vars qw($FW_ME); # webname (default is fhem)
  12. use vars qw($FW_RET); # Returned data (html)
  13. use vars qw($FW_RETTYPE);
  14. use vars qw($FW_cmdret); # error msg forwarding from toSVG
  15. use vars qw($FW_detail); # for redirect after toSVG
  16. use vars qw($FW_plotmode);# Global plot mode (WEB attribute), used by weblink
  17. use vars qw($FW_plotsize);# Global plot size (WEB attribute), used by weblink
  18. use vars qw($FW_ss); # is smallscreen
  19. use vars qw($FW_wname); # Web instance
  20. use vars qw(%FW_pos); # scroll position
  21. use vars qw(%FW_webArgs); # all arguments specified in the GET
  22. sub FileLog_seekTo($$$$$);
  23. sub FileLog_dailySwitch($);
  24. #####################################
  25. sub
  26. FileLog_Initialize($)
  27. {
  28. my ($hash) = @_;
  29. $hash->{DefFn} = "FileLog_Define";
  30. $hash->{SetFn} = "FileLog_Set";
  31. $hash->{GetFn} = "FileLog_Get";
  32. $hash->{UndefFn} = "FileLog_Undef";
  33. #$hash->{DeleteFn} = "FileLog_Delete";
  34. $hash->{NotifyFn} = "FileLog_Log";
  35. $hash->{AttrFn} = "FileLog_Attr";
  36. # logtype is used by the frontend
  37. no warnings 'qw';
  38. my @attrList = qw(
  39. addStateEvent:0,1
  40. archiveCompress
  41. archivecmd
  42. archivedir
  43. createGluedFile:0,1
  44. disable:0,1
  45. disabledForIntervals
  46. eventOnThreshold
  47. logtype
  48. mseclog:1,0
  49. nrarchive
  50. reformatFn
  51. );
  52. use warnings 'qw';
  53. $hash->{AttrList} = join(" ", @attrList);
  54. $hash->{FW_summaryFn} = "FileLog_fhemwebFn";
  55. $hash->{FW_detailFn} = "FileLog_fhemwebFn";
  56. $hash->{SVG_sampleDataFn} = "FileLog_sampleDataFn";
  57. $hash->{SVG_regexpFn} = "FileLog_regexpFn";
  58. $data{FWEXT}{"/FileLog_toSVG"}{CONTENTFUNC} = "FileLog_toSVG";
  59. $data{FWEXT}{"/FileLog_logWrapper"}{CONTENTFUNC} = "FileLog_logWrapper";
  60. InternalTimer(time()+0.1, sub() { # Forum #39792
  61. map { HandleArchiving($defs{$_},1) } devspec2array("TYPE=FileLog");
  62. FileLog_dailySwitch($hash); # Forum #42415
  63. }, $hash, 0);
  64. }
  65. sub
  66. FileLog_dailySwitch($)
  67. {
  68. my ($hash) = @_;
  69. map { FileLog_Switch($defs{$_}) } devspec2array("TYPE=FileLog");
  70. my $t = time();
  71. my $off = fhemTzOffset($t);
  72. $t = 86400*(int(($t+$off)/86400)+1)+1-$off; # tomorrow, 1s after midnight
  73. InternalTimer($t, "FileLog_dailySwitch", $hash, 0);
  74. }
  75. #####################################
  76. sub
  77. FileLog_Define($@)
  78. {
  79. my ($hash, $def) = @_;
  80. my @a = split("[ \t][ \t]*", $def);
  81. my $fh;
  82. if(@a == 5 && $a[4] eq "readonly") {
  83. $hash->{READONLY} = 1;
  84. pop(@a);
  85. }
  86. return "wrong syntax: define <name> FileLog filename regexp [readonly]"
  87. if(int(@a) != 4);
  88. return "Bad regexp: starting with *" if($a[3] =~ m/^\*/);
  89. eval { "Hallo" =~ m/^$a[3]$/ };
  90. return "Bad regexp: $@" if($@);
  91. my @t = localtime;
  92. my $f = ResolveDateWildcards($a[2], @t);
  93. if(!$hash->{READONLY}) {
  94. $fh = new IO::File ">>$f";
  95. return "Can't open $f: $!" if(!defined($fh));
  96. }
  97. $hash->{FH} = $fh;
  98. $hash->{REGEXP} = $a[3];
  99. $hash->{logfile} = $a[2];
  100. $hash->{currentlogfile} = $f;
  101. $hash->{STATE} = "active";
  102. InternalTimer(0, sub(){ notifyRegexpChanged($hash, $a[3]); }, $hash);
  103. return undef;
  104. }
  105. #####################################
  106. sub
  107. FileLog_Undef($$)
  108. {
  109. my ($hash, $name) = @_;
  110. close($hash->{FH}) if($hash->{FH});
  111. return undef;
  112. }
  113. # Unused
  114. sub
  115. FileLog_Delete($$)
  116. {
  117. my ($hash, $name) = @_;
  118. return if(!$hash->{currentlogfile});
  119. unlink($hash->{currentlogfile});
  120. return undef;
  121. }
  122. sub
  123. FileLog_Switch($)
  124. {
  125. my ($log) = @_;
  126. my $fh = $log->{FH};
  127. my @t = localtime;
  128. my $cn = ResolveDateWildcards($log->{logfile}, @t);
  129. if($cn ne $log->{currentlogfile}) { # New logfile
  130. $log->{currentlogfile} = $cn;
  131. return 1 if($log->{READONLY});
  132. $fh->close() if($fh);
  133. HandleArchiving($log);
  134. $fh = new IO::File ">>$cn";
  135. if(!defined($fh)) {
  136. Log3 $log, 0, "Can't open $cn";
  137. return 0;
  138. }
  139. $log->{FH} = $fh;
  140. setReadingsVal($log, "linesInTheFile", 0, TimeNow());
  141. return 1;
  142. }
  143. return 0;
  144. }
  145. #####################################
  146. sub
  147. FileLog_Log($$)
  148. {
  149. # Log is my entry, Dev is the entry of the changed device
  150. my ($log, $dev) = @_;
  151. return if($log->{READONLY});
  152. my $ln = $log->{NAME};
  153. return if(IsDisabled($ln));
  154. my $events = deviceEvents($dev, AttrVal($ln, "addStateEvent", 0));
  155. return if(!$events);
  156. my $n = $dev->{NAME};
  157. my $re = $log->{REGEXP};
  158. my $max = int(@{$events});
  159. my $tn = $dev->{NTFY_TRIGGERTIME};
  160. if($log->{mseclog}) {
  161. my ($seconds, $microseconds) = gettimeofday();
  162. $tn .= sprintf(".%03d", $microseconds/1000);
  163. }
  164. my $ct = $dev->{CHANGETIME};
  165. my $fh;
  166. my $switched;
  167. my $written = 0;
  168. for (my $i = 0; $i < $max; $i++) {
  169. my $s = $events->[$i];
  170. $s = "" if(!defined($s));
  171. my $t = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
  172. if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/ || "$t:$n:$s" =~ m/^$re$/) {
  173. $t =~ s/ /_/; # Makes it easier to parse with gnuplot
  174. if(!$switched) {
  175. FileLog_Switch($log);
  176. $switched = 1;
  177. }
  178. $fh = $log->{FH};
  179. print $fh "$t $n $s\n";
  180. $written++;
  181. }
  182. }
  183. return "" if(!$written);
  184. if($fh) {
  185. $fh->flush;
  186. # Skip sync, it costs too much HD strain, esp. on SSD
  187. # $fh->sync if !($^O eq 'MSWin32'); #not implemented in Windows
  188. }
  189. my $owr = ReadingsVal($ln, "linesInTheFile", 0);
  190. my $eot = AttrVal($ln, "eventOnThreshold", 0);
  191. if($eot && ($owr+$written) % $eot == 0) {
  192. readingsSingleUpdate($log, "linesInTheFile", $owr+$written, 1);
  193. } else {
  194. setReadingsVal($log, "linesInTheFile", $owr+$written, $tn);
  195. }
  196. return "";
  197. }
  198. ###################################
  199. sub
  200. FileLog_Attr(@)
  201. {
  202. my @a = @_;
  203. my $do = 0;
  204. if($a[2] eq "mseclog") {
  205. $defs{$a[1]}{mseclog} = ($a[0] eq "set" && (!defined($a[3]) || $a[3]) );
  206. return;
  207. }
  208. if($a[0] eq "set" && $a[2] eq "disable") {
  209. $do = (!defined($a[3]) || $a[3]) ? 1 : 2;
  210. }
  211. $do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
  212. return if(!$do);
  213. $defs{$a[1]}{STATE} = ($do == 1 ? "disabled" : "active");
  214. return undef;
  215. }
  216. ###################################
  217. sub
  218. FileLog_Set($@)
  219. {
  220. my ($hash, @a) = @_;
  221. my $me = $hash->{NAME};
  222. return "no set argument specified" if(int(@a) < 2);
  223. my %sets = (reopen=>0, clear=>0, absorb=>1, addRegexpPart=>2,
  224. removeRegexpPart=>1);
  225. my $cmd = $a[1];
  226. if(!defined($sets{$cmd})) {
  227. my $r = "Unknown argument $cmd, choose one of ".join(" ",sort keys %sets);
  228. my $fllist = join(",", grep { $me ne $_ } devspec2array("TYPE=FileLog"));
  229. $r =~ s/absorb/absorb:$fllist/;
  230. return $r;
  231. }
  232. return "$cmd needs $sets{$cmd} parameter(s)" if(@a-$sets{$cmd} != 2);
  233. if(($cmd eq "reopen") or ($cmd eq "clear")) {
  234. if(!FileLog_Switch($hash)) { # No rename, reopen anyway
  235. my $fh = $hash->{FH};
  236. my $cn = $hash->{currentlogfile};
  237. $fh->close();
  238. if($cmd eq "clear") {
  239. $fh = new IO::File(">$cn");
  240. setReadingsVal($hash, "linesInTheFile", 0, TimeNow());
  241. } else {
  242. $fh = new IO::File(">>$cn");
  243. }
  244. return "Can't open $cn" if(!defined($fh));
  245. $hash->{FH} = $fh;
  246. }
  247. } elsif($cmd eq "addRegexpPart") {
  248. my %h;
  249. my $re = "$a[2]:$a[3]";
  250. map { $h{$_} = 1 } split(/\|/, $hash->{REGEXP});
  251. $h{$re} = 1;
  252. $re = join("|", sort keys %h);
  253. return "Bad regexp: starting with *" if($re =~ m/^\*/);
  254. eval { "Hallo" =~ m/^$re$/ };
  255. return "Bad regexp: $@" if($@);
  256. $hash->{REGEXP} = $re;
  257. $hash->{DEF} = $hash->{logfile} ." $re";
  258. notifyRegexpChanged($hash, $re);
  259. } elsif($cmd eq "removeRegexpPart") {
  260. my %h;
  261. map { $h{$_} = 1 } split(/\|/, $hash->{REGEXP});
  262. return "Cannot remove regexp part: not found" if(!$h{$a[2]});
  263. return "Cannot remove last regexp part" if(int(keys(%h)) == 1);
  264. delete $h{$a[2]};
  265. my $re = join("|", sort keys %h);
  266. return "Bad regexp: starting with *" if($re =~ m/^\*/);
  267. eval { "Hallo" =~ m/^$re$/ };
  268. return "Bad regexp: $@" if($@);
  269. $hash->{REGEXP} = $re;
  270. $hash->{DEF} = $hash->{logfile} ." $re";
  271. notifyRegexpChanged($hash, $re);
  272. } elsif($cmd eq "absorb") {
  273. my $victim = $a[2];
  274. return "need another FileLog as argument."
  275. if(!$victim ||
  276. !$defs{$victim} ||
  277. $defs{$victim}{TYPE} ne "FileLog" ||
  278. $victim eq $me);
  279. my $vh = $defs{$victim};
  280. my $mylogfile = $hash->{currentlogfile};
  281. return "Cant open the associated files"
  282. if(!open(FH1, $mylogfile) ||
  283. !open(FH2, $vh->{currentlogfile}) ||
  284. !open(FH3, ">$mylogfile.new"));
  285. my $fh = $hash->{FH};
  286. $fh->close();
  287. my $b1 = <FH1>; my $b2 = <FH2>;
  288. while(defined($b1) && defined($b2)) {
  289. if($b1 lt $b2) {
  290. print FH3 $b1; $b1 = <FH1>;
  291. } else {
  292. print FH3 $b2; $b2 = <FH2>;
  293. }
  294. }
  295. while($b1 = <FH1>) { print FH3 $b1; }
  296. while($b2 = <FH2>) { print FH3 $b2; }
  297. close(FH1); close(FH2); close(FH3);
  298. rename("$mylogfile.new", $mylogfile);
  299. $fh = new IO::File(">>$mylogfile");
  300. $hash->{FH} = $fh;
  301. $hash->{REGEXP} .= "|".$vh->{REGEXP};
  302. $hash->{DEF} = $hash->{logfile} . " ". $hash->{REGEXP};
  303. notifyRegexpChanged($hash, $hash->{REGEXP});
  304. CommandDelete(undef, $victim);
  305. }
  306. return undef;
  307. }
  308. sub
  309. FileLog_loadSVG()
  310. {
  311. if(!$modules{SVG}{LOADED} && -f "$attr{global}{modpath}/FHEM/98_SVG.pm") {
  312. my $ret = CommandReload(undef, "98_SVG");
  313. Log3 undef, 1, $ret if($ret);
  314. }
  315. }
  316. #########################
  317. sub
  318. FileLog_fhemwebFn($$$$)
  319. {
  320. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  321. return "<div id=\"$d\" align=\"center\" class=\"FileLog col2\">".
  322. "$defs{$d}{STATE}</div>" if($FW_ss && $pageHash);
  323. my $row = 0;
  324. my $ret = sprintf("<table class=\"FileLog %swide\">",
  325. $pageHash ? "" : "block ");
  326. foreach my $f (FW_fileList($defs{$d}{logfile})) {
  327. my $class = (!$pageHash ? (($row++&1)?"odd":"even") : "");
  328. $ret .= "<tr class=\"$class\">";
  329. $ret .= "<td><div class=\"dname\">$f</div></td>";
  330. my $idx = 0;
  331. foreach my $ln (split(",", AttrVal($d, "logtype", "text"))) {
  332. if($FW_ss && $idx++) {
  333. $ret .= "</tr><tr class=\"".(($row++&1)?"odd":"even")."\"><td>";
  334. }
  335. my ($lt, $name) = split(":", $ln);
  336. $name = $lt if(!$name);
  337. $ret .= FW_pH("$FW_ME/FileLog_logWrapper&dev=$d&type=$lt&file=$f",
  338. "<div class=\"dval\">$name</div>", 1, "dval", 1);
  339. }
  340. $ret .= "</tr>";
  341. }
  342. $ret .= "</table>";
  343. return $ret if($pageHash);
  344. # DETAIL only from here on
  345. my $hash = $defs{$d};
  346. $ret .= "<br>Regexp parts";
  347. $ret .= "<br><table class=\"block wide\">";
  348. my @ra = split(/\|/, $hash->{REGEXP});
  349. if(@ra > 1) {
  350. foreach my $r (@ra) {
  351. $ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
  352. my $cmd = "cmd.X= set $d removeRegexpPart&val.X=$r"; # =.set: avoid JS
  353. $ret .= "<td>$r</td>";
  354. $ret .= FW_pH("$cmd&detail=$d", "removeRegexpPart", 1,undef,1);
  355. $ret .= "</tr>";
  356. }
  357. }
  358. my @et = devspec2array("TYPE=eventTypes");
  359. if(!@et) {
  360. $ret .= FW_pH("$FW_ME/docs/commandref.html#eventTypes",
  361. "To add a regexp an eventTypes definition is needed",
  362. 1, undef, 1);
  363. } else {
  364. my %dh;
  365. my $etList = AnalyzeCommand(undef, "get $et[0] list");
  366. $etList = "" if(!$etList);
  367. foreach my $l (split("\n", $etList)) {
  368. my @a = split(/[ \r\n]/, $l);
  369. $a[1] = "" if(!defined($a[1]));
  370. $a[1] =~ s/\.\*//g;
  371. $a[1] =~ s/,.*//g;
  372. next if(@a < 2);
  373. $dh{$a[0]}{".*"} = 1;
  374. $dh{$a[0]}{$a[1].".*"} = 1;
  375. }
  376. my $list = "";
  377. foreach my $dev (sort keys %dh) {
  378. $list .= " $dev:" . join(",", sort keys %{$dh{$dev}});
  379. }
  380. $list =~ s/(['"])/./g;
  381. $ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
  382. $ret .= '<td colspan="2">';
  383. $ret .= FW_detailSelect($d, "set", $list, "addRegexpPart");
  384. $ret .= "</td></tr>";
  385. }
  386. $ret .= "</table>";
  387. my $newIdx=1;
  388. while($defs{"SVG_${d}_$newIdx"}) {
  389. $newIdx++;
  390. }
  391. my $name = "SVG_${d}_$newIdx";
  392. $ret .= FW_pH("cmd=define $name SVG $d:template:CURRENT;".
  393. "set $name copyGplotFile&detail=$name",
  394. "<div class=\"dval\">Create SVG plot</div>", 0, "dval", 1);
  395. return $ret;
  396. }
  397. ###################################
  398. sub
  399. FileLog_toSVG($)
  400. {
  401. my ($arg) = @_;
  402. FW_digestCgi($arg);
  403. return("text/html;", "bad url: cannot create SVG def")
  404. if(!defined($FW_webArgs{arg}));
  405. my @aa = split(":", $FW_webArgs{arg});
  406. my $max = 0;
  407. for my $d (keys %defs) {
  408. $max = ($1+1) if($d =~ m/^SVG_(\d+)$/ && $1 >= $max);
  409. }
  410. $defs{$aa[0]}{currentlogfile} =~ m,([^/]*)$,;
  411. $aa[2] = "CURRENT" if($1 eq $aa[2]);
  412. $FW_cmdret = FW_fC("define SVG_$max SVG $aa[0]:$aa[1]:$aa[2]");
  413. $FW_detail = "SVG_$max" if(!$FW_cmdret);
  414. return;
  415. }
  416. ######################
  417. # Show the content of the log (plain text), or an image and offer a link
  418. # to convert it to an SVG instance
  419. # If text and no reverse required, try to return the data as a stream;
  420. sub
  421. FileLog_logWrapper($)
  422. {
  423. my ($cmd) = @_;
  424. my $d = $FW_webArgs{dev};
  425. my $type = $FW_webArgs{type};
  426. my $file = $FW_webArgs{file};
  427. my $ret = "";
  428. if(!$d || !$type || !$file) {
  429. FW_addContent(">FileLog_logWrapper: bad arguments</div");
  430. return 0;
  431. }
  432. if(defined($type) && $type eq "text") {
  433. $defs{$d}{logfile} =~ m,^(.*)/([^/]*)$,; # Dir and File
  434. my $path = "$1/$file";
  435. $path =~ s/%L/$attr{global}{logdir}/g
  436. if($path =~ m/%/ && $attr{global}{logdir});
  437. $path = AttrVal($d,"archivedir","") . "/$file" if(!-f $path);
  438. FW_addContent();
  439. FW_pO "<div class=\"tiny\">" if($FW_ss);
  440. FW_pO "<pre class=\"log\">";
  441. my $suffix = "</pre>".($FW_ss ? "</div>" : "")."</div>";
  442. my $reverseLogs = AttrVal($FW_wname, "reverseLogs", 0);
  443. if(!$reverseLogs) {
  444. $suffix .= "</body></html>";
  445. return FW_returnFileAsStream($path, $suffix, "text/html", 1, 0);
  446. }
  447. if(!open(FH, $path)) {
  448. FW_addContent(">$path: $!</div></body></html");
  449. return 0;
  450. }
  451. my $cnt = join("", reverse <FH>);
  452. close(FH);
  453. $cnt = FW_htmlEscape($cnt);
  454. FW_pO $cnt;
  455. FW_pO $suffix;
  456. return 1;
  457. } else {
  458. FileLog_loadSVG();
  459. FW_pO "<script type='text/javascript' src='$FW_ME/pgm2/svg.js'></script>";
  460. FW_addContent();
  461. FW_pO "<br>";
  462. if(AttrVal($d,"plotmode",$FW_plotmode) ne "gnuplot") {
  463. FW_pO SVG_zoomLink("$cmd;zoom=-1", "Zoom-in", "zoom in");
  464. FW_pO SVG_zoomLink("$cmd;zoom=1", "Zoom-out","zoom out");
  465. FW_pO SVG_zoomLink("$cmd;off=-1", "Prev", "prev");
  466. FW_pO SVG_zoomLink("$cmd;off=1", "Next", "next");
  467. }
  468. FW_pO "<table><tr><td>";
  469. FW_pO "<td>";
  470. my $logtype = $defs{$d}{NAME};
  471. my $wl = "&amp;pos=" . join(";", map {"$_=$FW_pos{$_}"} keys %FW_pos);
  472. my $arg = "$FW_ME/SVG_showLog&dev=$logtype&logdev=$d".
  473. "&gplotfile=$type&logfile=$file$wl";
  474. if(AttrVal($d,"plotmode",$FW_plotmode) eq "SVG") {
  475. my ($w, $h) = split(",", AttrVal($d,"plotsize",$FW_plotsize));
  476. FW_pO "<embed src=\"$arg\" type=\"image/svg+xml\" " .
  477. "width=\"$w\" height=\"$h\" name=\"$d\"/>\n";
  478. } else {
  479. FW_pO "<img src=\"$arg\"/>";
  480. }
  481. FW_pO "<br>";
  482. FW_pH "$FW_ME/FileLog_toSVG&arg=$d:$type:$file", "Create SVG instance";
  483. FW_pO "</td>";
  484. FW_pO "</td></tr></table>";
  485. FW_pO "</div>";
  486. }
  487. return 0;
  488. }
  489. ###################################
  490. # We use this function to be able to scroll/zoom in the plots created from the
  491. # logfile. When outfile is specified, it is used with gnuplot post-processing,
  492. # when outfile is "-" it is used to create SVG graphics
  493. #
  494. # Up till now following functions are impemented:
  495. # - int (to cut off % from a number, as for the actuator)
  496. # - delta-h / delta-d to get rain/h and rain/d values from continuous data.
  497. #
  498. # It will set the %data values
  499. # mindate<x>, min<x>, maxdate<x>, max<x>, avg<x>, cnt<x>, currdate<x>,
  500. # currval<x>, sum<x>
  501. # for each requested column, beginning with <x> = 1
  502. sub
  503. FileLog_Get($@)
  504. {
  505. my ($hash, @a) = @_;
  506. return "Usage: get $a[0] <infile> <outfile> <from> <to> [<column_spec>...]\n".
  507. " where column_spec is <col>:<regexp>:<default>:<fn>\n" .
  508. " see the FileLogGrep entries in he .gplot files\n" .
  509. " <infile> is without direcory, - means the current file\n" .
  510. " <outfile> is a prefix, - means stdout\n"
  511. if(int(@a) < 4);
  512. shift @a;
  513. my $inf = shift @a;
  514. my $outf = shift @a;
  515. my $from = shift @a;
  516. my $to = shift @a; # Now @a contains the list of column_specs
  517. my $internal;
  518. my $name = $hash->{NAME};
  519. if($outf eq "INT") {
  520. $outf = "-";
  521. $internal = 1;
  522. }
  523. my $reformatFn = AttrVal($name, "reformatFn", "");
  524. my $tempread;
  525. if($inf eq "-") {
  526. # In case now is after midnight, before the first event is logged.
  527. FileLog_Switch($hash);
  528. $inf = $hash->{currentlogfile};
  529. } else {
  530. my $linf;
  531. if($inf eq "CURRENT") {
  532. # Try to guess
  533. if($from =~ m/^(....)-(..)-(..)/) {
  534. $linf = $hash->{logfile};
  535. my ($Y,$m,$d) = ($1,$2,$3);
  536. sub expandFileWildcards($$$$) {
  537. my ($f,$Y,$m,$d)=@_;
  538. return ResolveDateWildcards($f,
  539. localtime(time_str2num("$Y-$m-$d 00:00:00")));
  540. };
  541. $linf=expandFileWildcards($linf,$Y,$m,$d);
  542. if(AttrVal($name, "createGluedFile", 0)) {
  543. if($to =~ m/^(....)-(..)-(..)/) {
  544. my $linf_to = $hash->{logfile};
  545. my ($Y,$m,$d) = ($1,$2,$3);
  546. $linf_to=expandFileWildcards($linf_to,$Y,$m,$d);
  547. if($linf ne $linf_to){ # use to log files
  548. $tempread=$linf_to.".transit.temp.log";
  549. if(open(my $temp,'>',$tempread)){
  550. if(open(my $i,'<',$linf)){
  551. print $temp join("",<$i>);
  552. close($i);
  553. }
  554. if(open(my $i,'<',$linf_to)){
  555. print $temp join("",<$i>);
  556. close($i);
  557. }
  558. $linf=$tempread;
  559. close($temp);
  560. }
  561. }
  562. }
  563. }
  564. $linf = $hash->{currentlogfile} if($linf =~ m/%/ || ! -f $linf);
  565. } else {
  566. $linf = $hash->{currentlogfile};
  567. }
  568. } else {
  569. $linf = "$1/$inf" if($hash->{currentlogfile} =~ m,^(.*)/[^/]*$,);
  570. $linf = "" if(!$linf); # Missing log directory
  571. }
  572. # Look for the file in the log directory...
  573. if(!-f $linf) {
  574. # ... or in the archivelog
  575. $linf = AttrVal($name, "archivedir",".") ."/". $inf;
  576. }
  577. $inf = $linf;
  578. }
  579. Log3 $name, 4, "$name get: Input file $inf, from:$from to:$to";
  580. my $ifh = new IO::File $inf if($inf);
  581. FileLog_seekTo($inf, $ifh, $hash, $from, $reformatFn) if($ifh);
  582. # Return the the plain file data, $outf is ignored
  583. if(!@a) {
  584. return "" if(!$ifh);
  585. my $out = "";
  586. while(my $l = <$ifh>) {
  587. if($reformatFn) { no strict; $l = &$reformatFn($l); use strict; }
  588. next if($l lt $from);
  589. last if($l gt $to);
  590. $out .= $l;
  591. }
  592. return $out;
  593. }
  594. #############
  595. # Digest the input.
  596. # last1: first delta value after d/h change
  597. # last2: last delta value recorded (for the very last entry)
  598. # last3: last delta timestamp (d or h)
  599. my (@d, @fname);
  600. my (@min, @max, @sum, @cnt, @lastv, @lastd, @mind, @maxd, @firstv, @firstd);
  601. for(my $i = 0; $i < int(@a); $i++) {
  602. my @fld = split(":", $a[$i], 4);
  603. my %h;
  604. if($outf ne "-") {
  605. $fname[$i] = "$outf.$i";
  606. $h{fh} = new IO::File "> $fname[$i]";
  607. }
  608. $h{re} = $fld[1]; # Filter: regexp
  609. $h{df} = defined($fld[2]) ? $fld[2] : ""; # default value
  610. $h{fn} = $fld[3]; # function
  611. $h{didx} = 10 if($fld[3] && $fld[3] eq "delta-d"); # delta idx, substr len
  612. $h{didx} = 13 if($fld[3] && $fld[3] eq "delta-h");
  613. if($fld[0] =~ m/"(.*)"/o) {
  614. $h{col} = $1;
  615. $h{type} = 0;
  616. } else {
  617. $h{col} = $fld[0]-1;
  618. $h{type} = 1;
  619. }
  620. if($h{fn}) {
  621. $h{type} = 4;
  622. $h{type} = 2 if($h{didx});
  623. $h{type} = 3 if($h{fn} eq "int");
  624. }
  625. $h{ret} = "";
  626. $d[$i] = \%h;
  627. $min[$i] = 999999;
  628. $max[$i] = -999999;
  629. $sum[$i] = 0;
  630. $cnt[$i] = 0;
  631. $lastv[$i] = 0;
  632. $lastd[$i] = "undef";
  633. $firstv[$i] = 0;
  634. $firstd[$i] = "undef";
  635. $mind[$i] = "undef";
  636. $maxd[$i] = "undef";
  637. }
  638. my %lastdate;
  639. my $d; # Used by eval functions
  640. my ($rescan, $rescanNum, $rescanIdx, @rescanArr);
  641. $rescan = 0;
  642. RESCAN:
  643. for(;;) {
  644. my $l;
  645. if($rescan) {
  646. last if($rescanIdx<1 || !$rescanNum);
  647. $l = $rescanArr[$rescanIdx--];
  648. } else {
  649. $l = <$ifh> if($ifh);
  650. last if(!$l);
  651. if($reformatFn) { no strict; $l = &$reformatFn($l); use strict; }
  652. }
  653. next if($l lt $from && !$rescan);
  654. last if($l gt $to);
  655. my @fld = split("[ \r\n]+", $l); # 40% CPU
  656. for my $i (0..int(@a)-1) { # Process each req. field
  657. my $h = $d[$i];
  658. next if($rescan && $h->{ret});
  659. my @missingvals;
  660. next if($h->{re} && $l !~ m/$h->{re}/); # 20% CPU
  661. my $col = $h->{col};
  662. my $t = $h->{type};
  663. my $val = undef;
  664. my $dte = $fld[0];
  665. if($t == 0) { # Fixed text
  666. $val = $col;
  667. } elsif($t == 1) { # The column
  668. $val = $fld[$col] if(defined($fld[$col]));
  669. } elsif($t == 2) { # delta-h or delta-d
  670. next if($rescan);
  671. my $hd = $h->{didx}; # TimeStamp-Length
  672. my $ld = substr($fld[0],0,$hd); # TimeStamp-Part (hour or date)
  673. if(!defined($h->{last1}) || $h->{last3} ne $ld) {
  674. if(defined($h->{last1})) {
  675. my @lda = split("[_:]", $lastdate{$hd});
  676. my $ts = "12:00:00"; # middle timestamp
  677. $ts = "$lda[1]:30:00" if($hd == 13);
  678. my $v = $fld[$col]-$h->{last1};
  679. # $v = 0 if($v < 0); # Skip negative delta (why?)
  680. $dte = "$lda[0]_$ts";
  681. $val = sprintf("%g", $v);
  682. if($hd == 13) { # Generate missing 0 values / hour
  683. my @cda = split("[_:]", $ld);
  684. for(my $mi = $lda[1]+1; $mi < $cda[1]; $mi++) {
  685. push @missingvals, sprintf("%s_%02d:30:00 0\n", $lda[0], $mi);
  686. }
  687. }
  688. }
  689. $h->{last1} = $fld[$col];
  690. $h->{last3} = $ld;
  691. }
  692. $h->{last2} = $fld[$col];
  693. $lastdate{$hd} = $fld[0];
  694. } elsif($t == 3) { # int function
  695. $val = $1 if($fld[$col] =~ m/^(\d+).*/o);
  696. } else { # evaluate
  697. $cmdFromAnalyze = $h->{fn};
  698. $val = eval($cmdFromAnalyze);
  699. $cmdFromAnalyze = undef;
  700. }
  701. next if(!defined($val) || $val !~ m/^-?[.\d]+$/o);
  702. if($val < $min[$i]) {
  703. $min[$i] = $val;
  704. $mind[$i] = $dte;
  705. }
  706. if($val > $max[$i]) {
  707. $max[$i] = $val;
  708. $maxd[$i] = $dte;
  709. }
  710. $sum[$i] += $val;
  711. $cnt[$i]++;
  712. if($firstd[$i] eq "undef") {
  713. $firstv[$i] = $val;
  714. $firstd[$i] = $dte;
  715. }
  716. $lastv[$i] = $val;
  717. $lastd[$i] = $dte;
  718. map { $cnt[$i]++; $min[$i] = 0 if(0 < $min[$i]); } @missingvals;
  719. if($outf eq "-") {
  720. $h->{ret} .= "$dte $val\n";
  721. map { $h->{ret} .= $_ } @missingvals;
  722. } else {
  723. my $fh = $h->{fh}; # cannot use $h->{fh} in print directly
  724. print $fh "$dte $val\n";
  725. map { print $fh $_ } @missingvals;
  726. }
  727. $h->{count}++;
  728. $rescanNum--;
  729. last if(!$rescanNum);
  730. }
  731. }
  732. # If no value found for some of the required columns, then look for the last
  733. # matching entry outside of the range. Known as the "window left open
  734. # yesterday" problem
  735. if(!$rescan && $ifh) {
  736. $rescanNum = 0;
  737. map { $rescanNum++ if(!$d[$_]->{count} && $d[$_]->{df} eq "") } (0..$#a);
  738. if($rescanNum) {
  739. $rescan=1;
  740. my $buf;
  741. my $end = $hash->{pos}{"$inf:$from"};
  742. my $start = $end - 1024;
  743. $start = 0 if($start < 0);
  744. $ifh->seek($start, 0);
  745. sysread($ifh, $buf, $end-$start);
  746. @rescanArr = split("\n", $buf);
  747. $rescanIdx = $#rescanArr;
  748. goto RESCAN;
  749. }
  750. }
  751. $ifh->close() if($ifh);
  752. unlink($tempread) if($tempread);
  753. my $ret = "";
  754. for(my $i = 0; $i < int(@a); $i++) {
  755. my $h = $d[$i];
  756. my $hd = $h->{didx};
  757. if($hd && $lastdate{$hd}) {
  758. my $val = defined($h->{last1}) ? $h->{last2}-$h->{last1} : 0;
  759. $min[$i] = $val if($min[$i] == 999999);
  760. $max[$i] = $val if($max[$i] == -999999);
  761. $lastv[$i] = $val if(!$lastv[$i]);
  762. $sum[$i] = ($sum[$i] ? $sum[$i] + $val : $val);
  763. $cnt[$i]++;
  764. my @lda = split("[_:]", $lastdate{$hd});
  765. my $ts = "12:00:00"; # middle timestamp
  766. $ts = "$lda[1]:30:00" if($hd == 13);
  767. my $line = sprintf("%s_%s %0.1f\n", $lda[0],$ts,
  768. defined($h->{last1}) ? $h->{last2}-$h->{last1} : 0);
  769. if($outf eq "-") {
  770. $h->{ret} .= $line;
  771. } else {
  772. my $fh = $h->{fh};
  773. print $fh $line;
  774. $h->{count}++;
  775. }
  776. }
  777. if($outf eq "-") {
  778. $h->{ret} .= "$from $h->{df}\n" if(!$h->{ret} && $h->{df} ne "");
  779. $ret .= $h->{ret} if($h->{ret});
  780. $ret .= "#$a[$i]\n";
  781. } else {
  782. my $fh = $h->{fh};
  783. if(!$h->{count} && $h->{df} ne "") {
  784. print $fh "$from $h->{df}\n";
  785. }
  786. $fh->close();
  787. }
  788. my $j = $i+1;
  789. $data{"min$j"} = $min[$i];
  790. $data{"max$j"} = $max[$i];
  791. $data{"avg$j"} = $cnt[$i] ? sprintf("%0.1f", $sum[$i]/$cnt[$i]) : 0;
  792. $data{"sum$j"} = $sum[$i];
  793. $data{"cnt$j"} = $cnt[$i];
  794. $data{"currval$j"} = $lastv[$i];
  795. $data{"currdate$j"} = $lastd[$i];
  796. $data{"firstval$j"} = $firstv[$i];
  797. $data{"firstdate$j"} = $firstd[$i];
  798. $data{"mindate$j"} = $mind[$i];
  799. $data{"maxdate$j"} = $maxd[$i];
  800. $data{"lastraw$j"} = $h->{last2} if($h->{last2});
  801. Log3 $name, 4,
  802. "$name get: line $j, regexp:".$d[$i]->{re}.", col:".$d[$i]->{col}.
  803. ", output lines:".$data{"cnt$j"};
  804. }
  805. if($internal) {
  806. $internal_data = \$ret;
  807. return undef;
  808. }
  809. return ($outf eq "-") ? $ret : join(" ", @fname);
  810. }
  811. ###############
  812. # this is not elegant. Assume, that current seek pos is after a cr/nl
  813. sub
  814. seekBackOneLine($$)
  815. {
  816. my ($fh, $pos) = @_;
  817. my $buf;
  818. while($pos > 0) { # skip current CR/NL
  819. $fh->seek(--$pos, 0);
  820. $fh->read($buf, 1);
  821. last if($buf ne "\n" && $buf ne "\r");
  822. }
  823. $fh->seek($pos, 0);
  824. while($pos > 0 && $fh->read($buf, 1)) {
  825. return ++$pos if($buf eq "\n" || $buf eq "\r");
  826. $fh->seek(--$pos, 0);
  827. }
  828. return 0;
  829. }
  830. ###################################
  831. #($1-40587)*86400+$2
  832. sub
  833. FileLog_seekTo($$$$$)
  834. {
  835. my ($fname, $fh, $hash, $ts, $reformatFn) = @_;
  836. # If its cached
  837. if($hash->{pos} && $hash->{pos}{"$fname:$ts"}) {
  838. $fh->seek($hash->{pos}{"$fname:$ts"}, 0);
  839. return;
  840. }
  841. $fh->seek(0, 2); # Go to the end
  842. my $upper = $fh->tell;
  843. my ($lower, $next, $last) = (0, $upper/2, -1);
  844. for(my $iter=0; $iter<200; $iter++) { # Binary search
  845. if($next == $last) {
  846. $fh->seek($next, 0);
  847. last;
  848. }
  849. $fh->seek($next, 0);
  850. my $data = <$fh>;
  851. if(!$data) {
  852. $last = $next;
  853. last;
  854. }
  855. if($reformatFn) { no strict; $data = &$reformatFn($data); use strict; }
  856. if($data !~ m/^\d\d\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /o) {
  857. $next = seekBackOneLine($fh, $fh->tell);
  858. next;
  859. }
  860. $last = $next;
  861. if(!$data || $data lt $ts) {
  862. ($lower, $next) = ($next, int(($next+$upper)/2));
  863. } else {
  864. ($upper, $next) = ($next, int(($lower+$next)/2));
  865. }
  866. }
  867. $last = 0 if($last < 0); # Forum #46512
  868. $hash->{pos}{"$fname:$ts"} = $last;
  869. }
  870. sub
  871. FileLog_addTics($$)
  872. {
  873. my ($in, $p) = @_;
  874. return if(!$in || $in !~ m/^\((.*)\)$/);
  875. map { $p->{"\"$2\""}=1 if(m/^ *([^ ]+) ([^ ]+) */); } split(",",$1);
  876. }
  877. sub
  878. FileLog_sampleDataFn($$$$$)
  879. {
  880. my ($flName, $flog, $max, $conf, $wName) = @_;
  881. my $desc = "Input:Column,Regexp,DefaultValue,Function";
  882. my @htmlArr;
  883. my $fName = $defs{$flName}{currentlogfile};
  884. my $reformatFn = AttrVal($flName, "reformatFn", "");
  885. my $fh = new IO::File $fName;
  886. if(!$fh) {
  887. $fName = "<undefined>" if(!defined($fName));
  888. Log3 $wName, 1, "FileLog get sample data: $fName: $!";
  889. return ($desc, \@htmlArr, "");
  890. }
  891. $fh->seek(0, 2); # Go to the end
  892. my $sz = $fh->tell;
  893. $fh->seek($sz > 65536 ? $sz-65536 : 0, 0);
  894. my $data;
  895. $data = <$fh> if($sz > 65536); # discard the first/partial line
  896. my $maxcols = 0;
  897. my %h;
  898. while($data = <$fh>) {
  899. if($reformatFn) { no strict; $data = &$reformatFn($data); use strict; }
  900. my @cols = split(" ", $data);
  901. next if(@cols < 3);
  902. $maxcols = @cols if(@cols > $maxcols);
  903. $cols[2] = "*" if($cols[2] =~ m/^[-\.\d]+$/);
  904. $h{"$cols[1].$cols[2]"} = $data;
  905. $h{"$cols[1].*"} = "" if($cols[2] ne "*");
  906. }
  907. $fh->close();
  908. my $colnums = $maxcols;
  909. my $colregs = join(",", sort keys %h);
  910. my $example = join("<br>", grep /.+/,map { $h{$_} } sort keys %h);
  911. $colnums = join(",", 3..$colnums);
  912. my %tickh;
  913. FileLog_addTics($conf->{ytics}, \%tickh);
  914. FileLog_addTics($conf->{y2tics}, \%tickh);
  915. $colnums = join(",", sort keys %tickh).",$colnums" if(%tickh);
  916. for(my $r=0; $r < $max; $r++) {
  917. my @f = split(":", ($flog->[$r] ? $flog->[$r] : ":::"), 4);
  918. my $ret = "";
  919. $f[1] =~ s/\\x(..)/chr(hex($1))/ge; # Convert \x3a to :
  920. $colregs .= ",$f[1]" if($f[1] && !$h{$f[1]});
  921. $ret .= SVG_sel("par_${r}_0", $colnums, $f[0], undef, "svgColumn");
  922. $ret .= SVG_sel("par_${r}_1", $colregs, $f[1], undef, "svgRegexp");
  923. $ret .= SVG_txt("par_${r}_2", "", $f[2], 2);
  924. $ret .= SVG_txt("par_${r}_3", "", $f[3],10);
  925. push @htmlArr, $ret;
  926. }
  927. return ($desc, \@htmlArr, $example);
  928. }
  929. sub
  930. FileLog_regexpFn($$)
  931. {
  932. my ($name, $filter) = @_;
  933. $filter = " $filter ";
  934. $filter =~ s/ [^: ]*:/ /g;
  935. $filter =~ s/:[^ ]* / /g;
  936. $filter =~ s/(^ | $)//g;
  937. $filter =~ s/ /|/g;
  938. return $filter;
  939. }
  940. 1;
  941. =pod
  942. =item helper
  943. =item summary log events to a file
  944. =item summary_DE schreibt Events in eine Logdatei
  945. =begin html
  946. <a name="FileLog"></a>
  947. <h3>FileLog</h3>
  948. <ul>
  949. <br>
  950. <a name="FileLogdefine"></a>
  951. <b>Define</b>
  952. <ul>
  953. <code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code>
  954. <br><br>
  955. Log events to <code>&lt;filename&gt;</code>. The log format is
  956. <ul><code><br>
  957. YYYY-MM-DD_HH:MM:SS &lt;device&gt; &lt;event&gt;<br>
  958. <br></code></ul>
  959. The regexp will be checked against the device name
  960. devicename:event or timestamp:devicename:event combination.
  961. The regexp must match the complete string, not just a part of it.
  962. <br>
  963. <code>&lt;filename&gt;</code> may contain %-wildcards of the
  964. POSIX strftime function of the underlying OS (see your strftime manual).
  965. Common used wildcards are:
  966. <ul>
  967. <li><code>%d</code> day of month (01..31)</li>
  968. <li><code>%m</code> month (01..12)</li>
  969. <li><code>%Y</code> year (1970...)</li>
  970. <li><code>%w</code> day of week (0..6); 0 represents Sunday</li>
  971. <li><code>%j</code> day of year (001..366)</li>
  972. <li><code>%U</code> week number of year with Sunday as first day of week (00..53)</li>
  973. <li><code>%W</code> week number of year with Monday as first day of week (00..53)</li>
  974. </ul>
  975. FHEM also replaces <code>%L</code> by the value of the global logdir attribute.<br>
  976. Before using <code>%V</code> for ISO 8601 week numbers check if it is
  977. correctly supported by your system (%V may not be replaced, replaced by an
  978. empty string or by an incorrect ISO-8601 week number, especially
  979. at the beginning of the year)
  980. If you use <code>%V</code> you will also have to use %G
  981. instead of %Y for the year!<br>
  982. If readonly is specified, then the file is used only for visualisation, and
  983. it is not opened for writing.
  984. Examples:
  985. <ul>
  986. <code>define lamplog FileLog %L/lamp.log lamp</code><br>
  987. <code>define wzlog FileLog ./log/wz-%Y-%U.log
  988. wz:(measured-temp|actuator).*</code><br>
  989. With ISO 8601 week numbers, if supported:<br>
  990. <code>define wzlog FileLog ./log/wz-%G-%V.log
  991. wz:(measured-temp|actuator).*</code><br>
  992. </ul>
  993. <br>
  994. </ul>
  995. <a name="FileLogset"></a>
  996. <b>Set </b>
  997. <ul>
  998. <li>reopen
  999. <ul>
  1000. Reopen a FileLog after making some manual changes to the
  1001. logfile.
  1002. </ul>
  1003. </li>
  1004. <li>clear
  1005. <ul>
  1006. Clears and reopens the logfile.
  1007. </ul>
  1008. </li>
  1009. <li>addRegexpPart &lt;device&gt; &lt;regexp&gt;
  1010. <ul>
  1011. add a regexp part, which is constructed as device:regexp. The parts
  1012. are separated by |. Note: as the regexp parts are resorted, manually
  1013. constructed regexps may become invalid.
  1014. </ul>
  1015. </li>
  1016. <li>removeRegexpPart &lt;re&gt;
  1017. <ul>
  1018. remove a regexp part. Note: as the regexp parts are resorted, manually
  1019. constructed regexps may become invalid.<br>
  1020. The inconsistency in addRegexpPart/removeRegexPart arguments originates
  1021. from the reusage of javascript functions.
  1022. </ul>
  1023. </li>
  1024. <li>absorb secondFileLog
  1025. <ul>
  1026. merge the current and secondFileLog into one file, add the regexp of the
  1027. secondFileLog to the current one, and delete secondFileLog.<br>
  1028. This command is needed to create combined plots (weblinks).<br>
  1029. <b>Notes:</b>
  1030. <ul>
  1031. <li>secondFileLog will be deleted (i.e. the FHEM definition).</li>
  1032. <li>only the current files will be merged.</li>
  1033. <li>weblinks using secondFilelog will become broken, they have to be
  1034. adopted to the new logfile or deleted.</li>
  1035. </ul>
  1036. </ul>
  1037. </li>
  1038. <br>
  1039. </ul>
  1040. <br>
  1041. <a name="FileLogget"></a>
  1042. <b>Get</b>
  1043. <ul>
  1044. <code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
  1045. &lt;to&gt; &lt;column_spec&gt; </code>
  1046. <br><br>
  1047. Read data from the logfile, used by frontends to plot data without direct
  1048. access to the file.<br>
  1049. <ul>
  1050. <li>&lt;infile&gt;<br>
  1051. Name of the logfile to open. Special case: "-" is the currently active
  1052. logfile, "CURRENT" opens the file corresponding to the "from"
  1053. parameter.
  1054. </li>
  1055. <li>&lt;outfile&gt;<br>
  1056. If it is "-", you get the data back on the current connection, else it
  1057. is the prefix for the output file. If more than one file is specified,
  1058. the data is separated by a comment line for "-", else it is written in
  1059. separate files, numerated from 0.
  1060. </li>
  1061. <li>&lt;from&gt; &lt;to&gt;<br>
  1062. Used to grep the data. The elements should correspond to the
  1063. timeformat or be an initial substring of it.</li>
  1064. <li>&lt;column_spec&gt;<br>
  1065. For each column_spec return a set of data in a separate file or
  1066. separated by a comment line on the current connection.<br>
  1067. Syntax: &lt;col&gt;:&lt;regexp&gt;:&lt;default&gt;:&lt;fn&gt;<br>
  1068. <ul>
  1069. <li>&lt;col&gt;
  1070. The column number to return, starting at 1 with the date.
  1071. If the column is enclosed in double quotes, then it is a fix text,
  1072. not a column number.</li>
  1073. <li>&lt;regexp&gt;
  1074. If present, return only lines containing the regexp. Case sensitive.
  1075. </li>
  1076. <li>&lt;default&gt;<br>
  1077. If no values were found and the default value is set, then return
  1078. one line containing the from value and this default. We need this
  1079. feature as gnuplot aborts if a dataset has no value at all.
  1080. </li>
  1081. <li>&lt;fn&gt;
  1082. One of the following:
  1083. <ul>
  1084. <li>int<br>
  1085. Extract the integer at the beginning og the string. Used e.g.
  1086. for constructs like 10%</li>
  1087. <li>delta-h or delta-d<br>
  1088. Return the delta of the values for a given hour or a given day.
  1089. Used if the column contains a counter, as is the case for the
  1090. KS300 rain column.</li>
  1091. <li>everything else<br>
  1092. The string is evaluated as a perl expression. @fld is the
  1093. current line splitted by spaces. Note: The string/perl
  1094. expression cannot contain spaces, as the part after the space
  1095. will be considered as the next column_spec.</li>
  1096. </ul></li>
  1097. </ul></li>
  1098. </ul>
  1099. <br><br>
  1100. Example:
  1101. <ul><code><br>
  1102. get outlog out-2008.log - 2008-01-01 2008-01-08 4:IR:int: 9:IR::
  1103. </code></ul>
  1104. <br>
  1105. </ul>
  1106. <a name="FileLogattr"></a>
  1107. <b>Attributes</b>
  1108. <ul>
  1109. <li><a href="#addStateEvent">addStateEvent</a></li><br><br>
  1110. <a name="archivedir"></a>
  1111. <a name="archivecmd"></a>
  1112. <a name="nrarchive"></a>
  1113. <li>archivecmd / archivedir / nrarchive<br>
  1114. When a new FileLog file is opened, the FileLog archiver wil be called.
  1115. This happens only, if the name of the logfile has changed (due to
  1116. time-specific wildcards, see the <a href="#FileLog">FileLog</a>
  1117. section), and there is a new entry to be written into the file.
  1118. <br>
  1119. If the attribute archivecmd is specified, then it will be started as a
  1120. shell command (no enclosing " is needed), and each % in the command
  1121. will be replaced with the name of the old logfile.<br>
  1122. If this attribute is not set, but nrarchive is set, then nrarchive old
  1123. logfiles are kept along the current one while older ones are moved to
  1124. archivedir (or deleted if archivedir is not set).<br>
  1125. Note: "old" means here the first ones in the alphabetically soreted
  1126. list. <br>
  1127. Note: setting these attributes for the global instance will effect the
  1128. <a href="#logfile">FHEM logfile</a> only.
  1129. </li><br>
  1130. <a name="archiveCompress"></a>
  1131. <li>archiveCompress<br>
  1132. If nrarchive, archivedir and archiveCompress is set, then the files
  1133. in the archivedir will be compressed.
  1134. </li><br>
  1135. <a name="createGluedFile"></a>
  1136. <li>createGluedFile<br>
  1137. If set (to 1), and the SVG-Plot requests a time-range wich is stored
  1138. in two files, a temporary file with the content of both files will be
  1139. created, in order to satisfy the request.
  1140. </li><br>
  1141. <li><a href="#disable">disable</a></li>
  1142. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  1143. <br>
  1144. <a name="eventOnThreshold"></a>
  1145. <li>eventOnThreshold<br>
  1146. If set (to a nonzero number), the event linesInTheFile will be
  1147. generated, if the lines in the file is a multiple of the set number.
  1148. Note: the counter is only correct for files created after this
  1149. feature was implemented. A FHEM crash or kill will falsify the counter.
  1150. </li><br>
  1151. <a name="logtype"></a>
  1152. <li>logtype<br>
  1153. Used by the pgm2 webfrontend to offer gnuplot/SVG images made from the
  1154. logs. The string is made up of tokens separated by comma (,), each
  1155. token specifies a different gnuplot program. The token may contain a
  1156. colon (:), the part before the colon defines the name of the program,
  1157. the part after is the string displayed in the web frontend. Currently
  1158. following types of gnuplot programs are implemented:<br>
  1159. <ul>
  1160. <li>fs20<br>
  1161. Plots on as 1 and off as 0. The corresponding filelog definition
  1162. for the device fs20dev is:<br>
  1163. define fslog FileLog log/fs20dev-%Y-%U.log fs20dev
  1164. </li>
  1165. <li>fht<br>
  1166. Plots the measured-temp/desired-temp/actuator lines. The
  1167. corresponding filelog definitions (for the FHT device named
  1168. fht1) looks like:<br>
  1169. <code>define fhtlog1 FileLog log/fht1-%Y-%U.log fht1:.*(temp|actuator).*</code>
  1170. </li>
  1171. <li>temp4rain10<br>
  1172. Plots the temperature and rain (per hour and per day) of a
  1173. ks300. The corresponding filelog definitions (for the KS300
  1174. device named ks300) looks like:<br>
  1175. define ks300log FileLog log/fht1-%Y-%U.log ks300:.*H:.*
  1176. </li>
  1177. <li>hum6wind8<br>
  1178. Plots the humidity and wind values of a
  1179. ks300. The corresponding filelog definition is the same as
  1180. above, both programs evaluate the same log.
  1181. </li>
  1182. <li>text<br>
  1183. Shows the logfile as it is (plain text). Not gnuplot definition
  1184. is needed.
  1185. </li>
  1186. </ul>
  1187. Example:<br>
  1188. attr ks300log1 logtype
  1189. temp4rain10:Temp/Rain,hum6wind8:Hum/Wind,text:Raw-data
  1190. </li><br>
  1191. <li><a href="#mseclog">mseclog</a></li><br>
  1192. <a name="reformatFn"></a>
  1193. <li>reformatFn<br>
  1194. used to convert "foreign" logfiles for the SVG Module, contains the
  1195. name(!) of a function, which will be called with a "raw" line from the
  1196. original file, and has to return a line in "FileLog" format.<br>
  1197. E.g. to visualize the NTP loopstats, set reformatFn to ntpLoopstats, and
  1198. copy the following into your 99_myUtils.pm:
  1199. <pre><code>
  1200. sub
  1201. ntpLoopstats($)
  1202. {
  1203. my ($d) = @_;
  1204. return $d if($d !~ m/^(\d{5}) (\d+)\.(\d{3}) (.*)$/);
  1205. my ($r, $t) = ($4, FmtDateTime(($1-40587)*86400+$2));
  1206. $t =~ s/ /_/;
  1207. return "$t ntpLoopStats $r";
  1208. }</code></pre>
  1209. </li>
  1210. </ul>
  1211. <br>
  1212. </ul>
  1213. =end html
  1214. =begin html_DE
  1215. <a name="FileLog"></a>
  1216. <h3>FileLog</h3>
  1217. <ul>
  1218. <br>
  1219. <a name="FileLogdefine"></a>
  1220. <b>Define</b>
  1221. <ul>
  1222. <code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code>
  1223. <br><br>
  1224. Speichert Ereignisse in einer Log-Datei mit Namen <code>&lt;filename&gt;</code>. Das Log-Format ist
  1225. <ul><code><br>
  1226. YYYY-MM-DD_HH:MM:SS &lt;device&gt; &lt;event&gt;<br>
  1227. <br></code></ul>
  1228. Der Ausdruck unter regexp wird anhand des Ger&auml;tenames &uuml;berpr&uuml;ft und zwar
  1229. devicename:event oder der timestamp:devicename:event-Kombination.
  1230. Der regexp muss mit dem kompletten String &uuml;bereinstimmen und nicht nur teilweise.
  1231. <br>
  1232. <code>&lt;filename&gt;</code> k&ouml;nnen %-wildcards der POSIX
  1233. strftime-Funktion des darunterliegenden OS enthalten (siehe auch strftime
  1234. Beschreibung).
  1235. Allgemein gebr&auml;uchliche Wildcards sind:
  1236. <ul>
  1237. <li><code>%d</code> Tag des Monats (01..31)</li>
  1238. <li><code>%m</code> Monat (01..12)</li>
  1239. <li><code>%Y</code> Jahr (1970...)</li>
  1240. <li><code>%w</code> Wochentag (0..6); beginnend mit Sonntag (0)</li>
  1241. <li><code>%j</code> Tag des Jahres (001..366)</li>
  1242. <li><code>%U</code> Wochennummer des Jahres, wobei Wochenbeginn = Sonntag (00..53)</li>
  1243. <li><code>%W</code> Wochennummer des Jahres, wobei Wochenbeginn = Montag (00..53)</li>
  1244. </ul>
  1245. FHEM ersetzt <code>%L</code> mit dem Wert des global logdir Attributes.<br>
  1246. Bevor <code>%V</code> f&uuml;r ISO 8601 Wochennummern verwendet werden,
  1247. muss &uuml;berpr&uuml;ft werden, ob diese Funktion durch das Brriebssystem
  1248. unterst&uuml;tzt wird (Es kann sein, dass %V nicht umgesetzt wird, durch
  1249. einen Leerstring ersetzt wird oder durch eine falsche ISO-Wochennummer
  1250. dargestellt wird - besonders am Jahresanfang)
  1251. Bei der Verwendung von <code>%V</code> muss gleichzeitig f&uuml;r das Jahr
  1252. ein <code>%G</code> anstelle von <code>%Y</code> benutzt werden.<br>
  1253. Falls man readonly spezifiziert, dann wird die Datei nur zum visualisieren
  1254. verwendet, und nicht zum Schreiben ge&ouml;ffnet.
  1255. <br>
  1256. Beispiele:
  1257. <ul>
  1258. <code>define lamplog FileLog %L/lamp.log lamp</code><br>
  1259. <code>define wzlog FileLog ./log/wz-%Y-%U.log
  1260. wz:(measured-temp|actuator).*</code><br>
  1261. Mit ISO 8601 Wochennummern falls unterst&uuml;tzt:<br>
  1262. <code>define wzlog FileLog ./log/wz-%G-%V.log
  1263. wz:(measured-temp|actuator).*</code><br>
  1264. </ul>
  1265. <br>
  1266. </ul>
  1267. <a name="FileLogset"></a>
  1268. <b>Set </b>
  1269. <ul>
  1270. <li>reopen
  1271. <ul>
  1272. Erneutes &Ouml;ffnen eines FileLogs nach h&auml;ndischen
  1273. &Auml;nderungen in dieser Datei.
  1274. </ul></li>
  1275. <li>clear
  1276. <ul>
  1277. L&ouml;schen und erneutes &Ouml;ffnen eines FileLogs.
  1278. </ul></li>
  1279. <li>addRegexpPart &lt;device&gt; &lt;regexp&gt;
  1280. <ul>
  1281. F&uuml;gt ein regexp Teil hinzu, der als device:regexp aufgebaut ist.
  1282. Die Teile werden nach Regexp-Regeln mit | getrennt. Achtung: durch
  1283. hinzuf&uuml;gen k&ouml;nnen manuell erzeugte Regexps ung&uuml;ltig
  1284. werden.
  1285. </ul></li>
  1286. <li>removeRegexpPart &lt;re&gt;
  1287. <ul>
  1288. Entfernt ein regexp Teil. Die Inkonsistenz von addRegexpPart /
  1289. removeRegexPart-Argumenten hat seinen Ursprung in der Wiederverwendung
  1290. von Javascript-Funktionen.
  1291. </ul></li>
  1292. <li>absorb secondFileLog
  1293. <ul>
  1294. F&uuml;hrt den gegenw&auml;rtigen Log und den secondFileLog zu einer
  1295. gemeinsamen Datei zusammen, f&uuml;gt danach die regexp des
  1296. secondFileLog dem gegenw&auml;rtigen Filelog hinzu und l&ouml;scht dann
  1297. anschlie&szlig;end das secondFileLog.<br>
  1298. Dieses Komanndo wird zur Erzeugung von kombinierten Plots (weblinks)
  1299. ben&ouml;tigt.<br>
  1300. <b>Hinweise:</b>
  1301. <ul>
  1302. <li>secondFileLog wird gel&ouml;scht (d.h. die FHEM-Definition und
  1303. die Datei selbst).</li>
  1304. <li>nur das aktuelle File wird zusammengef&uuml;hrt, keine
  1305. archivierten Versionen.</li>
  1306. <li>Weblinks, die das secondFilelog benutzen werden unbrauchbar, sie
  1307. m&uuml;ssen deshalb auf das neue Logfile angepasst oder
  1308. gel&ouml;scht werden.</li>
  1309. </ul>
  1310. </ul></li>
  1311. <br>
  1312. </ul>
  1313. <br>
  1314. <a name="FileLogget"></a>
  1315. <b>Get</b>
  1316. <ul>
  1317. <code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
  1318. &lt;to&gt; &lt;column_spec&gt; </code>
  1319. <br><br>
  1320. Liest Daten aus einem Logfile und wird von einem Frontend ben&ouml;tigt, um
  1321. Daten ohne direkten Zugriff aus der Datei zu lesen.<br>
  1322. <ul>
  1323. <li>&lt;infile&gt;<br>
  1324. Name des Logfiles, auf das zugegriffen werden soll. Sonderf&auml;lle:
  1325. "-" steht f&uuml;r das aktuelle Logfile, und "CURRENT" &ouml;ffnet die
  1326. zum "from" passende Datei.</li>
  1327. <li>&lt;outfile&gt;<br>
  1328. Bei einem "-", bekommt man die Daten auf der aktuellen Verbindung
  1329. zur&uuml;ck, anderenfall ist es das Name (eigentlich Prefix, s.u.) des
  1330. Output-Files. Wenn mehr als ein File angesprochen wird, werden die
  1331. einzelnen Dateinamen durch ein "-" getrennt, anderenfalls werden die
  1332. Daten in einzelne Dateien geschrieben, die - beginnend mit 0 -
  1333. durchnummeriert werden.
  1334. </li>
  1335. <li>&lt;from&gt; &lt;to&gt;<br>
  1336. Bezeichnet den gew&uuml;nschten Datenbereich. Die beiden Elemente
  1337. m&uuml;ssen ganz oder mit dem Anfang des Zeitformates
  1338. &uuml;bereinstimmen.</li>
  1339. <li>&lt;column_spec&gt;<br>
  1340. Jede column_spec sendet die gew&uuml;nschten Daten entweder in eine
  1341. gesonderte Datei oder &uuml;ber die gegenw&auml;rtige Verbindung durch
  1342. "-" getrennt.<br>
  1343. Syntax: &lt;col&gt;:&lt;regexp&gt;:&lt;default&gt;:&lt;fn&gt;<br>
  1344. <ul>
  1345. <li>&lt;col&gt;
  1346. gibt die Spaltennummer zur&uuml;ck, beginnend mit 1 beim Datum.
  1347. Wenn die Spaltenmummer in doppelten Anf&uuml;hrungszeichen steht,
  1348. handelt es sich um einen festen Text und nicht um eine
  1349. Spaltennummer.</li>
  1350. <li>&lt;regexp&gt;
  1351. gibt, falls vorhanden, Zeilen mit Inhalten von regexp zur&uuml;ck.
  1352. Gro&szlig;- und Kleinschreibung beachten. </li>
  1353. <li>&lt;default&gt;<br>
  1354. Wenn keine Werte gefunden werden, und der Default-Wert
  1355. (Voreinstellung) wurde gesetzt, wird eine Zeile zur&uuml;ckgegeben,
  1356. die den von-Wert (from) und diesen Default-Wert enth&auml;lt.
  1357. Dieses Leistungsmerkmal ist notwendig, da gnuplot abbricht, wenn
  1358. ein Datensatz keine Daten enth&auml;lt.
  1359. </li>
  1360. <li>&lt;fn&gt;
  1361. Kann folgende Inhalte haben:
  1362. <ul>
  1363. <li>int<br>
  1364. L&ouml;st den Integer-Wert zu Beginn eines Strings heraus. Wird
  1365. z.B. bei 10% gebraucht.</li>
  1366. <li>delta-h oder delta-d<br>
  1367. Gibt nur den Unterschied der Werte-Spalte pro
  1368. Stunde oder pro Tag aus. Wird ben&ouml;tigt, wenn die Spalte
  1369. einen Z&auml;hler enth&auml;lt, wie im Falles des KS300 in der
  1370. Spalte f&uuml;r die Regenmenge.</li>
  1371. <li>alles andere<br>
  1372. Dieser String wird als Perl-Ausdruck ausgewertet. @fld enthaelt
  1373. die aktuelle Zeile getrennt durch Leerzeichen. Achtung:
  1374. Dieser String/Perl-Ausdruck darf keine Leerzeichen enthalten.
  1375. </li>
  1376. </ul></li>
  1377. </ul></li>
  1378. </ul>
  1379. <br><br>
  1380. Beispiel:
  1381. <ul><code><br>
  1382. get outlog out-2008.log - 2008-01-01 2008-01-08 4:IR:int: 9:IR::
  1383. </code></ul>
  1384. <br>
  1385. </ul>
  1386. <a name="FileLogattr"></a>
  1387. <b>Attribute</b>
  1388. <ul>
  1389. <li><a href="#addStateEvent">addStateEvent</a></li><br><br>
  1390. <a name="archivedir"></a>
  1391. <a name="archivecmd"></a>
  1392. <a name="nrarchive"></a>
  1393. <li>archivecmd / archivedir / nrarchive<br>
  1394. Wenn eine neue FileLog-Datei ge&ouml;ffnet wird, wird der FileLog
  1395. archiver aufgerufen. Das geschieht aber nur , wenn der Name der Datei
  1396. sich ge&auml;ndert hat(abh&auml;ngig von den zeitspezifischen
  1397. Wildcards, die weiter oben unter <a href="#FileLogdefine">FileLog
  1398. (define)</a> beschrieben werden) und gleichzeitig ein neuer Datensatz
  1399. in diese Datei geschrieben werden muss. <br>
  1400. Wenn das Attribut archivecmd benutzt wird, startet es als
  1401. shell-Kommando ( eine Einbettung in " ist nicht notwendig), und jedes %
  1402. in diesem Befehl wird durch den Namen des alten Logfiles ersetzt.<br>
  1403. Wenn dieses Attribut nicht gesetzt wird, aber daf&uuml;r nrarchive,
  1404. werden nrarchive viele Logfiles im aktuellen Verzeichnis gelassen, und
  1405. &auml;ltere Dateien in das Archivverzeichnis (archivedir) verschoben
  1406. (oder gel&ouml;scht, falls kein archivedir gesetzt wurde).<br>
  1407. Achtung: "&auml;ltere Dateien" sind die, die in der alphabetisch
  1408. sortierten Liste oben sind.<br>
  1409. Hinweis: Werden diese Attribute als global instance gesetzt, hat das
  1410. auschlie&szlig;lich auf das <a href="#logfile">FHEM logfile</a>
  1411. Auswirkungen. </li><br>
  1412. <a name="archiveCompress"></a>
  1413. <li>archiveCompress<br>
  1414. Falls nrarchive, archivedir und archiveCompress gesetzt ist, dann
  1415. werden die Dateien im archivedir komprimiert abgelegt.
  1416. </li><br>
  1417. <a name="createGluedFile"></a>
  1418. <li>createGluedFile<br>
  1419. Falls gesetzt (1), und im SVG-Plot ein Zeitbereich abgefragt wird, was
  1420. in zwei Logdateien gespeichert ist, dann wird f&uuml;r die Anfrage eine
  1421. tempor&auml;re Datei mit dem Inhalt der beiden Dateien erzeugt.
  1422. </li><br>
  1423. <li><a href="#disable">disable</a></li>
  1424. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  1425. <br>
  1426. <a name="eventOnThreshold"></a>
  1427. <li>eventOnThreshold<br>
  1428. Falls es auf eine (nicht Null-) Zahl gesetzt ist, dann wird das
  1429. linesInTheFile Event generiert, falls die Anzahl der Zeilen in der
  1430. Datei ein Mehrfaches der gesetzen Zahl ist. Achtung: der Z&auml;hler ist
  1431. nur f&uuml;r solche Dateien korrekt, die nach dem Impementieren dieses
  1432. Features angelegt wurden. Ein Absturz/Abschu&szlig; von FHEM
  1433. verf&auml;lscht die Z&auml;hlung.
  1434. </li><br>
  1435. <a name="logtype"></a>
  1436. <li>logtype<br>
  1437. Wird vom SVG Modul ben&ouml;tigt, um daten grafisch aufzubereiten.
  1438. Der String wird aus komma-separierten Tokens
  1439. (,) erzeugt, wobei jeder Token ein eigenes gnuplot-Programm bezeichnet.
  1440. Die Token k&ouml;nnen Doppelpunkte (:) enthalten. Der Teil vor dem
  1441. Doppelpunkt bezeichnet den Namen des Programms; der Teil nach dem
  1442. Doppelpunkt ist der String, der im Web.Frontend dargestellt werden
  1443. soll. Gegenw&auml;rtig sind folgende Typen von gnuplot-Programmen
  1444. implementiert:<br>
  1445. <ul>
  1446. <li>fs20<br>
  1447. Zeichnet on als 1 and off als 0. Die geeignete
  1448. filelog-Definition f&uuml;r das Ger&auml;t fs20dev lautet:<br>
  1449. define fslog FileLog log/fs20dev-%Y-%U.log fs20dev
  1450. </li>
  1451. <li>fht<br>
  1452. Zeichnet die Ist-Temperatur/Soll-temperatur/Aktor Kurven. Die
  1453. passende FileLog-Definition (f&uuml;r das FHT-Ger&auml;t mit
  1454. Namen fht1)sieht wie folgt aus: <br>
  1455. <code>define fhtlog1 FileLog log/fht1-%Y-%U.log
  1456. fht1:.*(temp|actuator).*</code>
  1457. </li>
  1458. <li>temp4rain10<br>
  1459. Zeichnet eine Kurve aus der Temperatur und dem Niederschlag (pro
  1460. Stunde und pro Tag) eines KS300. Die dazu passende
  1461. FileLog-Definition (f&uuml;r das KS300
  1462. Ger&auml;t mit Namen ks300) sieht wie folgt aus:<br>
  1463. define ks300log FileLog log/fht1-%Y-%U.log ks300:.*H:.*
  1464. </li>
  1465. <li>hum6wind8<br>
  1466. Zeichnet eine Kurve aus der Feuchtigkeit und der
  1467. Windgeschwindigkeit eines ks300. Die geeignete
  1468. FileLog-Definition ist identisch mit der vorhergehenden
  1469. Definition. Beide programme erzeugen das gleiche Log.
  1470. </li>
  1471. <li>text<br>
  1472. Zeigt das LogFile in seiner urspr&uuml;nglichen Form (Nur
  1473. Text).Eine gnuplot-Definition ist nicht notwendig.
  1474. </li>
  1475. </ul>
  1476. Beispiel:<br> attr ks300log1 logtype
  1477. temp4rain10:Temp/Rain,hum6wind8:Hum/Wind,text:Raw-data
  1478. </li><br>
  1479. <li><a href="#mseclog">mseclog</a></li><br>
  1480. <a name="reformatFn"></a>
  1481. <li>reformatFn<br>
  1482. wird verwendet, um "fremde" Dateien f&uuml;r die SVG-Anzeige ins
  1483. FileLog-Format zu konvertieren. Es enth&auml;lt nur den Namen einer
  1484. Funktion, der mit der urspr&uuml;nglichen Zeile aufgerufen wird. Z.Bsp.
  1485. um die NTP loopstats Datei zu visualisieren kann man den Wert von
  1486. reformatFn auf ntpLoopstats setzen, und folgende Funktion in
  1487. 99_myUtils.pm definieren:
  1488. <pre><code>
  1489. sub
  1490. ntpLoopstats($)
  1491. {
  1492. my ($d) = @_;
  1493. return $d if($d !~ m/^(\d{5}) (\d+)\.(\d{3}) (.*)$/);
  1494. my ($r, $t) = ($4, FmtDateTime(($1-40587)*86400+$2));
  1495. $t =~ s/ /_/;
  1496. return "$t ntpLoopStats $r";
  1497. }</code></pre>
  1498. </li>
  1499. </ul>
  1500. <br>
  1501. </ul>
  1502. =end html_DE
  1503. =cut