From a4620ffc27a840160518997e0597a68847393d05 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sat, 16 Nov 2019 09:09:31 +0000 Subject: [PATCH] 93_DbLog: new attribute defaultMinInterval, Forum: topic,65860.msg972352.html#msg972352 git-svn-id: https://svn.fhem.de/fhem/trunk@20515 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/93_DbLog.pm | 182 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 163 insertions(+), 21 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index cfc55d683..329a03f1c 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 93_DbLog: new attribute defaultMinInterval, + Forum: topic,65860.msg972352.html#msg972352 - feature: 73_AutoShuttersControl: new version 0.8, meany new features - change: 70_ONKYO_AVR: trying to improve reporting of model - feature: 31_HUEDevice: handle IODev rename diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index f8af9fe9f..a30fb612b 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -30,6 +30,9 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern by DS_Starter: our %DbLog_vNotesIntern = ( + "4.9.1" => "13.11.2019 escape \ with \\ in DbLog_Push and DbLog_PushAsync ", + "4.9.0" => "11.11.2019 new attribute defaultMinInterval to set a default minInterval central in dblog for all events ". + "Forum: https://forum.fhem.de/index.php/topic,65860.msg972352.html#msg972352 ", "4.8.0" => "14.10.2019 change SQL-Statement for delta-h, delta-d (SVG getter) ", "4.7.5" => "07.10.2019 fix warning \"error valueFn: Global symbol \$CN requires ...\" in DbLog_addCacheLine ". "enhanced configCheck by insert mode check ", @@ -254,6 +257,7 @@ sub DbLog_Initialize($) { "DbLogSelectionMode:Exclude,Include,Exclude/Include ". "DbLogType:Current,History,Current/History,SampleFill/History ". "dbSchema ". + "defaultMinInterval:textField-long ". "disable:1,0 ". "excludeDevs ". "expimpdir ". @@ -1292,7 +1296,7 @@ sub DbLog_Log($$) { my $ts_0 = TimeNow(); # timestamp in SQL format YYYY-MM-DD hh:mm:ss my $now = gettimeofday(); # get timestamp in seconds since epoch my $DbLogExclude = AttrVal($dev_name, "DbLogExclude", undef); - my $DbLogInclude = AttrVal($dev_name, "DbLogInclude",undef); + my $DbLogInclude = AttrVal($dev_name, "DbLogInclude", undef); my $DbLogValueFn = AttrVal($dev_name, "DbLogValueFn",""); my $DbLogSelectionMode = AttrVal($name, "DbLogSelectionMode","Exclude"); my $value_fn = AttrVal( $name, "valueFn", "" ); @@ -1369,14 +1373,15 @@ sub DbLog_Log($$) { Log3 $name, 5, "DbLog $name -> DbLogExclude of \"$dev_name\": $DbLogExclude" if($vb4show && !$hash->{HELPER}{".RUNNING_PID"} && $DbLogExclude); Log3 $name, 5, "DbLog $name -> DbLogInclude of \"$dev_name\": $DbLogInclude" if($vb4show && !$hash->{HELPER}{".RUNNING_PID"} && $DbLogInclude); - #Je nach DBLogSelectionMode muss das vorgegebene Ergebnis der Include-, bzw. Exclude-Pruefung - #entsprechend unterschiedlich vorbelegt sein. - #keine Readings loggen die in DbLogExclude explizit ausgeschlossen sind + # Je nach DBLogSelectionMode muss das vorgegebene Ergebnis der Include-, bzw. Exclude-Pruefung + # entsprechend unterschiedlich vorbelegt sein. + # keine Readings loggen die in DbLogExclude explizit ausgeschlossen sind my $DoIt = 0; + $DoIt = 1 if($DbLogSelectionMode =~ m/Exclude/ ); if($DbLogExclude && $DbLogSelectionMode =~ m/Exclude/) { - # Bsp: "(temperature|humidity):300,battery:3600" + # Bsp: "(temperature|humidity):300,battery:3600:force" my @v1 = split(/,/, $DbLogExclude); for (my $i=0; $i{NAME}}{TIME} = $now; @@ -1561,9 +1569,75 @@ sub DbLog_Log($$) { if($net && AttrVal($name, "showNotifyTime", undef)) { readingsSingleUpdate($hash, "notify_processing_time", sprintf("%.4f",$net), 1); } + return; } +################################################################################################# +# +# check zentrale Angabe von defaultMinInterval für alle Devices/Readings +# (kein Überschreiben spezifischer Angaben von DbLogExclude / DbLogInclude in den Quelldevices) +# +################################################################################################# +sub DbLog_checkDefMinInt ($$$$$){ + my ($name,$dev_name,$now,$reading,$value) = @_; + my $force; + my $DoIt = 1; + + my $defminint = AttrVal($name, "defaultMinInterval", undef); + return $DoIt if(!$defminint); # Attribut "defaultMinInterval" nicht im DbLog gesetzt -> kein ToDo + + my $DbLogExclude = AttrVal($dev_name, "DbLogExclude", undef); + my $DbLogInclude = AttrVal($dev_name, "DbLogInclude", undef); + $defminint =~ s/[\s\n]/,/g; + my @adef = split(/,/, $defminint); + + my $inex = ($DbLogExclude?$DbLogExclude.",":"").($DbLogInclude?$DbLogInclude:""); + + if($inex) { # Quelldevice hat DbLogExclude und/oder DbLogInclude gesetzt + my @ie = split(/,/, $inex); + for (my $k=0; $k kein Überschreiben durch $defminint + } + } + } + + for (my $l=0; $l don't log it !"); + $DoIt = 0; + return $DoIt; + } + } + } + } + } + # Log3 ($name, 1, "DbLog $name - defaulMInInterval - compare of \"$dev_name\", reading \"$reading\" successful -> log it !"); + +return $DoIt; +} + ################################################################################################# # Schreibroutine Einfügen Werte in DB im Synchronmode ################################################################################################# @@ -1649,9 +1723,9 @@ sub DbLog_Push(@) { push(@event, "$a[3]"); push(@reading, "$a[4]"); push(@value, "$a[5]"); - push(@unit, "$a[6]"); + push(@unit, "$a[6]"); Log3 $hash->{NAME}, 4, "DbLog $name -> processing event Timestamp: $a[0], Device: $a[1], Type: $a[2], Event: $a[3], Reading: $a[4], Value: $a[5], Unit: $a[6]" - if($vb4show); + if($vb4show); } use warnings; @@ -1683,6 +1757,9 @@ sub DbLog_Push(@) { $a[3] =~ s/'/''/g; # escape ' with '' $a[5] =~ s/'/''/g; # escape ' with '' $a[6] =~ s/'/''/g; # escape ' with '' + $a[3] =~ s/\\/\\\\/g; # escape \ with \\ + $a[5] =~ s/\\/\\\\/g; # escape \ with \\ + $a[6] =~ s/\\/\\\\/g; # escape \ with \\ $sqlins .= "('$a[0]','$a[1]','$a[2]','$a[3]','$a[4]','$a[5]','$a[6]'),"; } use warnings; @@ -2275,8 +2352,8 @@ sub DbLog_PushAsync(@) { push(@event, "$a[3]"); push(@reading, "$a[4]"); push(@value, "$a[5]"); - push(@unit, "$a[6]"); - Log3 $hash->{NAME}, 5, "DbLog $name -> processing event Timestamp: $a[0], Device: $a[1], Type: $a[2], Event: $a[3], Reading: $a[4], Value: $a[5], Unit: $a[6]"; + push(@unit, "$a[6]"); + Log3 $hash->{NAME}, 5, "DbLog $name -> processing event Timestamp: $a[0], Device: $a[1], Type: $a[2], Event: $a[3], Reading: $a[4], Value: $a[5], Unit: $a[6]"; } use warnings; @@ -2307,6 +2384,9 @@ sub DbLog_PushAsync(@) { $a[3] =~ s/'/''/g; # escape ' with '' $a[5] =~ s/'/''/g; # escape ' with '' $a[6] =~ s/'/''/g; # escape ' with '' + $a[3] =~ s/\\/\\\\/g; # escape \ with \\ + $a[5] =~ s/\\/\\\\/g; # escape \ with \\ + $a[6] =~ s/\\/\\\\/g; # escape \ with \\ $sqlins .= "('$a[0]','$a[1]','$a[2]','$a[3]','$a[4]','$a[5]','$a[6]'),"; } use warnings; @@ -6849,10 +6929,10 @@ sub DbLog_showChildHandles ($$$$) { DbLogInclude works just like DbLogExclude but to include matching readings. If a MinInterval is set, the logentry is dropped if the defined interval is not reached and the value vs. last value is equal. If the optional parameter "force" is set, the logentry is also dropped even though the value is not - equal the last one and the defined interval is not reached. - is not reached and the - See also DbLogSelectionMode-Attribute of DbLog device which takes influence on how DbLogExclude and DbLogInclude - are handled.

+ equal the last one and the defined interval is not reached.
+ See also the attributes defaultMinInterval and DbLogSelectionMode of DbLog device which takes influence on + how DbLogExclude and DbLogInclude are handled. +

Example
attr MyDevice1 DbLogInclude .*
@@ -6876,7 +6956,9 @@ sub DbLog_showChildHandles ($$$$) { comma. If a MinInterval is set, the logentry is dropped if the defined interval is not reached and the value vs. lastvalue is equal. If the optional parameter "force" is set, the logentry is also dropped even though the value is not - equal the last one and the defined interval is not reached. + equal the last one and the defined interval is not reached.
+ See also the attributes defaultMinInterval and DbLogSelectionMode of DbLog device which takes influence on + how DbLogExclude and DbLogInclude are handled.

Example
@@ -6940,6 +7022,35 @@ attr SMA_Energymeter DbLogValueFn
+
    + +
  • defaultMinInterval +
      + + attr <device> defaultMinInterval <devspec>::<MinInterval>[::force],[<devspec>::<MinInterval>[::force]] ... +
      + + With this attribute a default minimum interval for devspec is defined. + If a defaultMinInterval is set, the logentry is dropped if the defined interval is not reached and the value vs. + lastvalue is equal.
      + If the optional parameter "force" is set, the logentry is also dropped even though the value is not + equal the last one and the defined interval is not reached.
      + Potential set DbLogExclude / DbLogInclude specifications in source devices are having priority over defaultMinInterval + and are not overwritten by this attribute.
      + This attribute can be specified as multiline input.

      + + Examples
      + attr dblog defaultMinInterval .*::120::force
      + # Events of all devices are logged only in case of 120 seconds are elapsed to the last log entry (reading specific) independent of a possible value change.
      + attr dblog defaultMinInterval (Weather|SMA)::300
      + # Events of devices "Weather" and "SMA" are logged only in case of 300 seconds are elapsed to the last log entry (reading specific) and the value is equal to the last logged value.
      + attr dblog defaultMinInterval TYPE=CUL_HM::600::force
      + # Events of all devices of Type "CUL_HM" are logged only in case of 600 seconds are elapsed to the last log entry (reading specific) independent of a possible value change. +
    +
  • +
+
+
  • disable @@ -8207,10 +8318,10 @@ attr SMA_Energymeter DbLogValueFn in das Logging eingeschlossen statt ausgeschlossen werden koennen.
    Ist MinIntervall angegeben, wird der Logeintrag nicht geloggt, wenn das Intervall noch nicht erreicht und der Wert des Readings sich nicht verändert hat. - Ist der optionale Parameter "force" hinzugefügt, wird der Logeintrag auch dann nicht nicht geloggt, wenn sich der + Ist der optionale Parameter "force" hinzugefügt, wird der Logeintrag auch dann nicht geloggt, wenn sich der Wert des Readings verändert hat.
    - Siehe auch das DbLog Attribut DbLogSelectionMode. Es beeinflußt wie DbLogExclude und DbLogInclude ausgewertet - werden.

    + Siehe auch die DbLog Attribute defaultMinInterval und DbLogSelectionMode. + Es beeinflußt wie DbLogExclude und DbLogInclude ausgewertet werden.

    Beispiel
    attr MyDevice1 DbLogInclude .*
    @@ -8236,8 +8347,8 @@ attr SMA_Energymeter DbLogValueFn Wert des Readings sich nicht verändert hat. Ist der optionale Parameter "force" hinzugefügt, wird der Logeintrag auch dann nicht geloggt, wenn sich der Wert des Readings verändert hat.
    - Siehe auch das DbLog Attribut DbLogSelectionMode. Es beeinflußt wie DbLogExclude und DbLogInclude ausgewertet - werden.

    + Siehe auch die DbLog Attribute defaultMinInterval und DbLogSelectionMode. + Es beeinflußt wie DbLogExclude und DbLogInclude ausgewertet werden.

    Beispiel
    attr MyDevice1 DbLogExclude .*
    @@ -8300,6 +8411,35 @@ attr SMA_Energymeter DbLogValueFn

+
    + +
  • defaultMinInterval +
      + + attr <device> defaultMinInterval <devspec>::<MinInterval>[::force],[<devspec>::<MinInterval>[::force]] ... +
      + + Mit diesem Attribut wird ein Standard Minimum Intervall für devspec festgelegt. + Ist defaultMinInterval angegeben, wird der Logeintrag nicht geloggt, wenn das Intervall noch nicht erreicht und der + Wert des Readings sich nicht verändert hat.
      + Ist der optionale Parameter "force" hinzugefügt, wird der Logeintrag auch dann nicht geloggt, wenn sich der + Wert des Readings verändert hat.
      + Eventuell im Quelldevice angegebene Spezifikationen DbLogExclude / DbLogInclude haben Vorrag und werden durch + defaultMinInterval nicht überschrieben.
      + Die Eingabe kann mehrzeilig erfolgen.

      + + Beispiele
      + attr dblog defaultMinInterval .*::120::force
      + # Events aller Devices werden nur geloggt, wenn 120 Sekunden zum letzten Logeintrag vergangen sind ist (Reading spezifisch) unabhängig von einer eventuellen Änderung des Wertes.
      + attr dblog defaultMinInterval (Weather|SMA)::300
      + # Events der Devices "Weather" und "SMA" werden nur geloggt wenn 300 Sekunden zum letzten Logeintrag vergangen sind (Reading spezifisch) und sich der Wert nicht geändert hat.
      + attr dblog defaultMinInterval TYPE=CUL_HM::600::force
      + # Events aller Devices des Typs "CUL_HM" werden nur geloggt, wenn 600 Sekunden zum letzten Logeintrag vergangen sind (Reading spezifisch) unabhängig von einer eventuellen Änderung des Wertes. +
    +
  • +
+
+
  • disable