FileLog: add acceptedRange attribute and reformat doc (Forum #126381)

git-svn-id: https://svn.fhem.de/fhem/trunk@25744 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-02-26 11:49:43 +00:00
parent 3a4007e617
commit b5e0375b4c

View File

@ -42,6 +42,7 @@ FileLog_Initialize($)
# logtype is used by the frontend # logtype is used by the frontend
no warnings 'qw'; no warnings 'qw';
my @attrList = qw( my @attrList = qw(
acceptedRange
addLog addLog
addStateEvent:0,1 addStateEvent:0,1
archiveCompress archiveCompress
@ -304,6 +305,7 @@ FileLog_Log($$)
my $written = 0; my $written = 0;
my $fmt = AttrVal($ln, "outputFormat", undef); my $fmt = AttrVal($ln, "outputFormat", undef);
my $emi = $log->{".filelog-event-min-interval"}; my $emi = $log->{".filelog-event-min-interval"};
my $ar = $log->{".acceptedRange"};
my $al = $log->{".addLog"}; my $al = $log->{".addLog"};
for (my $i = 0; $i < $max; $i++) { for (my $i = 0; $i < $max; $i++) {
@ -324,10 +326,24 @@ FileLog_Log($$)
} }
} }
} }
if($al && $al->{$n} && $s =~ m/^([^:]+):/) { if($al && $al->{$n} && $s =~ m/^([^:]+):/) {
my $ale = $al->{$n}{$1}; my $ale = $al->{$n}{$1};
$ale->{LAST} = time_str2num($t) if($ale); $ale->{LAST} = time_str2num($t) if($ale);
} }
if($ar) {
my $doSkip=0;
my @sa = split(" ", $s);
for my $col (keys %{$ar}) {
next if($col > int(@sa));
my $val = $sa[$col];
next if(!looks_like_number($val));
$doSkip = 1 if($val < $ar->{$col}{min} || $val > $ar->{$col}{max});
}
next if($doSkip);
}
$t =~ s/ /_/; # Makes it easier to parse with gnuplot $t =~ s/ /_/; # Makes it easier to parse with gnuplot
if(!$switched) { if(!$switched) {
@ -374,6 +390,20 @@ FileLog_Attr(@)
return; return;
} }
if($a[2] eq "acceptedRange") {
if($a[0] eq "del") {
delete($defs{$a[1]}{".acceptedRange"});
return;
}
my %ar; # colX:min:max
my $in = $a[3];
$in =~ s/\b(\d+):([0-9.-]+):([0-9.-]+)\b/
$ar{$1}{min}=$2; $ar{$1}{max}=$3; ""/ge;
return "Bad argument $in" if($in !~ m/^ *$/);
$defs{$a[1]}{".acceptedRange"} = \%ar;
}
if($a[0] eq "set" && $a[2] eq "ignoreRegexp") { if($a[0] eq "set" && $a[2] eq "ignoreRegexp") {
return "Missing argument for ignoreRegexp" if(!defined($a[3])); return "Missing argument for ignoreRegexp" if(!defined($a[3]));
eval { "HALLO" =~ m/$a[3]/ }; eval { "HALLO" =~ m/$a[3]/ };
@ -1289,12 +1319,12 @@ FileLog_regexpFn($$)
=item summary_DE schreibt Events in eine Logdatei =item summary_DE schreibt Events in eine Logdatei
=begin html =begin html
<a name="FileLog"></a> <a id="FileLog"></a>
<h3>FileLog</h3> <h3>FileLog</h3>
<ul> <ul>
<br> <br>
<a name="FileLogdefine"></a> <a id="FileLog-define"></a>
<b>Define</b> <b>Define</b>
<ul> <ul>
<code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code> <code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code>
@ -1342,7 +1372,7 @@ FileLog_regexpFn($$)
<br> <br>
</ul> </ul>
<a name="FileLogset"></a> <a id="FileLog-set"></a>
<b>Set </b> <b>Set </b>
<ul> <ul>
<li>reopen <li>reopen
@ -1390,7 +1420,7 @@ FileLog_regexpFn($$)
<br> <br>
<a name="FileLogget"></a> <a id="FileLog-get"></a>
<b>Get</b> <b>Get</b>
<ul> <ul>
<code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt; <code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
@ -1458,12 +1488,19 @@ FileLog_regexpFn($$)
<br> <br>
</ul> </ul>
<a name="FileLogattr"></a> <a id="FileLog-attr"></a>
<b>Attributes</b> <b>Attributes</b>
<ul> <ul>
<li><a href="#addStateEvent">addStateEvent</a></li><br><br> <li><a href="#addStateEvent">addStateEvent</a></li><br><br>
<a name="addLog"></a> <a id="FileLog-attr-acceptedRange"></a>
<li>acceptedRange col1:min:max ...<br>
This attribute takes a space separated list of ranges. An event wont
be logged, if the column of the event (counted from 0) is a number, and
it is outside of the specified range.
</li><br>
<a id="FileLog-attr-addLog"></a>
<li>addLog<br> <li>addLog<br>
This attribute takes a comma-separated list of This attribute takes a comma-separated list of
devspec:reading:maxInterval triples. You may use regular expressions devspec:reading:maxInterval triples. You may use regular expressions
@ -1472,9 +1509,9 @@ FileLog_regexpFn($$)
has arrived. has arrived.
</li><br> </li><br>
<a name="archivedir"></a> <a id="FileLog-attr-archivedir"></a>
<a name="archivecmd"></a> <a id="FileLog-attr-archivecmd"></a>
<a name="nrarchive"></a> <a id="FileLog-attr-nrarchive"></a>
<li>archivecmd / archivedir / nrarchive<br> <li>archivecmd / archivedir / nrarchive<br>
When a new FileLog file is opened, the FileLog archiver wil be called. When a new FileLog file is opened, the FileLog archiver wil be called.
This happens only, if the name of the logfile has changed (due to This happens only, if the name of the logfile has changed (due to
@ -1496,13 +1533,13 @@ FileLog_regexpFn($$)
<a href="#logfile">FHEM logfile</a> only. <a href="#logfile">FHEM logfile</a> only.
</li><br> </li><br>
<a name="archiveCompress"></a> <a id="FileLog-attr-archiveCompress"></a>
<li>archiveCompress<br> <li>archiveCompress<br>
If nrarchive, archivedir and archiveCompress is set, then the files If nrarchive, archivedir and archiveCompress is set, then the files
in the archivedir will be compressed. in the archivedir will be compressed.
</li><br> </li><br>
<a name="createGluedFile"></a> <a id="FileLog-attr-createGluedFile"></a>
<li>createGluedFile<br> <li>createGluedFile<br>
If set (to 1), and the SVG-Plot requests a time-range wich is stored If set (to 1), and the SVG-Plot requests a time-range wich is stored
in multiple files, a temporary file with the content of all files will in multiple files, a temporary file with the content of all files will
@ -1513,7 +1550,7 @@ FileLog_regexpFn($$)
<li><a href="#disabledForIntervals">disabledForIntervals</a></li> <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
<br> <br>
<a name="eventOnThreshold"></a> <a id="FileLog-attr-eventOnThreshold"></a>
<li>eventOnThreshold<br> <li>eventOnThreshold<br>
If set (to a nonzero number), the event linesInTheFile will be If set (to a nonzero number), the event linesInTheFile will be
generated, if the lines in the file is a multiple of the set number. generated, if the lines in the file is a multiple of the set number.
@ -1521,7 +1558,7 @@ FileLog_regexpFn($$)
feature was implemented. A FHEM crash or kill will falsify the counter. feature was implemented. A FHEM crash or kill will falsify the counter.
</li><br> </li><br>
<a name="filelog-event-min-interval"></a> <a id="FileLog-attr-filelog-event-min-interval"></a>
<li>filelog-event-min-interval<br> <li>filelog-event-min-interval<br>
This attribute takes a comma-separated list of This attribute takes a comma-separated list of
devspec:reading:minInterval triples. You may use regular expressions devspec:reading:minInterval triples. You may use regular expressions
@ -1533,7 +1570,7 @@ FileLog_regexpFn($$)
<li><a href="#label">label</a><br></li> <li><a href="#label">label</a><br></li>
<a name="logtype"></a> <a id="FileLog-attr-logtype"></a>
<li>logtype<br> <li>logtype<br>
Used by FHEMWEB to offer gnuplot/SVG images made from the Used by FHEMWEB to offer gnuplot/SVG images made from the
logs. The string is made up of tokens separated by comma (,), each logs. The string is made up of tokens separated by comma (,), each
@ -1547,14 +1584,14 @@ FileLog_regexpFn($$)
<li><a href="#mseclog">mseclog</a></li><br> <li><a href="#mseclog">mseclog</a></li><br>
<a name="outputFormat"></a> <a id="FileLog-attr-outputFormat"></a>
<li>outputFormat &lt;perlCode&gt;<br> <li>outputFormat &lt;perlCode&gt;<br>
If set, the result of the evaluated perlCode will be written to the file. If set, the result of the evaluated perlCode will be written to the file.
Default is "$TIMESTAMP $NAME $EVENT\n".<br> Default is "$TIMESTAMP $NAME $EVENT\n".<br>
Note: only this format ist compatible with the SVG Editor Note: only this format ist compatible with the SVG Editor
</li><br> </li><br>
<a name="reformatFn"></a> <a id="FileLog-attr-reformatFn"></a>
<li>reformatFn &lt;perlFunctionName&gt;<br> <li>reformatFn &lt;perlFunctionName&gt;<br>
used to convert "foreign" logfiles for the SVG Module, contains the used to convert "foreign" logfiles for the SVG Module, contains the
name(!) of a function, which will be called with a "raw" line from the name(!) of a function, which will be called with a "raw" line from the
@ -1584,12 +1621,12 @@ FileLog_regexpFn($$)
=begin html_DE =begin html_DE
<a name="FileLog"></a> <a id="FileLog"></a>
<h3>FileLog</h3> <h3>FileLog</h3>
<ul> <ul>
<br> <br>
<a name="FileLogdefine"></a> <a id="FileLog-define"></a>
<b>Define</b> <b>Define</b>
<ul> <ul>
<code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code> <code>define &lt;name&gt; FileLog &lt;filename&gt; &lt;regexp&gt; [readonly]</code>
@ -1643,7 +1680,7 @@ FileLog_regexpFn($$)
<br> <br>
</ul> </ul>
<a name="FileLogset"></a> <a id="FileLog-set"></a>
<b>Set </b> <b>Set </b>
<ul> <ul>
<li>reopen <li>reopen
@ -1694,7 +1731,7 @@ FileLog_regexpFn($$)
<br> <br>
<a name="FileLogget"></a> <a id="FileLog-get"></a>
<b>Get</b> <b>Get</b>
<ul> <ul>
<code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt; <code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
@ -1773,12 +1810,20 @@ FileLog_regexpFn($$)
<br> <br>
</ul> </ul>
<a name="FileLogattr"></a> <a id="FileLog-attr"></a>
<b>Attribute</b> <b>Attribute</b>
<ul> <ul>
<li><a href="#addStateEvent">addStateEvent</a></li><br><br> <li><a href="#addStateEvent">addStateEvent</a></li><br><br>
<a name="addLog"></a> <a id="FileLog-attr-acceptedRange"></a>
<li>acceptedRange col1:min:max ...<br>
Dieses Attribut spezifiert eine durch Leerzeichen getrennte Liste von
Bereichen. Falls die Spalte (gerechnet ab 0) eines Events eine Zahl
ist, und ausserhalb dieses Bereiches liegt, wird das Event nicht
geloggt.
</li><br>
<a id="FileLog-attr-addLog"></a>
<li>addLog<br> <li>addLog<br>
Dieses Attribut enth&auml;lt eine durch Kommata getrennte Liste von Dieses Attribut enth&auml;lt eine durch Kommata getrennte Liste von
"devspec:readings:maxInterval" Tripel. readings kann ein regexp sein. "devspec:readings:maxInterval" Tripel. readings kann ein regexp sein.
@ -1786,9 +1831,9 @@ FileLog_regexpFn($$)
wird der letzte Wert zum Logfile hinzugefuegt. wird der letzte Wert zum Logfile hinzugefuegt.
</li><br> </li><br>
<a name="archivedir"></a> <a id="FileLog-attr-archivedir"></a>
<a name="archivecmd"></a> <a id="FileLog-attr-archivecmd"></a>
<a name="nrarchive"></a> <a id="FileLog-attr-nrarchive"></a>
<li>archivecmd / archivedir / nrarchive<br> <li>archivecmd / archivedir / nrarchive<br>
Wenn eine neue FileLog-Datei ge&ouml;ffnet wird, wird der FileLog Wenn eine neue FileLog-Datei ge&ouml;ffnet wird, wird der FileLog
archiver aufgerufen. Das geschieht aber nur , wenn der Name der Datei archiver aufgerufen. Das geschieht aber nur , wenn der Name der Datei
@ -1812,13 +1857,13 @@ FileLog_regexpFn($$)
auschlie&szlig;lich auf das <a href="#logfile">FHEM logfile</a> auschlie&szlig;lich auf das <a href="#logfile">FHEM logfile</a>
Auswirkungen. </li><br> Auswirkungen. </li><br>
<a name="archiveCompress"></a> <a id="FileLog-attr-archiveCompress"></a>
<li>archiveCompress<br> <li>archiveCompress<br>
Falls nrarchive, archivedir und archiveCompress gesetzt ist, dann Falls nrarchive, archivedir und archiveCompress gesetzt ist, dann
werden die Dateien im archivedir komprimiert abgelegt. werden die Dateien im archivedir komprimiert abgelegt.
</li><br> </li><br>
<a name="createGluedFile"></a> <a id="FileLog-attr-createGluedFile"></a>
<li>createGluedFile<br> <li>createGluedFile<br>
Falls gesetzt (1), und im SVG-Plot ein Zeitbereich abgefragt wird, was Falls gesetzt (1), und im SVG-Plot ein Zeitbereich abgefragt wird, was
in mehreren Logdateien gespeichert ist, dann wird f&uuml;r die Anfrage in mehreren Logdateien gespeichert ist, dann wird f&uuml;r die Anfrage
@ -1829,7 +1874,7 @@ FileLog_regexpFn($$)
<li><a href="#disabledForIntervals">disabledForIntervals</a></li> <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
<br> <br>
<a name="eventOnThreshold"></a> <a id="FileLog-attr-eventOnThreshold"></a>
<li>eventOnThreshold<br> <li>eventOnThreshold<br>
Falls es auf eine (nicht Null-) Zahl gesetzt ist, dann wird das Falls es auf eine (nicht Null-) Zahl gesetzt ist, dann wird das
linesInTheFile Event generiert, falls die Anzahl der Zeilen in der linesInTheFile Event generiert, falls die Anzahl der Zeilen in der
@ -1839,7 +1884,7 @@ FileLog_regexpFn($$)
verf&auml;lscht die Z&auml;hlung. verf&auml;lscht die Z&auml;hlung.
</li><br> </li><br>
<a name="filelog-event-min-interval"></a> <a id="FileLog-attr-filelog-event-min-interval"></a>
<li>filelog-event-min-interval<br> <li>filelog-event-min-interval<br>
Dieses Attribut enth&auml;lt eine durch Kommata getrennte Liste von Dieses Attribut enth&auml;lt eine durch Kommata getrennte Liste von
"devspec:readings:minInterval" Tripel. readings kann ein regexp sein. "devspec:readings:minInterval" Tripel. readings kann ein regexp sein.
@ -1849,7 +1894,7 @@ FileLog_regexpFn($$)
<li><a href="#ignoreRegexp">ignoreRegexp</a></li> <li><a href="#ignoreRegexp">ignoreRegexp</a></li>
<a name="logtype"></a> <a id="FileLog-attr-logtype"></a>
<li>logtype<br> <li>logtype<br>
Wird vom SVG Modul ben&ouml;tigt, um daten grafisch aufzubereiten. Wird vom SVG Modul ben&ouml;tigt, um daten grafisch aufzubereiten.
Der String wird aus komma-separierten Tokens Der String wird aus komma-separierten Tokens
@ -1897,14 +1942,14 @@ FileLog_regexpFn($$)
<li><a href="#mseclog">mseclog</a></li><br> <li><a href="#mseclog">mseclog</a></li><br>
<a name="outputFormat"></a> <a id="FileLog-attr-outputFormat"></a>
<li>outputFormat &lt;perlCode&gt;<br> <li>outputFormat &lt;perlCode&gt;<br>
Falls gesetzt, ist die Ausgabezeile das Ergebnis der Auswertung. Falls gesetzt, ist die Ausgabezeile das Ergebnis der Auswertung.
Voreinstellung ist "$TIMESTAMP $NAME $EVENT\n".<br> Voreinstellung ist "$TIMESTAMP $NAME $EVENT\n".<br>
Achtung: nur dieses Format ist kompatibel mit dem SVG-Editor. Achtung: nur dieses Format ist kompatibel mit dem SVG-Editor.
</li><br> </li><br>
<a name="reformatFn"></a> <a id="FileLog-attr-reformatFn"></a>
<li>reformatFn &lt;perlFunktionsName&gt;<br> <li>reformatFn &lt;perlFunktionsName&gt;<br>
wird verwendet, um "fremde" Dateien f&uuml;r die SVG-Anzeige ins wird verwendet, um "fremde" Dateien f&uuml;r die SVG-Anzeige ins
FileLog-Format zu konvertieren. Es enth&auml;lt nur den Namen einer FileLog-Format zu konvertieren. Es enth&auml;lt nur den Namen einer