2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

93_DbLog: contrib 4.10.0

git-svn-id: https://svn.fhem.de/fhem/trunk@22012 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2020-05-23 08:54:36 +00:00
parent 5faaa4419b
commit 0cbc22edee

View File

@ -1,5 +1,5 @@
############################################################################################################################################
# $Id: 93_DbLog.pm 21051 2020-01-25 20:53:06Z DS_Starter $
# $Id: 93_DbLog.pm 21801 2020-04-29 09:37:37Z DS_Starter $
#
# 93_DbLog.pm
# written by Dr. Boris Neubert 2007-12-30
@ -30,6 +30,10 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern by DS_Starter:
our %DbLog_vNotesIntern = (
"4.10.0" => "22.05.2020 improve configCheck, new vars \$LASTTIMESTAMP and \$LASTVALUE in valueFn / DbLogValueFn, Forum:#111423 ",
"4.9.13" => "12.05.2020 commandRef changed, AutoInactiveDestroy => 1 for dbh ",
"4.9.12" => "28.04.2020 fix line breaks in set function, Forum: #110673 ",
"4.9.11" => "22.03.2020 logfile entry if DBI module not installed, Forum: #109382 ",
"4.9.10" => "31.01.2020 fix warning, Forum: #107950 ",
"4.9.9" => "21.01.2020 default ParseEvent changed again, Forum: #106769 ",
"4.9.8" => "17.01.2020 adjust configCheck with plotEmbed check. Forum: #107383 ",
@ -303,15 +307,17 @@ return;
###############################################################
sub DbLog_Define($@) {
my ($hash, $def) = @_;
my $name = $hash->{NAME};
my @a = split("[ \t][ \t]*", $def);
return "Error: Perl module ".$DbLogMMDBI." is missing.
Install it on Debian with: sudo apt-get install libdbi-perl" if($DbLogMMDBI);
if($DbLogMMDBI) {
Log3($name, 1, "DbLog $name - ERROR - Perl module ".$DbLogMMDBI." is missing. DbLog module is not loaded ! On Debian systems you can install it with \"sudo apt-get install libdbi-perl\" ");
return "Error: Perl module ".$DbLogMMDBI." is missing. Install it on Debian with: sudo apt-get install libdbi-perl";
}
return "wrong syntax: define <name> DbLog configuration regexp"
if(int(@a) != 4);
my $name = $hash->{NAME};
$hash->{CONFIGURATION} = $a[2];
my $regexp = $a[3];
@ -341,7 +347,7 @@ sub DbLog_Define($@) {
my $ret = DbLog_readCfg($hash);
if ($ret) {
# return on error while reading configuration
Log3($hash->{NAME}, 1, "DbLog $hash->{NAME} - Error while reading $hash->{CONFIGURATION}: '$ret' ");
Log3($name, 1, "DbLog $name - Error while reading $hash->{CONFIGURATION}: '$ret' ");
return $ret;
}
@ -418,14 +424,16 @@ sub DbLog_Attr(@) {
if( $aName eq 'valueFn' ) {
my %specials= (
"%TIMESTAMP" => $name,
"%LASTTIMESTAMP" => $name,
"%DEVICE" => $name,
"%DEVICETYPE" => $name,
"%EVENT" => $name,
"%READING" => $name,
"%VALUE" => $name,
"%LASTVALUE" => $name,
"%UNIT" => $name,
"%IGNORE" => $name,
"%CN" => $name,
"%CN" => $name
);
my $err = perlSyntaxCheck($aVal, %specials);
return $err if($err);
@ -542,11 +550,29 @@ sub DbLog_Set($@) {
my ($hash, @a) = @_;
my $name = $hash->{NAME};
my $async = AttrVal($name, "asyncMode", undef);
my $usage = "Unknown argument, choose one of reduceLog reduceLogNbl reopen rereadcfg:noArg count:noArg countNbl:noArg
deleteOldDays deleteOldDaysNbl userCommand clearReadings:noArg
eraseReadings:noArg addLog ";
$usage .= "listCache:noArg addCacheLine purgeCache:noArg commitCache:noArg exportCache:nopurge,purgecache " if (AttrVal($name, "asyncMode", undef));
$usage .= "configCheck:noArg ";
my $usage = "Unknown argument, choose one of ".
"reduceLog ".
"reduceLogNbl ".
"reopen ".
"rereadcfg:noArg ".
"count:noArg ".
"configCheck:noArg ".
"countNbl:noArg ".
"deleteOldDays ".
"deleteOldDaysNbl ".
"userCommand ".
"clearReadings:noArg ".
"eraseReadings:noArg ".
"addLog "
;
$usage .= "listCache:noArg ".
"addCacheLine ".
"purgeCache:noArg ".
"commitCache:noArg ".
"exportCache:nopurge,purgecache "
if (AttrVal($name, "asyncMode", undef));
my $history = $hash->{HELPER}{TH};
my $current = $hash->{HELPER}{TC};
my (@logs,$dir);
@ -1441,16 +1467,20 @@ sub DbLog_Log($$) {
$DoIt = DbLog_checkDefMinInt($name,$dev_name,$now,$reading,$value);
if ($DoIt) {
my $lastt = $defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME}; # patch Forum:#111423
my $lastv = $defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE};
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME} = $now;
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE} = $value;
# Device spezifische DbLogValueFn-Funktion anwenden
if($DbLogValueFn ne '') {
my $TIMESTAMP = $timestamp;
my $LASTTIMESTAMP = $lastt // 0; # patch Forum:#111423
my $DEVICE = $dev_name;
my $EVENT = $event;
my $READING = $reading;
my $VALUE = $value;
my $LASTVALUE = $lastv // ""; # patch Forum:#111423
my $UNIT = $unit;
my $IGNORE = 0;
my $CN = " ";
@ -1459,7 +1489,9 @@ sub DbLog_Log($$) {
Log3 $name, 2, "DbLog $name -> error device \"$dev_name\" specific DbLogValueFn: ".$@ if($@);
if($IGNORE) {
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $DbLogValueFn
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME} = $lastt if($lastt); # patch Forum:#111423
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE} = $lastv if(defined $lastv);
Log3 $hash->{NAME}, 4, "DbLog $name -> Event ignored by device \"$dev_name\" specific DbLogValueFn - TS: $timestamp, Device: $dev_name, Type: $dev_type, Event: $event, Reading: $reading, Value: $value, Unit: $unit"
if($vb4show && !$hash->{HELPER}{".RUNNING_PID"});
next;
@ -1480,11 +1512,13 @@ sub DbLog_Log($$) {
# zentrale valueFn im DbLog-Device abarbeiten
if($value_fn ne '') {
my $TIMESTAMP = $timestamp;
my $LASTTIMESTAMP = $lastt // 0; # patch Forum:#111423
my $DEVICE = $dev_name;
my $DEVICETYPE = $dev_type;
my $EVENT = $event;
my $READING = $reading;
my $VALUE = $value;
my $LASTVALUE = $lastv // ""; # patch Forum:#111423
my $UNIT = $unit;
my $IGNORE = 0;
my $CN = " ";
@ -1493,7 +1527,9 @@ sub DbLog_Log($$) {
Log3 $name, 2, "DbLog $name -> error valueFn: ".$@ if($@);
if($IGNORE) {
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $value_fn
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{TIME} = $lastt if($lastt); # patch Forum:#111423
$defs{$dev_name}{Helper}{DBLOG}{$reading}{$hash->{NAME}}{VALUE} = $lastv if(defined $lastv);
Log3 $hash->{NAME}, 4, "DbLog $name -> Event ignored by valueFn - TS: $timestamp, Device: $dev_name, Type: $dev_type, Event: $event, Reading: $reading, Value: $value, Unit: $unit"
if($vb4show && !$hash->{HELPER}{".RUNNING_PID"});
next;
@ -2306,12 +2342,12 @@ sub DbLog_PushAsync(@) {
my ($useac,$useta) = DbLog_commitMode($hash);
eval {
if(!$useac) {
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} elsif($useac == 1) {
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} else {
# Server default
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
}
};
if ($@) {
@ -2967,12 +3003,12 @@ sub DbLog_ConnectPush($;$$) {
my ($useac,$useta) = DbLog_commitMode($hash);
eval {
if(!$useac) {
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => $utf8 });
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} elsif($useac == 1) {
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => $utf8 });
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} else {
# Server default
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, mysql_enable_utf8 => $utf8 });
$dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
}
};
@ -3034,12 +3070,12 @@ sub DbLog_ConnectNewDBH($) {
my ($useac,$useta) = DbLog_commitMode($hash);
eval {
if(!$useac) {
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} elsif($useac == 1) {
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
} else {
# Server default
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, mysql_enable_utf8 => $utf8 });
$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1, mysql_enable_utf8 => $utf8 });
}
};
@ -3744,14 +3780,29 @@ sub DbLog_configcheck($) {
my $dbi = $DBI::VERSION; # DBI Version
my %drivers = DBI->installed_drivers();
my $dv = "";
if($dbmodel =~ /MYSQL/i) {
if($dbmodel =~ /MYSQL/xi) {
for (keys %drivers) {
$dv = $_ if($_ =~ /mysql|mariadb/);
$dv = $_ if($_ =~ /mysql|mariadb/x);
}
}
my $dbd = ($dbmodel =~ /POSTGRESQL/xi) ? "Pg: ".$DBD::Pg::VERSION: # DBD Version
($dbmodel =~ /MYSQL/xi && $dv) ? "$dv: ".$DBD::mysql::VERSION:
($dbmodel =~ /SQLITE/xi) ? "SQLite: ".$DBD::SQLite::VERSION:"Undefined";
my $dbdhint = "";
my $dbdupd = 0;
if($dbmodel =~ /MYSQL/xi && $dv) { # check DBD Mindest- und empfohlene Version
my $dbdver = $DBD::mysql::VERSION * 1; # String to Zahl Konversion
if($dbdver < 4.032) {
$dbdhint = "<b>Caution:</b> Your DBD version doesn't support UTF8. ";
$dbdupd = 1;
} elsif ($dbdver < 4.042) {
$dbdhint = "<b>Caution:</b> Full UTF-8 support exists from DBD version 4.032, but installing DBD version 4.042 is highly suggested. ";
$dbdupd = 1;
} else {
$dbdhint = "Your DBD version fulfills UTF8 support, no need to update DBD.";
}
}
my $dbd = ($dbmodel =~ /POSTGRESQL/i)?"Pg: ".$DBD::Pg::VERSION: # DBD Version
($dbmodel =~ /MYSQL/i && $dv)?"$dv: ".$DBD::mysql::VERSION:
($dbmodel =~ /SQLITE/i)?"SQLite: ".$DBD::SQLite::VERSION:"Undefined";
my ($errcm,$supd,$uptb) = DbLog_checkModVer($name); # DbLog Version
@ -3761,14 +3812,14 @@ sub DbLog_configcheck($) {
$check .= "Used DBI (Database independent interface) version: $dbi <br>";
$check .= "Used DBD (Database driver) version $dbd <br>";
if($errcm) {
$check .= "<b>Recommendation:</b> ERROR - $errcm <br><br>";
$check .= "<b>Recommendation:</b> ERROR - $errcm. $dbdhint <br><br>";
}
if($supd) {
$check .= "Used DbLog version: $hash->{HELPER}{VERSION}.<br>$uptb <br>";
$check .= "<b>Recommendation:</b> You should update FHEM to get the recent DbLog version from repository ! <br><br>";
$check .= "<b>Recommendation:</b> You should update FHEM to get the recent DbLog version from repository ! $dbdhint <br><br>";
} else {
$check .= "Used DbLog version: $hash->{HELPER}{VERSION}.<br>$uptb <br>";
$check .= "<b>Recommendation:</b> No update of DbLog is needed. <br><br>";
$check .= "<b>Recommendation:</b> No update of DbLog is needed. $dbdhint <br><br>";
}
### Configuration read check
@ -3800,11 +3851,19 @@ sub DbLog_configcheck($) {
$chutf8mod = @ce ? uc($ce[1]) : "no result";
@se = DbLog_sqlget($hash,"SHOW VARIABLES LIKE 'character_set_database'");
$chutf8dat = @se ? uc($se[1]) : "no result";
if($chutf8mod eq $chutf8dat) {
$rec = "settings o.k.";
} else {
$rec = "Both encodings should be identical. You can adjust the usage of UTF8 connection by setting the UTF8 parameter in file '$hash->{CONFIGURATION}' to the right value. ";
}
if(uc($chutf8mod) ne "UTF8" && uc($chutf8dat) ne "UTF8") {
$dbdhint = "";
} else {
$dbdhint .= " If you want use UTF8 database option, you must update DBD (Database driver) to at least version 4.032. " if($dbdupd);
}
}
if($dbmodel =~ /POSTGRESQL/) {
@ce = DbLog_sqlget($hash,"SHOW CLIENT_ENCODING");
@ -3840,7 +3899,7 @@ sub DbLog_configcheck($) {
$check .= "<u><b>Result of encoding check</u></b><br><br>";
$check .= "Encoding used by Client (connection): $chutf8mod <br>" if($dbmodel !~ /SQLITE/);
$check .= "Encoding used by DB $dbname: $chutf8dat <br>";
$check .= "<b>Recommendation:</b> $rec <br><br>";
$check .= "<b>Recommendation:</b> $rec $dbdhint <br><br>";
### Check Betriebsmodus
#######################################################################
@ -4522,21 +4581,32 @@ sub DbLog_AddLog($$$$$) {
$defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{TIME} = $now;
$defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{VALUE} = $read_val;
$ts = TimeNow();
# Anwender spezifische Funktion anwenden
if($value_fn ne '') {
my $lastt = $defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{TIME}; # patch Forum:#111423
my $lastv = $defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{VALUE};
my $TIMESTAMP = $ts;
my $LASTTIMESTAMP = $lastt // 0; # patch Forum:#111423
my $DEVICE = $dev_name;
my $DEVICETYPE = $dev_type;
my $EVENT = $event;
my $READING = $dev_reading;
my $VALUE = $read_val;
my $LASTVALUE = $lastv // ""; # patch Forum:#111423
my $UNIT = $ut;
my $IGNORE = 0;
my $CN = $cn?$cn:"";
eval $value_fn;
Log3 $name, 2, "DbLog $name -> error valueFn: ".$@ if($@);
next if($IGNORE); # aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $value_fn
if($IGNORE) { # aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt
$defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{TIME} = $lastt if($lastt); # patch Forum:#111423
$defs{$dev_name}{Helper}{DBLOG}{$dev_reading}{$hash->{NAME}}{VALUE} = $lastv if(defined $lastv);
next;
}
my ($yyyy, $mm, $dd, $hh, $min, $sec) = ($TIMESTAMP =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/);
eval { my $epoch_seconds_begin = timelocal($sec, $min, $hh, $dd, $mm-1, $yyyy-1900); };
@ -4618,21 +4688,33 @@ sub DbLog_addCacheLine($$$$$$$$) {
} else {
$value_fn = '';
}
if($value_fn ne '') {
my $lastt;
my $lastv;
if($defs{$i_dev}) {
$lastt = $defs{$i_dev}{Helper}{DBLOG}{$i_reading}{$hash->{NAME}}{TIME};
$lastv = $defs{$i_dev}{Helper}{DBLOG}{$i_reading}{$hash->{NAME}}{VALUE};
}
my $TIMESTAMP = $i_timestamp;
my $LASTTIMESTAMP = $lastt // 0; # patch Forum:#111423
my $DEVICE = $i_dev;
my $DEVICETYPE = $i_type;
my $EVENT = $i_evt;
my $READING = $i_reading;
my $VALUE = $i_val;
my $LASTVALUE = $lastv // ""; # patch Forum:#111423
my $UNIT = $i_unit;
my $IGNORE = 0;
my $CN = " ";
eval $value_fn;
Log3 $name, 2, "DbLog $name -> error valueFn: ".$@ if($@);
if($IGNORE) {
# aktueller Event wird nicht geloggt wenn $IGNORE=1 gesetzt in $value_fn
if($IGNORE) { # kein add wenn $IGNORE=1 gesetzt
$defs{$i_dev}{Helper}{DBLOG}{$i_reading}{$hash->{NAME}}{TIME} = $lastt if($defs{$i_dev} && $lastt); # patch Forum:#111423
$defs{$i_dev}{Helper}{DBLOG}{$i_reading}{$hash->{NAME}}{VALUE} = $lastv if($defs{$i_dev} && defined $lastv);
Log3 $hash->{NAME}, 4, "DbLog $name -> Event ignored by valueFn - TS: $i_timestamp, Device: $i_dev, Type: $i_type, Event: $i_evt, Reading: $i_reading, Value: $i_val, Unit: $i_unit";
next;
}
@ -4677,7 +4759,6 @@ sub DbLog_addCacheLine($$$$$$$$) {
return;
}
#########################################################################################
#
# Subroutine cutCol - Daten auf maximale Länge beschneiden
@ -5054,12 +5135,12 @@ sub DbLog_reduceLogNbl($) {
my ($useac,$useta) = DbLog_commitMode($hash);
if(!$useac) {
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1, AutoCommit => 0 });};
} elsif($useac == 1) {
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1, AutoCommit => 1 });};
} else {
# Server default
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1 });};
}
if ($@) {
$err = encode_base64($@,"");
@ -5478,12 +5559,12 @@ sub DbLog_deldaysNbl($) {
my ($useac,$useta) = DbLog_commitMode($hash);
if(!$useac) {
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 0, AutoInactiveDestroy => 1 });};
} elsif($useac == 1) {
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoCommit => 1, AutoInactiveDestroy => 1 });};
} else {
# Server default
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1 });};
eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, AutoInactiveDestroy => 1 });};
}
if ($@) {
$error = encode_base64($@,"");
@ -6088,12 +6169,12 @@ sub DbLog_setVersionInfo($) {
if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) {
# META-Daten sind vorhanden
$modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{DbLog}{META}}
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbLog.pm 21051 2020-01-25 20:53:06Z DS_Starter $ im Kopf komplett! vorhanden )
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbLog.pm 21801 2020-04-29 09:37:37Z DS_Starter $ im Kopf komplett! vorhanden )
$modules{$type}{META}{x_version} =~ s/1.1.1/$v/g;
} else {
$modules{$type}{META}{x_version} = $v;
}
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbLog.pm 21051 2020-01-25 20:53:06Z DS_Starter $ im Kopf komplett! vorhanden )
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbLog.pm 21801 2020-04-29 09:37:37Z DS_Starter $ im Kopf komplett! vorhanden )
if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) {
# es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen
# mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden
@ -6255,7 +6336,9 @@ sub DbLog_showChildHandles ($$$$) {
# connection => "mysql:database=fhem;host=&lt;database host&gt;;port=3306",
# user => "fhemuser",
# password => "fhempassword",
# # optional enable(1) / disable(0) UTF-8 support (at least V 4.042 is necessary)
# # optional enable(1) / disable(0) UTF-8 support
# # (full UTF-8 support exists from DBD::mysql version 4.032, but installing
# # 4.042 is highly suggested)
# utf8 => 1
#);
####################################################################################
@ -7027,10 +7110,11 @@ sub DbLog_showChildHandles ($$$$) {
The attribute <i>DbLogValueFn</i> will be propagated to all devices if DbLog is used.
This attribute contains a Perl expression that can use and change values of $TIMESTAMP, $READING, $VALUE (value of
reading) and $UNIT (unit of reading value). That means the changed values are logged.
You also have readonly access to $DEVICE (the source device name) and $EVENT for evaluation in your expression. <br>
$DEVICE and $EVENT cannot be changed. <br>
If $TIMESTAMP should be changed, it must meet the condition "yyyy-mm-dd hh:mm:ss", otherwise the $timestamp wouldn't
reading) and $UNIT (unit of reading value). That means the changed values are logged. <br>
Furthermore you have readonly access to $DEVICE (the source device name), $EVENT, $LASTTIMESTAMP and $LASTVALUE
for evaluation in your expression.
The variables $LASTTIMESTAMP and $LASTVALUE contain time and value of the last logged dataset of $DEVICE / $READING. <br>
If the $TIMESTAMP is to be changed, it must meet the condition "yyyy-mm-dd hh:mm:ss", otherwise the $timestamp wouldn't
be changed.
In addition you can set the variable $IGNORE=1 if you want skip a dataset from logging. <br>
@ -7414,9 +7498,10 @@ attr SMA_Energymeter DbLogValueFn
</code><br>
The attribute contains a Perl expression that can use and change values of $TIMESTAMP, $DEVICE, $DEVICETYPE, $READING,
$VALUE (value of reading) and $UNIT (unit of reading value).
You also have readonly-access to $EVENT for evaluation in your expression. <br>
If $TIMESTAMP should be changed, it must meet the condition "yyyy-mm-dd hh:mm:ss", otherwise the $timestamp wouldn't
$VALUE (value of reading) and $UNIT (unit of reading value). <br>
Furthermore you have readonly access to $EVENT, $LASTTIMESTAMP and $LASTVALUE for evaluation in your expression.
The variables $LASTTIMESTAMP and $LASTVALUE contain time and value of the last logged dataset of $DEVICE / $READING. <br>
If $TIMESTAMP is to be changed, it must meet the condition "yyyy-mm-dd hh:mm:ss", otherwise the $timestamp wouldn't
be changed.
In addition you can set the variable $IGNORE=1 if you want skip a dataset from logging. <br><br>
@ -7577,7 +7662,9 @@ attr SMA_Energymeter DbLogValueFn
# connection => "mysql:database=fhem;host=&lt;database host&gt;;port=3306",
# user => "fhemuser",
# password => "fhempassword",
# # optional enable(1) / disable(0) UTF-8 support (at least V 4.042 is necessary)
# # optional enable(1) / disable(0) UTF-8 support
# # (full UTF-8 support exists from DBD::mysql version 4.032, but installing
# # 4.042 is highly suggested)
# utf8 => 1
#);
####################################################################################
@ -8417,9 +8504,10 @@ attr SMA_Energymeter DbLogValueFn
Wird DbLog genutzt, wird in allen Devices das Attribut <i>DbLogValueFn</i> propagiert.
Es kann über einen Perl-Ausdruck auf die Variablen $TIMESTAMP, $READING, $VALUE (Wert des Readings) und
$UNIT (Einheit des Readingswert) zugegriffen werden und diese verändern, d.h. die veränderten Werte werden geloggt.
Außerdem hat man lesenden Zugriff auf $DEVICE (den Namen des Devices) und $EVENT für eine Auswertung im Perl-Ausdruck.
$DEVICE und $EVENT kann nicht verändert werden. <br>
$UNIT (Einheit des Readingswert) zugegriffen werden und diese verändern, d.h. die veränderten Werte werden geloggt. <br>
Außerdem hat man Lesezugriff auf $DEVICE (den Namen des Quellgeräts), $EVENT, $LASTTIMESTAMP und $LASTVALUE
zur Bewertung in Ihrem Ausdruck. <br>
Die Variablen $LASTTIMESTAMP und $LASTVALUE enthalten Zeit und Wert des zuletzt protokollierten Datensatzes von $DEVICE / $READING. <br>
Soll $TIMESTAMP verändert werden, muss die Form "yyyy-mm-dd hh:mm:ss" eingehalten werden, ansonsten wird der
geänderte $timestamp nicht übernommen.
Zusätzlich kann durch Setzen der Variable "$IGNORE=1" der Datensatz vom Logging ausgeschlossen werden. <br>
@ -8804,10 +8892,10 @@ attr SMA_Energymeter DbLogValueFn
</code><br>
Es kann über einen Perl-Ausdruck auf die Variablen $TIMESTAMP, $DEVICE, $DEVICETYPE, $READING, $VALUE (Wert des Readings) und
$UNIT (Einheit des Readingswert) zugegriffen werden und diese verändern, d.h. die veränderten Werte werden geloggt.
Außerdem hat man lesenden Zugriff auf $EVENT für eine Auswertung im Perl-Ausdruck.
Diese Variable kann aber nicht verändert werden. <br>
Soll $TIMESTAMP verändert werden, muss die Form "yyyy-mm-dd hh:mm:ss" eingehalten werden, ansonsten wird der
$UNIT (Einheit des Readingswert) zugegriffen werden und diese verändern, d.h. die veränderten Werte werden geloggt. <br>
Außerdem hat man Lesezugriff auf $EVENT, $LASTTIMESTAMP und $LASTVALUE zur Bewertung im Ausdruck. <br>
Die Variablen $LASTTIMESTAMP und $LASTVALUE enthalten Zeit und Wert des zuletzt protokollierten Datensatzes von $DEVICE / $READING. <br>
Soll $TIMESTAMP verändert werden, muss die Form "yyyy-mm-dd hh:mm:ss" eingehalten werden. Anderenfalls wird der
geänderte $timestamp nicht übernommen.
Zusätzlich kann durch Setzen der Variable "$IGNORE=1" ein Datensatz vom Logging ausgeschlossen werden. <br><br>