From b0fbf0a1526918f2485c90151e44374dd2eaddcd Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sun, 19 Feb 2023 18:20:55 +0000 Subject: [PATCH] 93_DbLog: adapt configCheck, new get...configCheck, commref edited git-svn-id: https://svn.fhem.de/fhem/trunk@27250 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/93_DbLog.pm | 481 ++++++++++++++++++++++++++---------------- 2 files changed, 295 insertions(+), 187 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 617f52d16..dcffa157e 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. + - change: 93_DbLog: adapt configCheck, new get...configCheck, commref edited - change: 93_DbLog: adapt configCheck - feature: 93_DbRep: Support of utf8mb4 collation, minor fixes, new setter migrateCollation diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index 42e0f12b1..06089007a 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -38,6 +38,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern by DS_Starter: my %DbLog_vNotesIntern = ( + "5.8.3" => "19.02.2023 adapt DbLog_configcheck, new get ... configCheck, commandref edited ", "5.8.2" => "18.02.2023 adapt DbLog_configcheck, Forum: https://forum.fhem.de/index.php/topic,132163.msg1264320.html#msg1264320 ", "5.8.1" => "13.02.2023 change field type of DbLogInclude, DbLogExclude to textField-long, configCheck evaluate collation ". "_DbLog_SBP_connectDB: UTF8 -> evaluate DB character/collation set and use it for ". @@ -109,7 +110,7 @@ my %DbLog_hset = ( stopSubProcess => { fn => \&_DbLog_setstopSubProcess }, purgeCache => { fn => \&_DbLog_setpurgeCache }, commitCache => { fn => \&_DbLog_setcommitCache }, - configCheck => { fn => \&_DbLog_setconfigCheck }, + configCheck => { fn => \&DbLog_configcheck }, reopen => { fn => \&_DbLog_setreopen }, rereadcfg => { fn => \&_DbLog_setrereadcfg }, addLog => { fn => \&_DbLog_setaddLog }, @@ -137,6 +138,7 @@ my %DbLog_hget = ( webchart => { fn => \&_DbLog_chartQuery }, plotdata => { fn => \&_DbLog_plotData }, retrieve => { fn => \&_DbLog_chartQuery }, + configCheck => { fn => \&DbLog_configcheck }, ); my %DbLog_columns = ("DEVICE" => 64, @@ -741,18 +743,6 @@ sub _DbLog_setcommitCache { ## no critic "not used" return; } -################################################################ -# Setter configCheck -################################################################ -sub _DbLog_setconfigCheck { ## no critic "not used" - my $paref = shift; - my $hash = $paref->{hash}; - - my $check = DbLog_configcheck($hash); - -return $check; -} - ################################################################ # Setter reopen ################################################################ @@ -1344,7 +1334,7 @@ sub DbLog_Log { if($DbLogExclude && $DbLogSelectionMode =~ m/Exclude/) { # Bsp: "(temperature|humidity):300,battery:3600:force" my @v1 = DbLog_attrLong2Array ($DbLogExclude, ','); - + for (my $i = 0; $i < int(@v1); $i++) { my @v2 = split /:/, $v1[$i]; $DoIt = 0 if(!$v2[1] && $reading =~ m,^$v2[0]$,); # Reading matcht auf Regexp, kein MinIntervall angegeben @@ -1368,7 +1358,7 @@ sub DbLog_Log { if($DoIt == 0) { if($DbLogInclude && ($DbLogSelectionMode =~ m/Include/)) { my @v1 = DbLog_attrLong2Array ($DbLogInclude, ','); - + for (my $i = 0; $i < int(@v1); $i++) { my @v2 = split /:/, $v1[$i]; $DoIt = 1 if($reading =~ m,^$v2[0]$,); # Reading matcht auf Regexp @@ -1860,10 +1850,10 @@ sub _DbLog_checkDefMinInt { my $DbLogExclude = AttrVal ($dev_name, "DbLogExclude", undef); $DbLogExclude = join ",", DbLog_attrLong2Array ($DbLogExclude, ','); - + my $DbLogInclude = AttrVal ($dev_name, "DbLogInclude", undef); $DbLogInclude = join ",", DbLog_attrLong2Array ($DbLogInclude, ','); - + $defminint =~ s/[\s\n]/,/g; my @adef = split /,/, $defminint; my $inex = ($DbLogExclude ? $DbLogExclude."," : "").($DbLogInclude ? $DbLogInclude : ""); @@ -2604,13 +2594,13 @@ sub _DbLog_SBP_connectDB { if($utf8) { if($model eq "MYSQL") { - $dbh->{mysql_enable_utf8} = 1; + $dbh->{mysql_enable_utf8} = 1; ($err, my @se) = _DbLog_prepExecQueryOnly ($name, $dbh, "SHOW VARIABLES LIKE 'collation_database'"); return ($err, q{}) if($err); - + my $dbcharset = @se ? $se[1] : 'noresult'; - + _DbLog_SBP_Log3Parent ( { name => $name, level => 4, msg => qq(Database Character set is >$dbcharset<), @@ -2618,14 +2608,14 @@ sub _DbLog_SBP_connectDB { subprocess => $subprocess } ); - - if ($dbcharset !~ /noresult|ucs2|utf16|utf32/ixs) { # Impermissible Client Character Sets -> https://dev.mysql.com/doc/refman/8.0/en/charset-connection.html + + if ($dbcharset !~ /noresult|ucs2|utf16|utf32/ixs) { # Impermissible Client Character Sets -> https://dev.mysql.com/doc/refman/8.0/en/charset-connection.html my $collation = $dbcharset; $dbcharset = (split '_', $collation, 2)[0]; - + ($err, undef) = _DbLog_SBP_dbhDo ($name, $dbh, qq(set names "$dbcharset" collate "$collation"), $subprocess); # set names utf8 collate utf8_general_ci return ($err, q{}) if($err); - } + } } if($model eq "SQLITE") { @@ -5107,7 +5097,7 @@ sub DbLog_SBP_CheckAndInit { my $nscd = shift // 0; # 1 - kein senden Connectiondata direkt nach Start Subprozess return "Shutdown sequence running" if(defined $hash->{HELPER}{SHUTDOWNSEQ}); # Shutdown Sequenz läuft - + my $name = $hash->{NAME}; my $err = q{}; @@ -5858,7 +5848,8 @@ sub DbLog_Get { return &{$DbLog_hget{$opt}{fn}} ($params); } - my $getlist = "Unknown argument $opt, choose one of ". + my $getlist = "Unknown argument $opt, choose one of ". + "configCheck:noArg ". "ReadingsVal: ". "ReadingsTimestamp ". "ReadingsValTimestamp ". @@ -6088,7 +6079,7 @@ sub _DbLog_createQuerySql { $offset = $a[6]; $limit = $a[7]; $xaxis = 'TIMESTAMP'; - + if ($querytype eq 'last') { $limit = '10' if(!$limit); } @@ -6098,7 +6089,7 @@ sub _DbLog_createQuerySql { $endtime =~ s/_/ / if($endtime); my ($sql, $jsonstring, $countsql); - + my ($hourstats, $daystats, $weekstats, $monthstats, $yearstats) = ('error', 'error', 'error', 'error', 'error'); if ($device && $reading && $starttime && $endtime) { @@ -6205,7 +6196,7 @@ sub _DbLog_createQuerySql { } $sql = 'error'; - + if ($querytype eq 'getdevices' || $querytype eq 'alldevices') { $sql = "SELECT distinct(device) FROM $history"; } @@ -6981,7 +6972,9 @@ return $ret; # ########################################################################## sub DbLog_configcheck { - my $hash = shift; + my $paref = shift; + my $hash = $paref->{hash}; + my $name = $hash->{NAME}; my $dbmodel = $hash->{MODEL}; my $dbconn = $hash->{dbconn}; @@ -7054,11 +7047,11 @@ sub DbLog_configcheck { $check .= "Used Perl version: $pv
"; $check .= "Used DBI (Database independent interface) version: $dbi
"; $check .= "Used DBD (Database driver) version $dbd
"; - + ($err, $upd, $msg, $rec) = _DbLog_checkModVer($name); # DbLog Version $check .= "Used DbLog version: $hash->{HELPER}{VERSION}
$msg
"; - + if ($err) { $check .= "Rating: ".$nok."
"; } @@ -7231,27 +7224,48 @@ sub DbLog_configcheck { my $wall = ""; for my $web (@webdvs) { - my $pf = AttrVal($web,"plotfork",0); - my $pe = AttrVal($web,"plotEmbed",0); - $forks = 0 if(!$pf); - $emb = 0 if($pe =~ /[01]/); + my $pf = AttrVal ($web, 'plotfork', 0); + my $lps = AttrVal ($web, 'longpollSVG', 0); + my $pe = AttrVal ($web, 'plotEmbed', 0); - if(!$pf || $pe =~ /[01]/) { - $wall .= "".$web.": plotfork=".$pf." / plotEmbed=".$pe."
"; + $forks = 0 if(!$pf); + $emb = 0 if($lps && $pe != 1); + + if(!$pf || ($lps && $pe != 1)) { + $wall .= "".$web.": plotfork=".$pf." / plotEmbed=".$pe." / longpollSVG=".$lps."
"; } else { - $wall .= $web.": plotfork=".$pf." / plotEmbed=".$pe."
"; + $wall .= $web.": plotfork=".$pf." / plotEmbed=".$pe." / longpollSVG=".$lps."
"; } } if (!$forks || !$emb) { - $check .= "WARNING - at least one of your FHEMWEB devices has attribute \"plotfork = 1\" and/or attribute \"plotEmbed = 2\" not set.

"; + $rec = q{}; + + if (!$forks) { + $check .= "WARNING - at least one of your FHEMWEB devices has attribute 'plotfork = 1' not set.
"; + } + + if (!$emb) { + $check .= "WARNING - at least one of your FHEMWEB devices has attribute 'longpollSVG = 1' but not 'plotEmbed = 1' set.
"; + } + + $check .= "
"; $check .= $wall; $check .= "
"; $check .= "Rating: ".$warn."
"; - $rec = "You should set attribute \"plotfork = 1\" and \"plotEmbed = 2\" in relevant devices. ". - "If these attributes are not set, blocking situations may occure when creating plots. ". - "Note: Your system must have sufficient memory to handle parallel running Perl processes. See also global attribute \"blockingCallMax\".
" + + if (!$forks) { + $rec .= "You should set attribute 'plotfork = 1' in relevant devices. ". + "If this attribute is not set, blocking situations may occure when creating plots.
". + "(Note: Your system must have sufficient memory to handle parallel running Perl processes.) ". + "See also global attribute blockingCallMax.
" + } + + if (!$emb) { + $rec .= "You have to set the attribute 'plotEmbed = 1' in FHEMWEB devices where 'longpollSVG' should be used. ". + "Refer to longpollSVG for further information.
"; + } } else { $check .= $wall; @@ -7714,7 +7728,7 @@ return $check; sub _DbLog_checkModVer { my $name = shift; my $src = "http://fhem.de/fhemupdate/controls_fhem.txt"; - + my $msg = q{}; my $rec = q{}; @@ -7728,7 +7742,7 @@ sub _DbLog_checkModVer { my $ctrlFileName = $2; my ($err, $remCtrlFile) = __DbLog_updGetUrl($name, $src); - + if ($err) { $msg = "Check of SVN DbLog version not possible: ".$err; $rec = "Try to execute the configCheck later again. Inform the DbLog Maintainer if it seems to be a permanent problem."; @@ -7743,17 +7757,17 @@ sub _DbLog_checkModVer { my @remList = split /\R/, $remCtrlFile; my $root = $attr{global}{modpath}; - + Log3 ($name, 4, "DbLog $name - configCheck: Got SVN $ctrlFileName with ".int(@remList)." entries."); - + open (FD, "$root/FHEM/$ctrlFileName") or do { $msg = "Automatic check of SVN DbLog version not possible: $!"; $rec = "Try to solve the problem that has occurred. Compare your local DbLog version with the public version manually."; return (1, 0, $msg, $rec); }; - + my @locList = map { $_ =~ s/[\r\n]//; $_ } ; close(FD); - + Log3 ($name, 4, "DbLog $name - configCheck: Got local $ctrlFileName with ".int(@locList)." entries."); my %lh; @@ -7763,7 +7777,7 @@ sub _DbLog_checkModVer { next if($l[0] ne "UPD" || $l[3] !~ /93_DbLog/); $lh{$l[3]}{TS} = $l[1]; $lh{$l[3]}{LEN} = $l[2]; - + Log3 ($name, 4, "DbLog $name - configCheck: local version from last update - creation time: ".$lh{$l[3]}{TS}." - bytes: ".$lh{$l[3]}{LEN}); } @@ -7777,25 +7791,25 @@ sub _DbLog_checkModVer { if (!$fileOk) { Log3 ($name, 4, "DbLog $name - configCheck: New SVN version of $fName found - creation time: $r[1] ($r[2] Bytes)"); - + $msg = "A new DbLog version is available (creation time: $r[1], size: $r[2] bytes)"; - $rec = "You should update FHEM to get the recent DbLog version from repository!"; + $rec = "You should update FHEM to get the recent DbLog version from repository."; return (0, 1, $msg, $rec); } - + my $sz = -s $fPath; - + if ($fileOk && defined($sz) && $sz ne $r[2]) { Log3 ($name, 4, "DbLog $name - configCheck: SVN version of $fName creation time: $r[1] ($r[2] Bytes) differs from local one ($sz Bytes)"); - + $msg = "Your local DbLog module is modified. The SVN version of $fName has creation time: $r[1] ($r[2] Bytes)"; - $rec = "You should update FHEM to get the recent DbLog version from repository!"; + $rec = "You should update FHEM to get the recent DbLog version from repository."; return (0, 1, $msg, $rec); } - + last; } - + $msg = "Your local DbLog module is up to date."; $rec = "Update of DbLog is not needed."; @@ -7816,13 +7830,13 @@ sub __DbLog_updGetUrl { if($err) { Log3 ($name, 1, "DbLog $name - configCheck: ERROR while connecting to fhem.de: $err"); - + return ($err, ""); } - + if(!$data) { Log3 ($name, 1, "DbLog $name - configCheck: ERROR $url: empty file received"); - + $err = 1; return ($err, ""); } @@ -8233,14 +8247,14 @@ return($txt); } ############################################################################### -# Einen Attributinhalt vom Typ textField-long splitten und als +# Einen Attributinhalt vom Typ textField-long splitten und als # Array zurückgeben # Optional kann das Split-Zeichen, default ',', angegeben werden. ############################################################################### sub DbLog_attrLong2Array { my $content = shift; my $sptchar = shift // q{,}; - + return if(!$content); my @v = map { my $p = $_; $p =~ s/\s//xg; $p; } split /$sptchar/xs, $content; ## no critic 'Map blocks' @@ -8637,19 +8651,19 @@ return; SVN -> contrib/dblog/db_create_<DBType>.sql.
(Caution: The local FHEM-Installation subdirectory ./contrib/dblog doesn't contain the freshest scripts!)

- + The default installation of the MySQL/MariaDB database provides for the use of the utf8_bin collation. With this setting, characters up to 3 bytes long can be stored, which is generally sufficient. - However, if characters with a length of 4 bytes (e.g. emojis) are to be stored in the database, the utf8mb4 + However, if characters with a length of 4 bytes (e.g. emojis) are to be stored in the database, the utf8mb4 character set must be used.
Accordingly, in this case the MySQL/MariaDB database would be created with the following statement:

- +
- - In the configuration file (see below) utf8 support must be enabled with the key utf8 => 1 if utf8 is to be + + In the configuration file (see below) utf8 support must be enabled with the key utf8 => 1 if utf8 is to be used.

The database contains two tables: current and history.
@@ -8775,7 +8789,7 @@ return; After you have defined your DbLog-device it is recommended to run the configuration check


@@ -8816,7 +8830,7 @@ return; @@ -8825,7 +8839,7 @@ return; If the notes don't lead to success, please increase verbose level of the DbLog-device to 4 or 5 and observe entries in logfile relating to the DbLog-device. - For problem analysis please post the output of "list <name>", the result of "set <name> configCheck" and the + For problem analysis please post the output of "list <name>", the result of "get <name> configCheck" and the logfile entries of DbLog-device to the forum thread.

@@ -8838,7 +8852,9 @@ return;