diff --git a/fhem/CHANGED b/fhem/CHANGED index bbc9c8118..575c4f598 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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: V3.9.0, syntax of attribute excludeDevs enhanced - update: 39_Talk2Fhem: Timephrases added, bugfixes and some changes - bugfix: 74_AMADCommBridge: fix Commandref - bugfix: 82_LGTV_WebOS: fix litte typos fix eval bug diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index 39a38c2f1..e18bb59af 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -16,6 +16,7 @@ ############################################################################################################################################ # Versions History done by DS_Starter & DeeSPe: # +# 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 # 3.8.7 28.02.2018 changed DbLog_sampleDataFn - no change limits got fron SVG, commandref revised @@ -191,7 +192,7 @@ use Blocking; use Time::HiRes qw(gettimeofday tv_interval); use Encode qw(encode_utf8); -my $DbLogVersion = "3.8.9"; +my $DbLogVersion = "3.9.0"; my %columns = ("DEVICE" => 64, "TYPE" => 64, @@ -1182,8 +1183,7 @@ sub DbLog_Log($$) { my $events = deviceEvents($dev_hash, AttrVal($name, "addStateEvent", 1)); return if(!$events); - my $max = int(@{$events}); - my $lcdev = lc($dev_name); + my $max = int(@{$events}); # verbose4 Logs nur für Devices in Attr "verbose4Devs" my $vb4show = 0; @@ -1206,23 +1206,7 @@ sub DbLog_Log($$) { Log3 $name, 4, "DbLog $name -> ################################################################"; Log3 $name, 4, "DbLog $name -> number of events received: $max for device: $dev_name"; } - - # Devices ausschließen durch Attribut "excludeDevs" (nur wenn kein $hash->{NOTIFYDEV}) - if(!$hash->{NOTIFYDEV}) { - my $exc = AttrVal($name, "excludeDevs", ""); - $exc =~ s/\s/,/g; - my @exdvs = devspec2array($exc); - if(@exdvs) { - # Log3 $name, 3, "DbLog $name -> excludeDevs: @exdvs"; - foreach (@exdvs) { - if(lc($dev_name) eq lc($_)) { - Log3 $name, 4, "DbLog $name -> Device: $dev_name excluded from database logging due to attribute \"excludeDevs\" restrictions" if($vb4show); - return; - } - } - } - } - + my $re = $hash->{REGEXP}; my @row_array; my ($event,$reading,$value,$unit); @@ -1243,6 +1227,7 @@ sub DbLog_Log($$) { #one Transaction eval { for (my $i = 0; $i < $max; $i++) { + my $next = 0; my $event = $events->[$i]; $event = "" if(!defined($event)); $event = DbLog_charfilter($event) if(AttrVal($name, "useCharfilter",0)); @@ -1260,7 +1245,40 @@ sub DbLog_Log($$) { if(!defined $reading) {$reading = "";} if(!defined $value) {$value = "";} if(!defined $unit || $unit eq "") {$unit = AttrVal("$dev_name", "unit", "");} - Log3 $name, 5, "DbLog $name -> parsed Event: $dev_name , Event: $event" if($vb4show && !$hash->{HELPER}{".RUNNING_PID"}); + + # Devices / Readings ausschließen durch Attribut "excludeDevs" + # attr excludeDevs [#],[#],[#] + my ($exc,@excldr,$ds,$rd,@exdvs); + $exc = AttrVal($name, "excludeDevs", ""); + if($exc) { + $exc =~ s/[\s\n]/,/g; + @excldr = split(",",$exc); + foreach my $excl (@excldr) { + ($ds,$rd) = split("#",$excl); + @exdvs = devspec2array($ds); + if(@exdvs) { + # Log3 $name, 3, "DbLog $name -> excludeDevs: @exdvs"; + foreach (@exdvs) { + if($rd) { + if("$dev_name:$reading" =~ m/^$_:$rd$/) { + Log3 $name, 4, "DbLog $name -> Device:Reading \"$dev_name:$reading\" global excluded from logging by attribute \"excludeDevs\" " if($vb4show && !$hash->{HELPER}{".RUNNING_PID"}); + $next = 1; + } + } else { + if($dev_name =~ m/^$_$/) { + Log3 $name, 4, "DbLog $name -> Device \"$dev_name\" global excluded from logging by attribute \"excludeDevs\" " if($vb4show && !$hash->{HELPER}{".RUNNING_PID"}); + $next = 1; + } + } + } + } + } + next if($next); + } + + Log3 $name, 5, "DbLog $name -> parsed Event: $dev_name , Event: $event" if($vb4show && !$hash->{HELPER}{".RUNNING_PID"}); + 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. @@ -2292,7 +2310,7 @@ sub DbLog_ConnectPush($;$$) { my $dbuser = $hash->{dbuser}; my $dbpassword = $attr{"sec$name"}{secret}; my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; - my $dbhp; + my ($dbhp,$state,$evt,$err); return 0 if(IsDisabled($name)); @@ -2314,6 +2332,7 @@ sub DbLog_ConnectPush($;$$) { } if($@) { + $err = $@; Log3 $hash->{NAME}, 2, "DbLog $name - Error: $@"; } @@ -2321,8 +2340,8 @@ sub DbLog_ConnectPush($;$$) { RemoveInternalTimer($hash, "DbLog_ConnectPush"); Log3 $hash->{NAME}, 4, "DbLog $name - Trying to connect to database"; - my $state = $@?$@:(IsDisabled($name))?"disabled":"disconnected"; - my $evt = ($state eq $hash->{HELPER}{OLDSTATE})?0:1; + $state = $err?$err:(IsDisabled($name))?"disabled":"disconnected"; + $evt = ($state eq $hash->{HELPER}{OLDSTATE})?0:1; readingsSingleUpdate($hash, "state", $state, $evt); $hash->{HELPER}{OLDSTATE} = $state; @@ -2336,7 +2355,12 @@ sub DbLog_ConnectPush($;$$) { Log3 $hash->{NAME}, 3, "DbLog $name - Push-Handle to db $dbconn created" if(!$get); Log3 $hash->{NAME}, 3, "DbLog $name - UTF8 support enabled" if($utf8 && $hash->{MODEL} eq "MYSQL" && !$get); - readingsSingleUpdate($hash, 'state', 'connected', 1) if(!$get); + if(!$get) { + $state = "connected"; + $evt = ($state eq $hash->{HELPER}{OLDSTATE})?0:1; + readingsSingleUpdate($hash, "state", $state, $evt); + $hash->{HELPER}{OLDSTATE} = $state; + } $hash->{DBHP}= $dbhp; @@ -3041,7 +3065,7 @@ sub DbLog_configcheck($) { if(!@ce || !@se) { $check .= "Connection to database was not successful.
"; $check .= "Recommendation: Plese check logfile for further information.

"; - # $check .= ""; + $check .= ""; return $check; } $check .= "Result of encoding check

"; @@ -5186,7 +5210,7 @@ sub dbReadings($@) { #); #################################################################################### -
+ If configDB is used, the configuration file has to be uploaded into the configDB !


@@ -5807,22 +5831,31 @@ sub dbReadings($@) {
    excludeDevs
      - attr <device> excludeDevs <devspec1>,<devspec2>,<devspec..> + attr <device> excludeDevs <devspec1>[#Reading],<devspec2>[#Reading],<devspec...>
      - The devices "devspec1", "devspec2" up to "devspec.." are excluded from logging into database. This attribute - will only be evaluated if internal "NOTIFYDEV" is not defined. - Thereby devices can be explicit excluded from logging. The devices to exclude can be specified as - device-specification. - For further informations about devspec please see device-specification.

      + The device/reading-combinations "devspec1#Reading", "devspec2#Reading" up to "devspec.." are globally excluded from + logging into the database.
      + The specification of a reading is optional.
      + Thereby devices are explicit and consequently excluded from logging without consideration of another excludes or + includes (e.g. in DEF). + The devices to exclude can be specified as device-specification. +

      - Example
      + Examples
      attr <device> excludeDevs global,Log.*,Cam.*,TYPE=DbLog
      - # The devices global respectively devices starting with "Log" or "Cam" and devices with Type=DbLog - are excluded from database logging.
      -
    + # The devices global respectively devices starting with "Log" or "Cam" and devices with Type=DbLog are excluded from database logging.
    + + attr <device> excludeDevs .*#.*Wirkleistung.* +
    + # All device/reading-combinations which contain "Wirkleistung" in reading are excluded from logging.
    + + attr <device> excludeDevs SMA_Energymeter#Bezug_WirkP_Zaehler_Diff +
    + # The event containing device "SMA_Energymeter" and reading "Bezug_WirkP_Zaehler_Diff" are excluded from logging.
    +

@@ -6088,7 +6121,7 @@ sub dbReadings($@) { TYPE : Type des Devices, z.B. KS300 EVENT : das auftretende Event als volle Zeichenkette, z.B. humidity: 71 (%) READING : Name des Readings, ermittelt aus dem Event, z.B. humidity - VALUE : aktueller Wert des Readings, ermittelt aus dem Event, z.B. humidity + VALUE : aktueller Wert des Readings, ermittelt aus dem Event, z.B. 71 UNIT : Einheit, ermittelt aus dem Event, z.B. % @@ -6162,8 +6195,7 @@ sub dbReadings($@) { #); #################################################################################### -
- + Wird configDB genutzt, ist das Konfigurationsfile in die configDB hochzuladen !


Define @@ -6843,12 +6875,14 @@ sub dbReadings($@) {
    excludeDevs
      - attr <device> excludeDevs <devspec1>,<devspec2>,<devspec..> + attr <device> excludeDevs <devspec1>[#Reading],<devspec2>[#Reading],<devspec...>
      - Die Devices "devspec1", "devspec2" bis "devspec.." werden vom Logging in die Datenbank ausgeschlossen. - Diese Attribut wirkt nur wenn kein Internal "NOTIFYDEV" vorhanden ist. - Dadurch können Devices explizit vom Logging ausgeschlossen werden. + Die Device/Reading-Kombinationen "devspec1#Reading", "devspec2#Reading" bis "devspec..." werden vom Logging in die + Datenbank global ausgeschlossen.
      + Die Angabe eines auszuschließenden Readings ist optional.
      + Somit können Device/Readings explizit bzw. konsequent vom Logging ausgeschlossen werden ohne Berücksichtigung anderer + Excludes oder Includes (z.B. im DEF). Die auszuschließenden Devices können als Geräte-Spezifikation angegeben werden. Für weitere Details bezüglich devspec siehe Geräte-Spezifikation.

      @@ -6856,8 +6890,17 @@ sub dbReadings($@) { attr <device> excludeDevs global,Log.*,Cam.*,TYPE=DbLog
      - # Es werden die Devices global bzw. Devices beginnend mit "Log" oder "Cam" bzw. Devices vom Typ "DbLog" vom Datenbanklogging ausgeschlossen.
      -
    + # Es werden die Devices global bzw. Devices beginnend mit "Log" oder "Cam" bzw. Devices vom Typ "DbLog" vom Logging ausgeschlossen.
    + + attr <device> excludeDevs .*#.*Wirkleistung.* +
    + # Es werden alle Device/Reading-Kombinationen mit "Wirkleistung" im Reading vom Logging ausgeschlossen.
    + + attr <device> excludeDevs SMA_Energymeter#Bezug_WirkP_Zaehler_Diff +
    + # Es wird der Event mit Device "SMA_Energymeter" und Reading "Bezug_WirkP_Zaehler_Diff" vom Logging ausgeschlossen.
    + +