From 9f8d0b90135ba67b7b7d04c56f6e18372b5e8aa7 Mon Sep 17 00:00:00 2001 From: DS_Starter Date: Mon, 2 Apr 2018 13:45:27 +0000 Subject: [PATCH] 93_DbLog: V3.10.0, addLog considers DbLogExclude in Devices,keyword "!useExcludes" to switch off considering DbLogExclude in addLog, DbLogExclude & DbLogInclude can handle "/" in Readingname, commandref revised git-svn-id: https://svn.fhem.de/fhem/trunk@16533 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 ++ fhem/FHEM/93_DbLog.pm | 139 ++++++++++++++++++++++++++++-------------- 2 files changed, 98 insertions(+), 45 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 72f75c84f..3f271e7dc 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,9 @@ # 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. + - change: 93_DbLog: V3.10.0, addLog considers DbLogExclude in Devices, + keyword "!useExcludes" to switch off considering + DbLogExclude in addLog, DbLogExclude & DbLogInclude + can handle "/" in Readingname, commandref revised - bugfix: 00_SIGNALduino: Perl Warnings and FHEM crash fixed - added: 88_xs1Bridge: Documentation added - added: 88_xs1Dev: various sensor types added diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index e18bb59af..202434c48 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -16,6 +16,9 @@ ############################################################################################################################################ # Versions History done by DS_Starter & DeeSPe: # +# 3.10.0 02.04.2018 addLog consider DbLogExclude in Devices, keyword "!useExcludes" to switch off considering +# DbLogExclude in addLog, DbLogExclude & DbLogInclude can handle "/" in Readingname, +# commandref (reduceLog) revised # 3.9.0 17.03.2018 DbLog_ConnectPush state-handling changed, attribute excludeDevs enhanced in DbLog_Log # 3.8.9 10.03.2018 commandref revised # 3.8.8 05.03.2018 fix device doesn't exit if configuration couldn't be read @@ -191,8 +194,9 @@ use Data::Dumper; use Blocking; use Time::HiRes qw(gettimeofday tv_interval); use Encode qw(encode_utf8); +no if $] >= 5.017011, warnings => 'experimental::smartmatch'; -my $DbLogVersion = "3.9.0"; +my $DbLogVersion = "3.10.0"; my %columns = ("DEVICE" => 64, "TYPE" => 64, @@ -542,8 +546,10 @@ sub DbLog_Set($@) { } } elsif ($a[1] eq 'addLog') { - unless ($a[2]) { return " The argument of $a[1] is not valid. Use a pair of ,reading [value] you want to create a log entry from";} - DbLog_AddLog($hash,$a[2],$a[3]); + unless ($a[2]) { return "The argument of $a[1] is not valid. Please check commandref.";} + my $nce = ("\!useExcludes" ~~ @a)?1:0; + map(s/\!useExcludes//g, @a); + DbLog_AddLog($hash,$a[2],$a[3],$nce); } elsif ($a[1] eq 'reopen') { if ($dbh) { @@ -1292,9 +1298,9 @@ sub DbLog_Log($$) { for (my $i=0; $i{NAME}}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME}; my $lv = $defs{$dev_hash->{NAME}}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE}; @@ -1317,9 +1323,9 @@ sub DbLog_Log($$) { for (my $i=0; $i{NAME}}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME}; my $lv = $defs{$dev_hash->{NAME}}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE}; @@ -3537,8 +3543,8 @@ return @sr; # Addlog - einfügen des Readingwertes eines gegebenen Devices # ######################################################################################### -sub DbLog_AddLog($$$) { - my ($hash,$devrdspec,$value)= @_; +sub DbLog_AddLog($$$$) { + my ($hash,$devrdspec,$value,$nce)= @_; my $name = $hash->{NAME}; my $async = AttrVal($name, "asyncMode", undef); my $value_fn = AttrVal( $name, "valueFn", "" ); @@ -3572,9 +3578,24 @@ sub DbLog_AddLog($$$) { next; } - my $r = $defs{$dev_name}{READINGS}; + my $r = $defs{$dev_name}{READINGS}; + my $DbLogExclude = AttrVal($dev_name, "DbLogExclude", undef); my @exrds; foreach my $rd (sort keys %{$r}) { + # jedes Reading des Devices auswerten + my $do = 1; + if($DbLogExclude && !$nce) { + my @v1 = split(/,/, $DbLogExclude); + for (my $i=0; $i Device: \"$dev_name\", reading: \"$v2[0]\" excluded by attribute DbLogExclude from addLog !"; + $do = 0; + } + } + } + next if(!$do); push @exrds,$rd if($rd =~ m/^$rdspec$/); } Log3 $name, 4, "DbLog $name -> Readings extracted from Regex: @exrds"; @@ -3588,7 +3609,7 @@ sub DbLog_AddLog($$$) { $dev_reading = $_; $read_val = $value?$value:ReadingsVal($dev_name,$dev_reading,""); $dev_type = uc($defs{$dev_name}{TYPE}); - + # dummy-Event zusammenstellen $event = $dev_reading.": ".$read_val; @@ -5303,12 +5324,14 @@ sub dbReadings($@) { set <name> addCacheLine 2017-12-05 17:03:59|MaxBathRoom|MAX|valveposition: 95|valveposition|95|%

- set <name> addLog <devspec>:<Reading> [Value]

+ set <name> addLog <devspec>:<Reading> [Value] [!useExcludes]

    Inserts an additional log entry of a device/reading combination into the database. Optionally you can enter a "Value" that is used as reading value for the dataset. If the value isn't specified (default), the current value of the specified reading will be inserted into the database. The field "$EVENT" will be filled automatically by "addLog". The device can be declared by a device specification (devspec). - "Reading" will be evaluated as regular expression. + "Reading" will be evaluated as regular expression.
    + The function considers attribute "DbLogExclude" in source device if it is set. If the optional keyword "!useExcludes" + is set, the attribute "DbLogExclude" isn't considered.
    By the addLog-command NO additional events will be created !

    Examples:
    @@ -5380,23 +5403,32 @@ sub dbReadings($@) {
      In asynchronous mode (attribute asyncMode=1), the in memory cached data will be deleted. With this command data won't be written from cache into the database.

    - set <name> reduceLog <n> [average[=day]] [exclude=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...]

    -
      Reduces records older than <n> days to one record each hour (the 1st) per device & reading.

      - CAUTION: It is strongly recommended to check if the default INDEX 'Search_Idx' exists on the table 'history'!
      - The execution of this command may take (without INDEX) extremely long. FHEM will be blocked completely after issuing the command to completion !

      + set <name> reduceLog <n> [average[=day]] [exclude=device1:reading1,device2:reading2,...]

      +
        Reduces records older than <n> days to one record (the 1st) each hour per device & reading.
        + Within the device/reading name SQL-Wildcards "%" and "_" can be used.

        With the optional argument 'average' not only the records will be reduced, but all numerical values of an hour will be reduced to a single average.
        With the optional argument 'average=day' not only the records will be reduced, but all numerical values of a - day will be reduced to a single average. (implies 'average')
        - You can optional set the last argument to "EXCLUDE=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...." - to exclude device/readings from reduceLog.
        - You can optional set the last argument to "INCLUDE=Database-deviceRegExp:Database-ReadingRegExp" to delimit - the SELECT statement which is executet on the database. This reduces the system RAM load and increases the - performance. (Wildcards are % and _)
        + day will be reduced to a single average. (implies 'average')

        + + You can optional set the last argument to "exclude=device1:reading1,device2:reading2,..." to exclude + device/readings from reduceLog.
        + Also you can optional set the last argument to "include=device:reading" to delimit the SELECT statement which + is executed on the database. This may reduce the system RAM load and increases the performance.

        + +
          + Example:
          + set <name> reduceLog 270 average include=Luftdaten_remote:%
          +
        +
        + + CAUTION: It is strongly recommended to check if the default INDEX 'Search_Idx' exists on the table 'history'!
        + The execution of this command may take (without INDEX) extremely long. FHEM will be blocked completely after issuing the command to completion !

        +

      - set <name> reduceLogNbl <n> [average[=day]] [exclude=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...]

      + set <name> reduceLogNbl <n> [average[=day]] [exclude=device1:reading1,device2:reading2,...]

        Same function as "set <name> reduceLog" but FHEM won't be blocked due to this function is implemented non-blocking !

      @@ -5782,7 +5814,9 @@ sub dbReadings($@) {
      • Exclude: DbLog behaves just as usual. This means everything specified in the regex in DEF will be logged by default and anything excluded via the DbLogExclude attribute will not be logged
      • -
      • Include: Nothing will be logged, except the readings specified via regex in the DbLogInclude attribute
      • +
      • Include: Nothing will be logged, except the readings specified via regex in the DbLogInclude attribute + (in source devices). + Neither the Regex set in DEF will be considered nor the device name of the source device itself.
      • Exclude/Include: Just almost the same as Exclude, but if the reading matches the DbLogExclude attribute, then it will further be checked against the regex in DbLogInclude whicht may possibly re-include the already excluded reading.
      • @@ -5797,9 +5831,8 @@ sub dbReadings($@) { attr <device> DbLogInclude regex:MinInterval,[regex:MinInterval] ...
        - A new Attribute DbLogInclude will be propagated - to all Devices if DBLog is used. DbLogInclude works just like DbLogExclude but - to include matching readings. + A new Attribute DbLogInclude will be propagated to all Devices if DBLog is used. + DbLogInclude works just like DbLogExclude but to include matching readings. See also DbLogSelectionMode-Attribute of DbLog-Device which takes influence on on how DbLogExclude and DbLogInclude are handled.
        @@ -6289,18 +6322,20 @@ sub dbReadings($@) { set <name> addCacheLine 2017-12-05 17:03:59|MaxBathRoom|MAX|valveposition: 95|valveposition|95|%

      - set <name> addLog <devspec>:<Reading> [Value]

      + set <name> addLog <devspec>:<Reading> [Value] [!useExcludes]

        Fügt einen zusatzlichen Logeintrag einer Device/Reading-Kombination in die Datenbank ein. Optional kann "Value" für den Readingwert angegeben werden. Ist Value nicht angegeben, wird der aktuelle Wert des Readings in die DB eingefügt. Das Feld "$EVENT" wird automatisch mit "addLog" belegt. Das Device kann - als Geräte-Spezifikation angegeben werden. "Reading" wird als regulärer Ausdruck ausgewertet. + als Geräte-Spezifikation angegeben werden. "Reading" wird als regulärer Ausdruck ausgewertet.
        + Ein eventuell im Quell-Device gesetztes Attribut "DbLogExclude" wird von der Funktion berücksichtigt. Soll dieses + Attribut nicht berücksichtigt werden, kann das Schüsselwort "!useExcludes" verwendet werden.
        Es wird KEIN zusätzlicher Event im System erzeugt !

        Beispiele:
        set <name> addLog SMA_Energymeter:Bezug_Wirkleistung
        set <name> addLog TYPE=SSCam:state
        set <name> addLog MyWetter:(fc10.*|fc8.*)
        - set <name> addLog MyWetter:(wind|wind_ch.*) 20
        + set <name> addLog MyWetter:(wind|wind_ch.*) 20 !useExcludes
        set <name> addLog TYPE=CUL_HM:FILTER=model=HM-CC-RT-DN:FILTER=subType!=(virtual|):(measured-temp|desired-temp|actuator)

      @@ -6367,25 +6402,38 @@ sub dbReadings($@) {
        Im asynchronen Modus (Attribut asyncMode=1), werden die im Speicher gecachten Daten gelöscht. Es werden keine Daten aus dem Cache in die Datenbank geschrieben.

      - set <name> reduceLog <n> [average[=day]] [exclude=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...]

      -
        Reduziert historische Datensaetze, die älter sind als <n> Tage auf einen Eintrag pro Stunde (den ersten) je Device & Reading.

        - ACHTUNG: Es wird dringend empfohlen zu überprüfen ob der standard INDEX 'Search_Idx' in der Tabelle 'history' existiert!
        - Die Abarbeitung dieses Befehls dauert unter Umständen (ohne INDEX) extrem lange. FHEM wird durch den Befehl bis - zur Fertigstellung komplett blockiert !

        + set <name> reduceLog <n> [average[=day]] [exclude=device1:reading1,device2:reading2,...]

        +
          Reduziert historische Datensätze, die älter sind als <n> Tage auf einen Eintrag (den ersten) pro Stunde je + Device & Reading.
          + Innerhalb von device/reading können SQL-Wildcards "%" und "_" verwendet werden.

          Das Reading "reduceLogState" zeigt den Ausführungsstatus des letzten reduceLog-Befehls.

          Durch die optionale Angabe von 'average' wird nicht nur die Datenbank bereinigt, sondern alle numerischen Werte einer Stunde werden auf einen einzigen Mittelwert reduziert.
          Durch die optionale Angabe von 'average=day' wird nicht nur die Datenbank bereinigt, sondern alle numerischen - Werte eines Tages auf einen einzigen Mittelwert reduziert. (impliziert 'average')
          - Optional kann als letzer Parameter "EXCLUDE=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...." - angegeben werden um device/reading Kombinationen von reduceLog auszuschließen.
          - Optional kann als letzer Parameter "INCLUDE=Database-deviceRegExp:Database-ReadingRegExp" angegeben werden um + Werte eines Tages auf einen einzigen Mittelwert reduziert. (impliziert 'average')

          + + Optional kann als letzer Parameter "exclude=device1:reading1,device2:reading2,...." + angegeben werden um device/reading Kombinationen von reduceLog auszuschließen.

          + + Optional kann als letzer Parameter "include=device:reading" angegeben werden um die auf die Datenbank ausgeführte SELECT-Abfrage einzugrenzen, was die RAM-Belastung verringert und die - Performance erhöht. (Wildcards sind % und _)
          + Performance erhöht.

          + +
            + Beispiel:
            + set <name> reduceLog 270 average include=Luftdaten_remote:%
            + +
          +
          + + ACHTUNG: Es wird dringend empfohlen zu überprüfen ob der standard INDEX 'Search_Idx' in der Tabelle 'history' existiert!
          + Die Abarbeitung dieses Befehls dauert unter Umständen (ohne INDEX) extrem lange. FHEM wird durch den Befehl bis + zur Fertigstellung komplett blockiert !

          +

        - set <name> reduceLogNbl <n> [average[=day]] [exclude=deviceRegExp1:ReadingRegExp1,deviceRegExp2:ReadingRegExp2,...]

        + set <name> reduceLogNbl <n> [average[=day]] [exclude=device1:reading1,device2:reading2,...]

          Führt die gleiche Funktion wie "set <name> reduceLog" aus. Im Gegensatz zu reduceLog wird mit FHEM wird durch den Befehl reduceLogNbl nicht mehr blockiert da diese Funktion non-blocking implementiert ist !
          @@ -6797,7 +6845,7 @@ sub dbReadings($@) { Die current-Tabelle wird bei der SVG-Erstellung ausgewertet. SampleFill/History Events werden nur in die history-Tabelle geloggt. Die current-Tabelle wird bei der SVG-Erstellung ausgewertet und kann zur Erzeugung einer DropDown-Liste mittels einem - DbRep-Device
          "set <DbRep-Name> tableCurrentFillup" mit + DbRep-Device
          "set <DbRep-Name> tableCurrentFillup" mit einem einstellbaren Extract der history-Tabelle gefüllt werden (advanced Feature).
        @@ -6825,8 +6873,9 @@ sub dbReadings($@) {
      • Exclude: DbLog verhaelt sich wie bisher auch, alles was ueber die RegExp im DEF angegeben ist, wird geloggt, bis auf das, was ueber die RegExp in DbLogExclude ausgeschlossen wird.
        Das Attribut DbLogInclude wird in diesem Fall nicht beruecksichtigt
      • -
      • Include: Es wird nur das geloggt was ueber die RegExp in DbLogInclude eingeschlossen wird.
        - Das Attribut DbLogExclude wird in diesem Fall ebenso wenig beruecksichtigt wie die Regex im DEF.
      • +
      • Include: Es wird nur das geloggt was ueber die RegExp in DbLogInclude (im Quelldevice) eingeschlossen wird.
        + Das Attribut DbLogExclude wird in diesem Fall ebenso wenig beruecksichtigt wie die Regex im DEF. Auch + der Devicename (des Quelldevice) geht in die Auswertung nicht mit ein.
      • Exclude/Include: Funktioniert im Wesentlichen wie "Exclude", nur das sowohl DbLogExclude als auch DbLogInclude geprueft werden. Readings die durch DbLogExclude zwar ausgeschlossen wurden, mit DbLogInclude aber wiederum eingeschlossen werden, werden somit dennoch geloggt.