92_FileLog.pm 54 KB

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