92_FileLog.pm 55 KB

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