From 2d1e442e36de9595bf2c74f3a11687889635fff2 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Fri, 12 Apr 2019 12:29:02 +0000 Subject: [PATCH] 93_DbLog: add support for Meta.pm and delayed shutdown, attribute shutdownWait removed, direct attribute help in FHEMWEB git-svn-id: https://svn.fhem.de/fhem/trunk@19158 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 + fhem/FHEM/93_DbLog.pm | 1098 +++++++++++++++++++++++++---------------- 2 files changed, 686 insertions(+), 416 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 55a8ece64..60f36a641 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: add support for Meta.pm and delayed shutdown, attribute + shutdownWait removed, direct attribute help in FHEMWEB, + !!! NOTE !!! attr shutdownWait will be deleted it set and + an appropriated log message appears. - bugfix: 70_BRAVIA: fix channel presets - bugfix: 49_SSCam: fix perl warnings, Forum: 45671.msg927912.html#msg927912 - new: 10_WS980: new module to control the WS980Wifi weather station diff --git a/fhem/FHEM/93_DbLog.pm b/fhem/FHEM/93_DbLog.pm index a8371e70d..a5897a271 100644 --- a/fhem/FHEM/93_DbLog.pm +++ b/fhem/FHEM/93_DbLog.pm @@ -13,205 +13,12 @@ # redesigned 2016-2019 by DS_Starter with credits by: JoeAllb, DeeSpe # ############################################################################################################################################ -# Versions History done by DS_Starter: -# -# 3.13.3 04.03.2019 addLog better Log3 Outputs -# 3.13.2 09.02.2019 Commandref revised -# 3.13.1 27.11.2018 DbLog_ExecSQL log output changed -# 3.13.0 12.11.2018 adding attributes traceFlag, traceLevel -# 3.12.7 10.11.2018 addLog considers DbLogInclude (Forum:#92854) -# 3.12.6 22.10.2018 fix timer not deleted if reopen after reopen xxx (Forum: https://forum.fhem.de/index.php/topic,91869.msg848433.html#msg848433) -# 3.12.5 12.10.2018 charFilter: "\xB0C" substitution by "°C" added and usage in DbLog_Log changed -# 3.12.4 10.10.2018 return non-saved datasets back in asynch mode only if transaction is used -# 3.12.3 08.10.2018 Log output of recuceLogNbl enhanced, some functions renamed -# 3.12.2 07.10.2018 $hash->{HELPER}{REOPEN_RUNS_UNTIL} contains the time the DB is closed -# 3.12.1 19.09.2018 use Time::Local (forum:#91285) -# 3.12.0 04.09.2018 corrected SVG-select (https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640) -# 3.11.0 02.09.2018 reduceLog, reduceLogNbl - optional "days newer than" part added -# 3.10.10 05.08.2018 commandref revised reducelogNbl -# 3.10.9 23.06.2018 commandref added hint about special characters in passwords -# 3.10.8 21.04.2018 addLog - not available reading can be added as new one (forum:#86966) -# 3.10.7 16.04.2018 fix generate addLog-event if device or reading was not found by addLog -# 3.10.6 13.04.2018 verbose level in addlog changed if reading not found -# 3.10.5 12.04.2018 fix warnings -# 3.10.4 11.04.2018 fix addLog if no valueFn is used -# 3.10.3 10.04.2018 minor fixes in addLog -# 3.10.2 09.04.2018 add qualifier CN= to addlog -# 3.10.1 04.04.2018 changed event parsing of Weather -# 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 -# 3.8.7 28.02.2018 changed DbLog_sampleDataFn - no change limits got fron SVG, commandref revised -# 3.8.6 25.02.2018 commandref revised (forum:#84953) -# 3.8.5 16.02.2018 changed ParseEvent for Zwave -# 3.8.4 07.02.2018 minor fixes of "$@", code review, eval for userCommand, DbLog_ExecSQL1 (forum:#83973) -# 3.8.3 03.02.2018 call execmemcache only syncInterval/2 if cacheLimit reached and DB is not reachable, fix handling of -# "$@" in DbLog_PushAsync -# 3.8.2 31.01.2018 RaiseError => 1 in DbLog_ConnectPush, DbLog_ConnectNewDBH, configCheck improved -# 3.8.1 29.01.2018 Use of uninitialized value $txt if addlog has no value -# 3.8.0 26.01.2018 escape "|" in events to log events containing it -# 3.7.1 25.01.2018 fix typo in commandref -# 3.7.0 21.01.2018 parsed event with Log 5 added, configCheck enhanced by configuration read check -# 3.6.5 19.01.2018 fix lot of logentries if disabled and db not available -# 3.6.4 17.01.2018 improve DbLog_Shutdown, extend configCheck by shutdown preparation check -# 3.6.3 14.01.2018 change verbose level of addlog "no Reading of device ..." message from 2 to 4 -# 3.6.2 07.01.2018 new attribute "exportCacheAppend", change function exportCache to respect attr exportCacheAppend, -# fix DbLog_execmemcache verbose 5 message -# 3.6.1 04.01.2018 change SQLite PRAGMA from NORMAL to FULL (Default Value of SQLite) -# 3.6.0 20.12.2017 check global blockingCallMax in configCheck, configCheck now available for SQLITE -# 3.5.0 18.12.2017 importCacheFile, addCacheLine uses useCharfilter option, filter only $event by charfilter -# 3.4.0 10.12.2017 avoid print out {RUNNING_PID} by "list device" -# 3.3.0 07.12.2017 avoid print out the content of cache by "list device" -# 3.2.0 06.12.2017 change attribute "autocommit" to "commitMode", activate choice of autocommit/transaction in logging -# Addlog/addCacheLine change $TIMESTAMP check, -# rebuild DbLog_Push/DbLog_PushAsync due to bugfix in update current (Forum:#80519), -# new attribute "useCharfilter" for Characterfilter usage -# 3.1.1 05.12.2017 Characterfilter added to avoid unwanted characters what may destroy transaction -# 3.1.0 05.12.2017 new set command addCacheLine -# 3.0.0 03.12.2017 set begin_work depending of AutoCommit value, new attribute "autocommit", some minor corrections, -# report working progress of reduceLog,reduceLogNbl in logfile (verbose 3), enhanced log output -# (e.g. of execute_array) -# 2.22.15 28.11.2017 some Log3 verbose level adapted -# 2.22.14 18.11.2017 create state-events if state has been changed (Forum:#78867) -# 2.22.13 20.10.2017 output of reopen command improved -# 2.22.12 19.10.2017 avoid illegible messages in "state" -# 2.22.11 13.10.2017 DbLogType expanded by SampleFill, DbLog_sampleDataFn adapted to sort case insensitive, commandref revised -# 2.22.10 04.10.2017 Encode::encode_utf8 of $error, DbLog_PushAsyncAborted adapted to use abortArg (Forum:77472) -# 2.22.9 04.10.2017 added hint to SVG/DbRep in commandref -# 2.22.8 29.09.2017 avoid multiple entries in Dopdown-list when creating SVG by group Device:Reading in DbLog_sampleDataFn -# 2.22.7 24.09.2017 minor fixes in configcheck -# 2.22.6 22.09.2017 commandref revised -# 2.22.5 05.09.2017 fix Internal MODE isn't set correctly after DEF is edited, nextsynch is not renewed if reopen is -# set manually after reopen was set with a delay Forum:#76213, Link to 98_FileLogConvert.pm added -# 2.22.4 27.08.2017 fhem chrashes if database DBD driver is not installed (Forum:#75894) -# 2.22.3 11.08.2017 Forum:#74690, bug unitialized in row 4322 -> $ret .= SVG_txt("par_${r}_0", "", "$f0:$f1:$f2:$f3", 20); -# 2.22.2 08.08.2017 Forum:#74690, bug unitialized in row 737 -> $ret .= ($fld[0]?$fld[0]:" ").'.'.($fld[1]?$fld[1]:" "); -# 2.22.1 07.08.2017 attribute "suppressAddLogV3" to suppress verbose3-logentries created by DbLog_AddLog -# 2.22.0 25.07.2017 attribute "addStateEvent" added -# 2.21.3 24.07.2017 commandref revised -# 2.21.2 19.07.2017 changed readCfg to report more error-messages -# 2.21.1 18.07.2017 change configCheck for DbRep Report_Idx -# 2.21.0 17.07.2017 standard timeout increased to 86400, enhanced explaination in configCheck -# 2.20.0 15.07.2017 state-Events complemented with state by using $events = deviceEvents($dev_hash,1) -# 2.19.0 11.07.2017 replace {DBMODEL} by {MODEL} completely -# 2.18.3 04.07.2017 bugfix (links with $FW_ME deleted), MODEL as Internal (for statistic) -# 2.18.2 29.06.2017 check of index for DbRep added -# 2.18.1 25.06.2017 DbLog_configCheck/ DbLog_sqlget some changes, commandref revised -# 2.18.0 24.06.2017 configCheck added (MySQL, PostgreSQL) -# 2.17.1 17.06.2017 fix log-entries "utf8 enabled" if SVG's called, commandref revised, enable UTF8 for DbLog_get -# 2.17.0 15.06.2017 enable UTF8 for MySQL (entry in configuration file necessary) -# 2.16.11 03.06.2017 execmemcache changed for SQLite avoid logging if deleteOldDaysNbl or reduceLogNbL is running -# 2.16.10 15.05.2017 commandref revised -# 2.16.9.1 11.05.2017 set userCommand changed - -# Forum: https://forum.fhem.de/index.php/topic,71808.msg633607.html#msg633607 -# 2.16.9 07.05.2017 addlog syntax changed to "addLog devspec:Reading [Value]" -# 2.16.8 06.05.2017 in valueFN $VALUE and $UNIT can now be set to '' or 0 -# 2.16.7 20.04.2017 fix $now at addLog -# 2.16.6 18.04.2017 AddLog set lasttime, lastvalue of dev_name, dev_reading -# 2.16.5 16.04.2017 DbLog_checkUsePK changed again, new attribute noSupportPK -# 2.16.4 15.04.2017 commandref completed, DbLog_checkUsePK changed (@usepkh = "", @usepkc = "") -# 2.16.3 07.04.2017 evaluate reading in DbLog_AddLog as regular expression -# 2.16.2 06.04.2017 sub DbLog_cutCol for cutting fields to maximum length, return to "$lv = "" if(!$lv);" because -# of problems with MinIntervall, DbLogType-Logging in database cycle verbose 5, make $TIMESTAMP -# changable by valueFn -# 2.16.1 04.04.2017 changed regexp $exc =~ s/(\s|\s*\n)/,/g; , DbLog_AddLog changed, enhanced sort of listCache -# 2.16.0 03.04.2017 new set-command addLog -# 2.15.0 03.04.2017 new attr valueFn using for perl expression which may change variables and skip logging -# unwanted datasets, change DbLog_ParseEvent for ZWAVE, -# change DbLogExclude / DbLogInclude in DbLog_Log to "$lv = "" if(!defined($lv));" -# 2.14.4 28.03.2017 pre-connection check in DbLog_execmemcache deleted (avoid possible blocking), attr excludeDevs -# can be specified as devspec -# 2.14.3 24.03.2017 DbLog_Get, DbLog_Push changed for better plotfork-support -# 2.14.2 23.03.2017 new reading "lastCachefile" -# 2.14.1 22.03.2017 cacheFile will be renamed after successful import by set importCachefile -# 2.14.0 19.03.2017 new set-commands exportCache, importCachefile, new attr expimpdir, all cache relevant set-commands -# only in drop-down list when asynch mode is used, minor fixes -# 2.13.6 13.03.2017 plausibility check in set reduceLog(Nbl) enhanced, minor fixes -# 2.13.5 20.02.2017 check presence of table current in DbLog_sampleDataFn -# 2.13.4 18.02.2017 DbLog_Push & DbLog_PushAsync: separate eval-routines for history & current table execution -# to decouple commit or rollback transactions, DbLog_sampleDataFn changed to avoid fhem from crash if table -# current is not present and DbLogType isn't set -# 2.13.3 18.02.2017 default timeout of DbLog_PushAsync increased to 1800, -# delete {HELPER}{xx_PID} in reopen function -# 2.13.2 16.02.2017 deleteOldDaysNbl added (non-blocking implementation of deleteOldDays) -# 2.13.1 15.02.2017 clearReadings limited to readings which won't be recreated periodicly in asynch mode and set readings only blank, -# eraseReadings added to delete readings except reading "state", -# countNbl non-blocking by DeeSPe, -# rename reduceLog non-blocking to reduceLogNbl and implement the old reduceLog too -# 2.13.0 13.02.2017 made reduceLog non-blocking by DeeSPe -# 2.12.5 11.02.2017 add support for primary key of PostgreSQL DB (Rel. 9.5) in both modes for current table -# 2.12.4 09.02.2017 support for primary key of PostgreSQL DB (Rel. 9.5) in both modes only history table -# 2.12.3 07.02.2017 set command clearReadings added -# 2.12.2 07.02.2017 support for primary key of SQLITE DB in both modes -# 2.12.1 05.02.2017 support for primary key of MySQL DB in synch mode -# 2.12 04.02.2017 support for primary key of MySQL DB in asynch mode -# 2.11.4 03.02.2017 check of missing modules added -# 2.11.3 01.02.2017 make errorlogging of DbLog_PushAsync more identical to DbLog_Push -# 2.11.2 31.01.2017 if attr colEvent, colReading, colValue is set, the limitation of fieldlength is also valid -# for SQLite databases -# 2.11.1 30.01.2017 output to central logfile enhanced for DbLog_Push -# 2.11 28.01.2017 DbLog_connect substituted by DbLog_connectPush completely -# 2.10.8 27.01.2017 DbLog_setinternalcols delayed at fhem start -# 2.10.7 25.01.2017 $hash->{HELPER}{COLSET} in DbLog_setinternalcols, DbLog_Push changed due to -# issue Turning on AutoCommit failed -# 2.10.6 24.01.2017 DbLog_connect changed "connect_cashed" to "connect", DbLog_Get, DbLog_chartQuery now uses -# DbLog_ConnectNewDBH, Attr asyncMode changed -> delete reading cacheusage reliable if mode was switched -# 2.10.5 23.01.2017 count, userCommand, deleteOldDays now uses DbLog_ConnectNewDBH -# DbLog_Push line 1107 changed -# 2.10.4 22.01.2017 new sub DbLog_setinternalcols, new attributes colEvent, colReading, colValue -# 2.10.3 21.01.2017 query of cacheEvents changed, attr timeout adjustable -# 2.10.2 19.01.2017 ReduceLog now uses DbLog_ConnectNewDBH -> makes start of ReduceLog stable -# 2.10.1 19.01.2017 commandref edited, cache events don't get lost even if other errors than "db not available" occure -# 2.10 18.10.2017 new attribute cacheLimit, showNotifyTime -# 2.9.3 17.01.2017 new sub DbLog_ConnectNewDBH (own new dbh for separate use in functions except logging functions), -# DbLog_sampleDataFn, DbLog_dbReadings now use DbLog_ConnectNewDBH -# 2.9.2 16.01.2017 new bugfix for SQLite issue SVGs, DbLog_Log changed to $dev_hash->{CHANGETIME}, DbLog_Push -# changed (db handle new separated) -# 2.9.1 14.01.2017 changed DbLog_ParseEvent to CallInstanceFn, renamed flushCache to purgeCache, -# renamed syncCache to commitCache, attr cacheEvents changed to 0,1,2 -# 2.9 11.01.2017 changed DbLog_ParseEvent to CallFn -# 2.8.9 11.01.2017 own $dbhp (new DbLog_ConnectPush) for synchronous logging, delete $hash->{HELPER}{RUNNING_PID} -# if DEAD, add func flushCache, syncCache -# 2.8.8 10.01.2017 connection check in Get added, avoid warning "commit/rollback ineffective with AutoCommit enabled" -# 2.8.7 10.01.2017 bugfix no dropdown list in SVG if asynchronous mode activated (func DbLog_sampleDataFn) -# 2.8.6 09.01.2017 Workaround for Warning begin_work failed: Turning off AutoCommit failed, start new timer of -# DbLog_execmemcache after reducelog -# 2.8.5 08.01.2017 attr syncEvents, cacheEvents added to minimize events -# 2.8.4 08.01.2017 $readingFnAttributes added -# 2.8.3 08.01.2017 set NOTIFYDEV changed to use notifyRegexpChanged (Forum msg555619), attr noNotifyDev added -# 2.8.2 06.01.2017 commandref maintained to cover new functions -# 2.8.1 05.01.2017 use Time::HiRes qw(gettimeofday tv_interval), bugfix $hash->{HELPER}{RUNNING_PID} -# 2.8 03.01.2017 attr asyncMode, you have a choice to use blocking (as V2.5) or non-blocking asynchronous -# with caching, attr showproctime -# 2.7 02.01.2017 initial release non-blocking using BlockingCall -# 2.6 02.01.2017 asynchron writing to DB using cache, attr syncInterval, set listCache -# 2.5 29.12.2016 commandref maintained to cover new attributes, attr "excludeDevs" and "verbose4Devs" now -# accepting Regex -# 2.4.4 28.12.2016 Attribut "excludeDevs" to exclude devices from db-logging (only if $hash->{NOTIFYDEV} eq ".*") -# 2.4.3 28.12.2016 function DbLog_Log: changed separators of @row_array -> better splitting -# 2.4.2 28.12.2016 Attribut "verbose4Devs" to restrict verbose4 loggings of specific devices -# 2.4.1 27.12.2016 DbLog_Push: improved update/insert into current, analyze execute_array -> ArrayTupleStatus -# 2.4 24.12.2016 some improvements of verbose 4 logging -# 2.3.1 23.12.2016 fix due to https://forum.fhem.de/index.php/topic,62998.msg545541.html#msg545541 -# 2.3 22.12.2016 fix eval{} in DbLog_Log -# 2.2 21.12.2016 set DbLogType only to "History" if attr DbLogType not set -# 2.1 21.12.2016 use execute_array in DbLog_Push -# 2.0 19.12.2016 some improvements DbLog_Log -# 1.9.3 17.12.2016 $hash->{NOTIFYDEV} added to process only events from devices are in Regex -# 1.9.2 17.12.2016 some improvemnts DbLog_Log, DbLog_Push -# 1.9.1 16.12.2016 DbLog_Log no using encode_base64 -# 1.9 16.12.2016 DbLog_Push changed to use deviceEvents -# 1.8.1 16.12.2016 DbLog_Push changed -# 1.8 15.12.2016 bugfix of don't logging all received events -# 1.7.1 15.12.2016 attr procedure of "disabled" changed package main; use strict; use warnings; eval "use DBI;1" or my $DbLogMMDBI = "DBI"; +eval "use FHEM::Meta;1" or my $modMetaAbsent = 1; use Data::Dumper; use Blocking; use Time::HiRes qw(gettimeofday tv_interval); @@ -219,7 +26,179 @@ use Time::Local; use Encode qw(encode_utf8); no if $] >= 5.017011, warnings => 'experimental::smartmatch'; -my $DbLogVersion = "3.13.1"; +# Version History intern by DS_Starter: +our %DbLog_vNotesIntern = ( + "3.14.0" => "05.04.2019 add support for Meta.pm and X_DelayedShutdownFn, attribute shutdownWait removed, ". + "direct attribute help in FHEMWEB ", + "3.13.3" => "04.03.2019 addLog better Log3 Outputs ", + "3.13.2" => "09.02.2019 Commandref revised ", + "3.13.1" => "27.11.2018 DbLog_ExecSQL log output changed ", + "3.13.0" => "12.11.2018 adding attributes traceFlag, traceLevel ", + "3.12.7" => "10.11.2018 addLog considers DbLogInclude (Forum:#92854) ", + "3.12.6" => "22.10.2018 fix timer not deleted if reopen after reopen xxx (Forum: https://forum.fhem.de/index.php/topic,91869.msg848433.html#msg848433) ", + "3.12.5" => "12.10.2018 charFilter: \"\\xB0C\" substitution by \"°C\" added and usage in DbLog_Log changed ", + "3.12.4" => "10.10.2018 return non-saved datasets back in asynch mode only if transaction is used ", + "3.12.3" => "08.10.2018 Log output of recuceLogNbl enhanced, some functions renamed ", + "3.12.2" => "07.10.2018 \$hash->{HELPER}{REOPEN_RUNS_UNTIL} contains the time the DB is closed ", + "3.12.1" => "19.09.2018 use Time::Local (forum:#91285) ", + "3.12.0" => "04.09.2018 corrected SVG-select (https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640) ", + "3.11.0" => "02.09.2018 reduceLog, reduceLogNbl - optional \"days newer than\" part added ", + "3.10.10" => "05.08.2018 commandref revised reducelogNbl ", + "3.10.9" => "23.06.2018 commandref added hint about special characters in passwords ", + "3.10.8" => "21.04.2018 addLog - not available reading can be added as new one (forum:#86966) ", + "3.10.7" => "16.04.2018 fix generate addLog-event if device or reading was not found by addLog ", + "3.10.6" => "13.04.2018 verbose level in addlog changed if reading not found ", + "3.10.5" => "12.04.2018 fix warnings ", + "3.10.4" => "11.04.2018 fix addLog if no valueFn is used ", + "3.10.3" => "10.04.2018 minor fixes in addLog ", + "3.10.2" => "09.04.2018 add qualifier CN= to addlog ", + "3.10.1" => "04.04.2018 changed event parsing of Weather ", + "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 ", + "3.8.7" => "28.02.2018 changed DbLog_sampleDataFn - no change limits got fron SVG, commandref revised ", + "3.8.6" => "25.02.2018 commandref revised (forum:#84953) ", + "3.8.5" => "16.02.2018 changed ParseEvent for Zwave ", + "3.8.4" => "07.02.2018 minor fixes of \"\$\@\", code review, eval for userCommand, DbLog_ExecSQL1 (forum:#83973) ", + "3.8.3" => "03.02.2018 call execmemcache only syncInterval/2 if cacheLimit reached and DB is not reachable, fix handling of ". + "\"\$\@\" in DbLog_PushAsync ", + "3.8.2" => "31.01.2018 RaiseError => 1 in DbLog_ConnectPush, DbLog_ConnectNewDBH, configCheck improved ", + "3.8.1" => "29.01.2018 Use of uninitialized value \$txt if addlog has no value ", + "3.8.0" => "26.01.2018 escape \"\|\" in events to log events containing it ", + "3.7.1" => "25.01.2018 fix typo in commandref ", + "3.7.0" => "21.01.2018 parsed event with Log 5 added, configCheck enhanced by configuration read check ", + "3.6.5" => "19.01.2018 fix lot of logentries if disabled and db not available ", + "3.6.4" => "17.01.2018 improve DbLog_Shutdown, extend configCheck by shutdown preparation check ", + "3.6.3" => "14.01.2018 change verbose level of addlog \"no Reading of device ...\" message from 2 to 4 ", + "3.6.2" => "07.01.2018 new attribute \"exportCacheAppend\", change function exportCache to respect attr exportCacheAppend, ". + "fix DbLog_execmemcache verbose 5 message ", + "3.6.1" => "04.01.2018 change SQLite PRAGMA from NORMAL to FULL (Default Value of SQLite) ", + "3.6.0" => "20.12.2017 check global blockingCallMax in configCheck, configCheck now available for SQLITE ", + "3.5.0" => "18.12.2017 importCacheFile, addCacheLine uses useCharfilter option, filter only \$event by charfilter ", + "3.4.0" => "10.12.2017 avoid print out {RUNNING_PID} by \"list device\" ", + "3.3.0" => "07.12.2017 avoid print out the content of cache by \"list device\" ", + "3.2.0" => "06.12.2017 change attribute \"autocommit\" to \"commitMode\", activate choice of autocommit/transaction in logging ". + "Addlog/addCacheLine change \$TIMESTAMP check ". + "rebuild DbLog_Push/DbLog_PushAsync due to bugfix in update current (Forum:#80519) ". + "new attribute \"useCharfilter\" for Characterfilter usage ", + "3.1.1" => "05.12.2017 Characterfilter added to avoid unwanted characters what may destroy transaction ", + "3.1.0" => "05.12.2017 new set command addCacheLine ", + "3.0.0" => "03.12.2017 set begin_work depending of AutoCommit value, new attribute \"autocommit\", some minor corrections, ". + "report working progress of reduceLog,reduceLogNbl in logfile (verbose 3), enhanced log output ". + "(e.g. of execute_array) ", + "2.22.15" => "28.11.2017 some Log3 verbose level adapted ", + "2.22.14" => "18.11.2017 create state-events if state has been changed (Forum:#78867) ", + "2.22.13" => "20.10.2017 output of reopen command improved ", + "2.22.12" => "19.10.2017 avoid illegible messages in \"state\" ", + "2.22.11" => "13.10.2017 DbLogType expanded by SampleFill, DbLog_sampleDataFn adapted to sort case insensitive, commandref revised ", + "2.22.10" => "04.10.2017 Encode::encode_utf8 of \$error, DbLog_PushAsyncAborted adapted to use abortArg (Forum:77472) ", + "2.22.9" => "04.10.2017 added hint to SVG/DbRep in commandref ", + "2.22.8" => "29.09.2017 avoid multiple entries in Dopdown-list when creating SVG by group Device:Reading in DbLog_sampleDataFn ", + "2.22.7" => "24.09.2017 minor fixes in configcheck ", + "2.22.6" => "22.09.2017 commandref revised ", + "2.22.5" => "05.09.2017 fix Internal MODE isn't set correctly after DEF is edited, nextsynch is not renewed if reopen is ". + "set manually after reopen was set with a delay Forum:#76213, Link to 98_FileLogConvert.pm added ", + "2.22.4" => "27.08.2017 fhem chrashes if database DBD driver is not installed (Forum:#75894) ", + "2.22.1" => "07.08.2017 attribute \"suppressAddLogV3\" to suppress verbose3-logentries created by DbLog_AddLog ", + "2.22.0" => "25.07.2017 attribute \"addStateEvent\" added ", + "2.21.3" => "24.07.2017 commandref revised ", + "2.21.2" => "19.07.2017 changed readCfg to report more error-messages ", + "2.21.1" => "18.07.2017 change configCheck for DbRep Report_Idx ", + "2.21.0" => "17.07.2017 standard timeout increased to 86400, enhanced explaination in configCheck ", + "2.20.0" => "15.07.2017 state-Events complemented with state by using \$events = deviceEvents(\$dev_hash,1) ", + "2.19.0" => "11.07.2017 replace {DBMODEL} by {MODEL} completely ", + "2.18.3" => "04.07.2017 bugfix (links with \$FW_ME deleted), MODEL as Internal (for statistic) ", + "2.18.2" => "29.06.2017 check of index for DbRep added ", + "2.18.1" => "25.06.2017 DbLog_configCheck/ DbLog_sqlget some changes, commandref revised ", + "2.18.0" => "24.06.2017 configCheck added (MySQL, PostgreSQL) ", + "2.17.1" => "17.06.2017 fix log-entries \"utf8 enabled\" if SVG's called, commandref revised, enable UTF8 for DbLog_get ", + "2.17.0" => "15.06.2017 enable UTF8 for MySQL (entry in configuration file necessary) ", + "2.16.11" => "03.06.2017 execmemcache changed for SQLite avoid logging if deleteOldDaysNbl or reduceLogNbL is running ", + "2.16.10" => "15.05.2017 commandref revised ", + "2.16.9.1"=> "11.05.2017 set userCommand changed - Forum: https://forum.fhem.de/index.php/topic,71808.msg633607.html#msg633607 ", + "2.16.9" => "07.05.2017 addlog syntax changed to \"addLog devspec:Reading [Value]\" ", + "2.16.8" => "06.05.2017 in valueFN \$VALUE and \$UNIT can now be set to '' or 0 ", + "2.16.7" => "20.04.2017 fix \$now at addLog ", + "2.16.6" => "18.04.2017 AddLog set lasttime, lastvalue of dev_name, dev_reading ", + "2.16.5" => "16.04.2017 DbLog_checkUsePK changed again, new attribute noSupportPK ", + "2.16.4" => "15.04.2017 commandref completed, DbLog_checkUsePK changed (\@usepkh = \"\", \@usepkc = \"\") ", + "2.16.3" => "07.04.2017 evaluate reading in DbLog_AddLog as regular expression ", + "2.16.0" => "03.04.2017 new set-command addLog ", + "2.15.0" => "03.04.2017 new attr valueFn using for perl expression which may change variables and skip logging ". + "unwanted datasets, change DbLog_ParseEvent for ZWAVE, ". + "change DbLogExclude / DbLogInclude in DbLog_Log to \"\$lv = \"\" if(!defined(\$lv));\" ", + "2.14.4" => "28.03.2017 pre-connection check in DbLog_execmemcache deleted (avoid possible blocking), attr excludeDevs ". + "can be specified as devspec ", + "2.14.3" => "24.03.2017 DbLog_Get, DbLog_Push changed for better plotfork-support ", + "2.14.2" => "23.03.2017 new reading \"lastCachefile\" ", + "2.14.1" => "22.03.2017 cacheFile will be renamed after successful import by set importCachefile ", + "2.14.0" => "19.03.2017 new set-commands exportCache, importCachefile, new attr expimpdir, all cache relevant set-commands ". + "only in drop-down list when asynch mode is used, minor fixes ", + "2.13.6" => "13.03.2017 plausibility check in set reduceLog(Nbl) enhanced, minor fixes ", + "2.13.5" => "20.02.2017 check presence of table current in DbLog_sampleDataFn ", + "2.13.3" => "18.02.2017 default timeout of DbLog_PushAsync increased to 1800, ". + "delete {HELPER}{xx_PID} in reopen function ", + "2.13.2" => "16.02.2017 deleteOldDaysNbl added (non-blocking implementation of deleteOldDays) ", + "2.13.1" => "15.02.2017 clearReadings limited to readings which won't be recreated periodicly in asynch mode and set readings only blank, ". + "eraseReadings added to delete readings except reading \"state\", ". + "countNbl non-blocking by DeeSPe, ". + "rename reduceLog non-blocking to reduceLogNbl and implement the old reduceLog too ", + "2.13.0" => "13.02.2017 made reduceLog non-blocking by DeeSPe ", + "2.12.5" => "11.02.2017 add support for primary key of PostgreSQL DB (Rel. 9.5) in both modes for current table ", + "2.12.4" => "09.02.2017 support for primary key of PostgreSQL DB (Rel. 9.5) in both modes only history table ", + "2.12.3" => "07.02.2017 set command clearReadings added ", + "2.12.2" => "07.02.2017 support for primary key of SQLITE DB in both modes ", + "2.12.1" => "05.02.2017 support for primary key of MySQL DB in synch mode ", + "2.12" => "04.02.2017 support for primary key of MySQL DB in asynch mode ", + "2.11.4" => "03.02.2017 check of missing modules added ", + "2.11.3" => "01.02.2017 make errorlogging of DbLog_PushAsync more identical to DbLog_Push ", + "2.11.2" => "31.01.2017 if attr colEvent, colReading, colValue is set, the limitation of fieldlength is also valid ". + "for SQLite databases ", + "2.11.1" => "30.01.2017 output to central logfile enhanced for DbLog_Push ", + "2.11" => "28.01.2017 DbLog_connect substituted by DbLog_connectPush completely ", + "2.10.8" => "27.01.2017 DbLog_setinternalcols delayed at fhem start ", + "2.10.7" => "25.01.2017 \$hash->{HELPER}{COLSET} in DbLog_setinternalcols, DbLog_Push changed due to ". + "issue Turning on AutoCommit failed ", + "2.10.6" => "24.01.2017 DbLog_connect changed \"connect_cashed\" to \"connect\", DbLog_Get, DbLog_chartQuery now uses ". + "DbLog_ConnectNewDBH, Attr asyncMode changed -> delete reading cacheusage reliable if mode was switched ", + "2.10.5" => "23.01.2017 count, userCommand, deleteOldDays now uses DbLog_ConnectNewDBH ". + "DbLog_Push line 1107 changed ", + "2.10.4" => "22.01.2017 new sub DbLog_setinternalcols, new attributes colEvent, colReading, colValue ", + "2.10.3" => "21.01.2017 query of cacheEvents changed, attr timeout adjustable ", + "2.10.2" => "19.01.2017 ReduceLog now uses DbLog_ConnectNewDBH -> makes start of ReduceLog stable ", + "2.10.1" => "19.01.2017 commandref edited, cache events don't get lost even if other errors than \"db not available\" occure ", + "2.10" => "18.10.2017 new attribute cacheLimit, showNotifyTime ", + "2.9.3" => "17.01.2017 new sub DbLog_ConnectNewDBH (own new dbh for separate use in functions except logging functions), ". + "DbLog_sampleDataFn, DbLog_dbReadings now use DbLog_ConnectNewDBH ", + "2.9.2" => "16.01.2017 new bugfix for SQLite issue SVGs, DbLog_Log changed to \$dev_hash->{CHANGETIME}, DbLog_Push ". + "changed (db handle new separated) ", + "2.9.1" => "14.01.2017 changed DbLog_ParseEvent to CallInstanceFn, renamed flushCache to purgeCache, ". + "renamed syncCache to commitCache, attr cacheEvents changed to 0,1,2 ", + "2.8.9" => "11.01.2017 own \$dbhp (new DbLog_ConnectPush) for synchronous logging, delete \$hash->{HELPER}{RUNNING_PID} ". + "if DEAD, add func flushCache, syncCache ", + "2.8.8" => "10.01.2017 connection check in Get added, avoid warning \"commit/rollback ineffective with AutoCommit enabled\" ", + "2.8.7" => "10.01.2017 bugfix no dropdown list in SVG if asynchronous mode activated (func DbLog_sampleDataFn) ", + "2.8.6" => "09.01.2017 Workaround for Warning begin_work failed: Turning off AutoCommit failed, start new timer of ". + "DbLog_execmemcache after reducelog ", + "2.8.5" => "08.01.2017 attr syncEvents, cacheEvents added to minimize events ", + "2.8.4" => "08.01.2017 \$readingFnAttributes added ", + "2.8.3" => "08.01.2017 set NOTIFYDEV changed to use notifyRegexpChanged (Forum msg555619), attr noNotifyDev added ", + "2.8.2" => "06.01.2017 commandref maintained to cover new functions ", + "2.8.1" => "05.01.2017 use Time::HiRes qw(gettimeofday tv_interval), bugfix \$hash->{HELPER}{RUNNING_PID} ", + "2.4.4" => "28.12.2016 Attribut \"excludeDevs\" to exclude devices from db-logging (only if \$hash->{NOTIFYDEV} eq \"\.\*\") ", + "2.4.3" => "28.12.2016 function DbLog_Log: changed separators of \@row_array -> better splitting ", + "2.4.2" => "28.12.2016 Attribut \"verbose4Devs\" to restrict verbose4 loggings of specific devices ", + "2.4.1" => "27.12.2016 DbLog_Push: improved update/insert into current, analyze execute_array -> ArrayTupleStatus ", + "2.3.1" => "23.12.2016 fix due to https://forum.fhem.de/index.php/topic,62998.msg545541.html#msg545541 ", + "1.9.3" => "17.12.2016 \$hash->{NOTIFYDEV} added to process only events from devices are in Regex ", + "1.9.2" => "17.12.2016 some improvemnts DbLog_Log, DbLog_Push ", + "1.9.1" => "16.12.2016 DbLog_Log no using encode_base64 ", + "1.8.1" => "16.12.2016 DbLog_Push changed ", + "1.7.1" => "15.12.2016 attr procedure of \"disabled\" changed" +); my %columns = ("DEVICE" => 64, "TYPE" => 64, @@ -236,63 +215,53 @@ sub DbLog_Initialize($) { my ($hash) = @_; - $hash->{DefFn} = "DbLog_Define"; - $hash->{UndefFn} = "DbLog_Undef"; - $hash->{NotifyFn} = "DbLog_Log"; - $hash->{SetFn} = "DbLog_Set"; - $hash->{GetFn} = "DbLog_Get"; - $hash->{AttrFn} = "DbLog_Attr"; - $hash->{SVG_regexpFn} = "DbLog_regexpFn"; - $hash->{ShutdownFn} = "DbLog_Shutdown"; - $hash->{AttrList} = "addStateEvent:0,1 ". - "commitMode:basic_ta:on,basic_ta:off,ac:on_ta:on,ac:on_ta:off,ac:off_ta:on ". - "colEvent ". - "colReading ". - "colValue ". - "disable:1,0 ". - "DbLogType:Current,History,Current/History,SampleFill/History ". - "shutdownWait ". - "suppressUndef:0,1 ". - "verbose4Devs ". - "excludeDevs ". - "expimpdir ". - "exportCacheAppend:1,0 ". - "syncInterval ". - "noNotifyDev:1,0 ". - "showproctime:1,0 ". - "suppressAddLogV3:1,0 ". - "traceFlag:SQL,CON,ENC,DBD,TXN,ALL ". - "traceLevel:0,1,2,3,4,5,6,7 ". - "asyncMode:1,0 ". - "cacheEvents:2,1,0 ". - "cacheLimit ". - "noSupportPK:1,0 ". - "syncEvents:1,0 ". - "showNotifyTime:1,0 ". - "timeout ". - "useCharfilter:0,1 ". - "valueFn:textField-long ". - "DbLogSelectionMode:Exclude,Include,Exclude/Include ". - $readingFnAttributes; - - # Das Attribut DbLogSelectionMode legt fest, wie die Device-Spezifischen Atrribute - # DbLogExclude und DbLogInclude behandelt werden sollen. - # - Exclude: Es wird nur das Device-spezifische Attribut Exclude beruecksichtigt, - # d.h. generell wird alles geloggt, was nicht per DBLogExclude ausgeschlossen wird - # - Include: Es wird nur das Device-spezifische Attribut Include beruecksichtigt, - # d.h. generell wird nichts geloggt, ausßer dem was per DBLogInclude eingeschlossen wird - # - Exclude/Include: Es wird zunaechst Exclude geprueft und bei Ausschluß wird ggf. noch zusaetzlich Include geprueft, - # d.h. generell wird alles geloggt, es sei denn es wird per DBLogExclude ausgeschlossen. - # Wird es von DBLogExclude ausgeschlossen, kann es trotzdem wieder per DBLogInclude - # eingeschlossen werden. - + $hash->{DefFn} = "DbLog_Define"; + $hash->{UndefFn} = "DbLog_Undef"; + $hash->{NotifyFn} = "DbLog_Log"; + $hash->{SetFn} = "DbLog_Set"; + $hash->{GetFn} = "DbLog_Get"; + $hash->{AttrFn} = "DbLog_Attr"; + $hash->{SVG_regexpFn} = "DbLog_regexpFn"; + $hash->{DelayedShutdownFn} = "DbLog_DelayedShutdown"; + $hash->{AttrList} = "addStateEvent:0,1 ". + "commitMode:basic_ta:on,basic_ta:off,ac:on_ta:on,ac:on_ta:off,ac:off_ta:on ". + "colEvent ". + "colReading ". + "colValue ". + "disable:1,0 ". + "DbLogType:Current,History,Current/History,SampleFill/History ". + "suppressUndef:0,1 ". + "verbose4Devs ". + "excludeDevs ". + "expimpdir ". + "exportCacheAppend:1,0 ". + "syncInterval ". + "noNotifyDev:1,0 ". + "showproctime:1,0 ". + "suppressAddLogV3:1,0 ". + "traceFlag:SQL,CON,ENC,DBD,TXN,ALL ". + "traceLevel:0,1,2,3,4,5,6,7 ". + "asyncMode:1,0 ". + "cacheEvents:2,1,0 ". + "cacheLimit ". + "noSupportPK:1,0 ". + "syncEvents:1,0 ". + "showNotifyTime:1,0 ". + "timeout ". + "useCharfilter:0,1 ". + "valueFn:textField-long ". + "DbLogSelectionMode:Exclude,Include,Exclude/Include ". + $readingFnAttributes; addToAttrList("DbLogInclude"); addToAttrList("DbLogExclude"); $hash->{FW_detailFn} = "DbLog_fhemwebFn"; $hash->{SVG_sampleDataFn} = "DbLog_sampleDataFn"; - + + eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html) + +return; } ############################################################### @@ -313,10 +282,13 @@ sub DbLog_Define($@) eval { "Hallo" =~ m/^$regexp$/ }; return "Bad regexp: $@" if($@); - $hash->{REGEXP} = $regexp; - $hash->{VERSION} = $DbLogVersion; - $hash->{MODE} = AttrVal($hash->{NAME}, "asyncMode", undef)?"asynchronous":"synchronous"; # Mode setzen Forum:#76213 - $hash->{HELPER}{OLDSTATE} = "initialized"; + $hash->{REGEXP} = $regexp; + $hash->{MODE} = AttrVal($hash->{NAME}, "asyncMode", undef)?"asynchronous":"synchronous"; # Mode setzen Forum:#76213 + $hash->{HELPER}{OLDSTATE} = "initialized"; + $hash->{HELPER}{MODMETAABSENT} = 1 if($modMetaAbsent); # Modul Meta.pm nicht vorhanden + + # Versionsinformationen setzen + DbLog_setVersionInfo($hash); # nur Events dieser Devices an NotifyFn weiterleiten, NOTIFYDEV wird gesetzt wenn möglich notifyRegexpChanged($hash, $regexp); @@ -361,24 +333,25 @@ sub DbLog_Undef($$) { return undef; } -################################################################ -sub DbLog_Shutdown($) { +####################################################################################################### +# Mit der X_DelayedShutdown Funktion kann eine Definition das Stoppen von FHEM verzögern um asynchron +# hinter sich aufzuräumen. +# Je nach Rückgabewert $delay_needed wird der Stopp von FHEM verzögert (0 | 1). +# Sobald alle nötigen Maßnahmen erledigt sind, muss der Abschluss mit CancelDelayedShutdown($name) an +# FHEM zurückgemeldet werden. +####################################################################################################### +sub DbLog_DelayedShutdown($) { my ($hash) = @_; - my $name = $hash->{NAME}; + my $name = $hash->{NAME}; + my $async = AttrVal($name, "asyncMode", ""); + + return 0 if(IsDisabled($name)); $hash->{HELPER}{SHUTDOWNSEQ} = 1; + Log3($name, 2, "DbLog $name - Last database write cycle due to shutdown ..."); DbLog_execmemcache($hash); - my $shutdownWait = AttrVal($name,"shutdownWait",undef); - if(defined($shutdownWait)) { - Log3($name, 2, "DbLog $name - waiting for shutdown $shutdownWait seconds ..."); - sleep($shutdownWait); - Log3($name, 2, "DbLog $name - continuing shutdown sequence"); - } - if($hash->{HELPER}{".RUNNING_PID"}) { - BlockingKill($hash->{HELPER}{".RUNNING_PID"}); - } - -return undef; + +return 1; } ################################################################ @@ -398,7 +371,8 @@ sub DbLog_Attr(@) { if ($aName eq "syncInterval" || $aName eq "cacheLimit" || $aName eq "timeout") { unless ($aVal =~ /^[0-9]+$/) { return " The Value of $aName is not valid. Use only figures 0-9 !";} } - if( $aName eq 'valueFn' ) { + + if( $aName eq 'valueFn' ) { my %specials= ( "%TIMESTAMP" => $name, "%DEVICE" => $name, @@ -413,6 +387,10 @@ sub DbLog_Attr(@) { my $err = perlSyntaxCheck($aVal, %specials); return $err if($err); } + + if ($aName eq "shutdownWait") { + return "DbLog $name - The attribute $aName is deprecated and has been removed !"; + } } if($aName eq "colEvent" || $aName eq "colReading" || $aName eq "colValue") { @@ -1459,18 +1437,21 @@ sub DbLog_Log($$) { if(!$async) { if(@row_array) { # synchoner Mode - # return wenn "reopen" mit Ablaufzeit gestartet ist - return if($hash->{HELPER}{REOPEN_RUNS}); + return if($hash->{HELPER}{REOPEN_RUNS}); # return wenn "reopen" mit Ablaufzeit gestartet ist my $error = DbLog_Push($hash, $vb4show, @row_array); - Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error" if($vb4show); - - my $state = $error?$error:(IsDisabled($name))?"disabled":"connected"; - my $evt = ($state eq $hash->{HELPER}{OLDSTATE})?0:1; + Log3 ($name, 5, "DbLog $name -> DbLog_Push Returncode: $error") if($vb4show); + CancelDelayedShutdown($name) if($hash->{HELPER}{SHUTDOWNSEQ}); + Log3 ($name, 2, "DbLog $name - Last database write cycle done") if(delete $hash->{HELPER}{SHUTDOWNSEQ}); + my $state = $error?$error:(IsDisabled($name))?"disabled":"connected"; + my $evt = ($state eq $hash->{HELPER}{OLDSTATE})?0:1; readingsSingleUpdate($hash, "state", $state, $evt); $hash->{HELPER}{OLDSTATE} = $state; # Notify-Routine Laufzeit ermitteln $net = tv_interval($nst); + } else { + CancelDelayedShutdown($name) if($hash->{HELPER}{SHUTDOWNSEQ}); + Log3 ($name, 2, "DbLog $name - no data for Last database write cycle") if(delete $hash->{HELPER}{SHUTDOWNSEQ}); } } if($net && AttrVal($name, "showNotifyTime", undef)) { @@ -1480,20 +1461,18 @@ return; } ################################################################################################# -# # Schreibroutine Einfügen Werte in DB im Synchronmode -# ################################################################################################# sub DbLog_Push(@) { my ($hash, $vb4show, @row_array) = @_; - my $name = $hash->{NAME}; - my $DbLogType = AttrVal($name, "DbLogType", "History"); - my $supk = AttrVal($name, "noSupportPK", 0); - my $tl = AttrVal($name, "traceLevel", 0); - my $tf = AttrVal($name, "traceFlag", "SQL"); - my $errorh = 0; - my $error = 0; - my $doins = 0; # Hilfsvariable, wenn "1" sollen inserts in Tabele current erfolgen (updates schlugen fehl) + my $name = $hash->{NAME}; + my $DbLogType = AttrVal($name, "DbLogType", "History"); + my $supk = AttrVal($name, "noSupportPK", 0); + my $tl = AttrVal($name, "traceLevel", 0); + my $tf = AttrVal($name, "traceFlag", "SQL"); + my $errorh = 0; + my $error = 0; + my $doins = 0; # Hilfsvariable, wenn "1" sollen inserts in Tabelle current erfolgen (updates schlugen fehl) my $dbh; my $nh = ($hash->{MODEL} ne 'SQLITE')?1:0; @@ -1876,7 +1855,10 @@ sub DbLog_execmemcache ($) { } else { if($dolog && $hash->{HELPER}{".RUNNING_PID"}) { $error = "Commit already running - resync at NextSync"; - } + } else { + CancelDelayedShutdown($name) if($hash->{HELPER}{SHUTDOWNSEQ}); + Log3 ($name, 2, "DbLog $name - no data for Last database write cycle") if(delete $hash->{HELPER}{SHUTDOWNSEQ}); + } } # $memcount = scalar(keys%{$hash->{cache}{".memcache"}}); @@ -2273,6 +2255,10 @@ sub DbLog_PushAsyncDone ($) { delete $hash->{HELPER}{".RUNNING_PID"}; delete $hash->{HELPER}{LASTLIMITRUNTIME} if(!$error); Log3 ($name, 5, "DbLog $name -> DbLog_PushAsyncDone finished"); + + Log3 ($name, 2, "DbLog $name - Last database write cycle done") if(delete $hash->{HELPER}{SHUTDOWNSEQ}); + CancelDelayedShutdown($name); + return; } @@ -2288,9 +2274,13 @@ sub DbLog_PushAsyncAborted(@) { readingsSingleUpdate($hash,"state",$cause, 1); delete $hash->{HELPER}{".RUNNING_PID"}; delete $hash->{HELPER}{LASTLIMITRUNTIME}; + + Log3 ($name, 2, "DbLog $name - Last database write cycle done") if(delete $hash->{HELPER}{SHUTDOWNSEQ}); + CancelDelayedShutdown($name); + +return; } - ################################################################ # # zerlegt uebergebenes FHEM-Datum in die einzelnen Bestandteile @@ -3085,8 +3075,8 @@ sub DbLog_configcheck($) { ####################################################################### $check = ""; $check .= "Result of DbLog version check

"; - $check .= "Used DbLog version: $hash->{VERSION}
"; - $check .= "Recommendation: Your running version may be the current one. Please check for updates of DbLog periodically.

"; + $check .= "Used DbLog version: $hash->{HELPER}{VERSION}
"; + $check .= "Recommendation: Please check for updates of DbLog periodically.

"; ### Configuration read check ####################################################################### @@ -3182,31 +3172,31 @@ sub DbLog_configcheck($) { } $check .= "Recommendation: $rec

"; - if($mode =~ /asynchronous/) { - my $shutdownWait = AttrVal($name,"shutdownWait",undef); - my $bpt = ReadingsVal($name,"background_processing_time",undef); - my $bptv = defined($bpt)?int($bpt)+2:2; - # $shutdownWait = defined($shutdownWait)?$shutdownWait:undef; - my $sdw = defined($shutdownWait)?$shutdownWait:" "; - $check .= "Result of shutdown sequence preparation check

"; - $check .= "Attribute \"shutdownWait\" is set to: $sdw
"; - if(!defined($shutdownWait) || $shutdownWait < $bptv) { - if(!$bpt) { - $rec = "Due to Reading \"background_processing_time\" is not available (you may set attribute \"showproctime\"), there is only a rough estimate to
"; - $rec .= "set attribute \"shutdownWait\" to $bptv seconds.
"; - } else { - $rec = "Please set this attribute at least to $bptv seconds to avoid data loss when system shutdown is initiated."; - } - } else { - if(!$bpt) { - $rec = "The setting may be ok. But due to the Reading \"background_processing_time\" is not available (you may set attribute \"showproctime\"), the current
"; - $rec .= "setting is only a rough estimate.
"; - } else { - $rec = "settings o.k."; - } - } - $check .= "Recommendation: $rec

"; - } +# if($mode =~ /asynchronous/) { +# my $shutdownWait = AttrVal($name,"shutdownWait",undef); +# my $bpt = ReadingsVal($name,"background_processing_time",undef); +# my $bptv = defined($bpt)?int($bpt)+2:2; +# # $shutdownWait = defined($shutdownWait)?$shutdownWait:undef; +# my $sdw = defined($shutdownWait)?$shutdownWait:" "; +# $check .= "Result of shutdown sequence preparation check

"; +# $check .= "Attribute \"shutdownWait\" is set to: $sdw
"; +# if(!defined($shutdownWait) || $shutdownWait < $bptv) { +# if(!$bpt) { +# $rec = "Due to Reading \"background_processing_time\" is not available (you may set attribute \"showproctime\"), there is only a rough estimate to
"; +# $rec .= "set attribute \"shutdownWait\" to $bptv seconds.
"; +# } else { +# $rec = "Please set this attribute at least to $bptv seconds to avoid data loss when system shutdown is initiated."; +# } +# } else { +# if(!$bpt) { +# $rec = "The setting may be ok. But due to the Reading \"background_processing_time\" is not available (you may set attribute \"showproctime\"), the current
"; +# $rec .= "setting is only a rough estimate.
"; +# } else { +# $rec = "settings o.k."; +# } +# } +# $check .= "Recommendation: $rec

"; +# } ### Check Plot Erstellungsmodus ####################################################################### @@ -3311,7 +3301,7 @@ sub DbLog_configcheck($) { $check .= "Column width used by $name: 'DEVICE' = $cmod_dev, 'TYPE' = $cmod_typ, 'EVENT' = $cmod_evt, 'READING' = $cmod_rdg, 'VALUE' = $cmod_val, 'UNIT' = $cmod_unt
"; $check .= "Recommendation: $rec

"; - ### Check Spaltenbreite current + ### Check Spaltenbreite current ####################################################################### if($dbmodel =~ /MYSQL/) { @sr_dev = DbLog_sqlget($hash,"SHOW FIELDS FROM current where FIELD='DEVICE'"); @@ -3505,7 +3495,7 @@ sub DbLog_configcheck($) { @dix = DbLog_sqlget($hash,"SHOW INDEX FROM history where Key_name='Report_Idx'"); if (!@dix) { $check .= "At least one DbRep-device assigned to $name is used, but the recommended index 'Report_Idx' is missing.
"; - $rec = "You can create the index by executing statement 'CREATE INDEX Report_Idx ON `history` (TIMESTAMP, READING) USING BTREE;'
"; + $rec = "You can create the index by executing statement 'CREATE INDEX Report_Idx ON `history` (READING, TIMESTAMP) USING BTREE;'
"; $rec .= "Depending on your database size this command may running a long time.
"; $rec .= "Please make sure the device '$name' is operating in asynchronous mode to avoid FHEM from blocking when creating the index.
"; $rec .= "Note: If you have just created another index which covers the same fields and order as suggested (e.g. a primary key) you don't need to create the 'Report_Idx' as well !
"; @@ -3514,15 +3504,15 @@ sub DbLog_configcheck($) { @dix_tsp = DbLog_sqlget($hash,"SHOW INDEX FROM history where Key_name='Report_Idx' and Column_name='TIMESTAMP'"); if (@dix_rdg && @dix_tsp) { $check .= "At least one DbRep-device assigned to $name is used. "; - $check .= "Index 'Report_Idx' exists and contains recommended fields 'TIMESTAMP', 'READING'.
"; + $check .= "Index 'Report_Idx' exists and contains recommended fields 'READING', 'TIMESTAMP'.
"; $rec = "settings o.k."; } else { $check .= "You use at least one DbRep-device assigned to $name. "; $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'READING'.
" if (!@dix_rdg); $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'TIMESTAMP'.
" if (!@dix_tsp); - $rec = "The index should contain the fields 'TIMESTAMP', 'READING'. "; + $rec = "The index should contain the fields 'READING', 'TIMESTAMP'. "; $rec .= "You can change the index by executing e.g.
"; - $rec .= "'ALTER TABLE `history` DROP INDEX `Report_Idx`, ADD INDEX `Report_Idx` (`TIMESTAMP`, `READING`) USING BTREE'
"; + $rec .= "'ALTER TABLE `history` DROP INDEX `Report_Idx`, ADD INDEX `Report_Idx` (`READING`, `TIMESTAMP`) USING BTREE'
"; $rec .= "Depending on your database size this command may running a long time.
"; } } @@ -3531,7 +3521,7 @@ sub DbLog_configcheck($) { @dix = DbLog_sqlget($hash,"SELECT * FROM pg_indexes WHERE tablename='history' and indexname ='Report_Idx'"); if (!@dix) { $check .= "You use at least one DbRep-device assigned to $name, but the recommended index 'Report_Idx' is missing.
"; - $rec = "You can create the index by executing statement 'CREATE INDEX \"Report_Idx\" ON history USING btree (\"timestamp\", reading)'
"; + $rec = "You can create the index by executing statement 'CREATE INDEX \"Report_Idx\" ON history USING btree (reading, \"timestamp\")'
"; $rec .= "Depending on your database size this command may running a long time.
"; $rec .= "Please make sure the device '$name' is operating in asynchronous mode to avoid FHEM from blocking when creating the index.
"; $rec .= "Note: If you have just created another index which covers the same fields and order as suggested (e.g. a primary key) you don't need to create the 'Report_Idx' as well !
"; @@ -3540,14 +3530,14 @@ sub DbLog_configcheck($) { $irep_rdg = 1 if($irep =~ /reading/); $irep_tsp = 1 if($irep =~ /timestamp/); if ($irep_rdg && $irep_tsp) { - $check .= "Index 'Report_Idx' exists and contains recommended fields 'TIMESTAMP', 'READING'.
"; + $check .= "Index 'Report_Idx' exists and contains recommended fields 'READING', 'TIMESTAMP'.
"; $rec = "settings o.k."; } else { $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'READING'.
" if (!$irep_rdg); $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'TIMESTAMP'.
" if (!$irep_tsp); - $rec = "The index should contain the fields 'TIMESTAMP', 'READING'. "; + $rec = "The index should contain the fields 'READING', 'TIMESTAMP'. "; $rec .= "You can change the index by executing e.g.
"; - $rec .= "'DROP INDEX \"Report_Idx\"; CREATE INDEX \"Report_Idx\" ON history USING btree (\"timestamp\", reading)'
"; + $rec .= "'DROP INDEX \"Report_Idx\"; CREATE INDEX \"Report_Idx\" ON history USING btree (reading, \"timestamp\")'
"; $rec .= "Depending on your database size this command may running a long time.
"; } } @@ -3556,7 +3546,7 @@ sub DbLog_configcheck($) { @dix = DbLog_sqlget($hash,"SELECT name,sql FROM sqlite_master WHERE type='index' AND name='Report_Idx'"); if (!$dix[0]) { $check .= "The index 'Report_Idx' is missing.
"; - $rec = "You can create the index by executing statement 'CREATE INDEX Report_Idx ON `history` (TIMESTAMP, READING)'
"; + $rec = "You can create the index by executing statement 'CREATE INDEX Report_Idx ON `history` (READING, TIMESTAMP)'
"; $rec .= "Depending on your database size this command may running a long time.
"; $rec .= "Please make sure the device '$name' is operating in asynchronous mode to avoid FHEM from blocking when creating the index.
"; $rec .= "Note: If you have just created another index which covers the same fields and order as suggested (e.g. a primary key) you don't need to create the 'Search_Idx' as well !
"; @@ -3565,14 +3555,14 @@ sub DbLog_configcheck($) { $irep_rdg = 1 if(lc($irep) =~ /reading/); $irep_tsp = 1 if(lc($irep) =~ /timestamp/); if ($irep_rdg && $irep_tsp) { - $check .= "Index 'Report_Idx' exists and contains recommended fields 'TIMESTAMP', 'READING'.
"; + $check .= "Index 'Report_Idx' exists and contains recommended fields 'READING', 'TIMESTAMP'.
"; $rec = "settings o.k."; } else { $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'READING'.
" if (!$irep_rdg); $check .= "Index 'Report_Idx' exists but doesn't contain recommended field 'TIMESTAMP'.
" if (!$irep_tsp); - $rec = "The index should contain the fields 'TIMESTAMP', 'READING'. "; + $rec = "The index should contain the fields 'READING', 'TIMESTAMP'. "; $rec .= "You can change the index by executing e.g.
"; - $rec .= "'DROP INDEX \"Report_Idx\"; CREATE INDEX Report_Idx ON `history` (TIMESTAMP, READING)'
"; + $rec .= "'DROP INDEX \"Report_Idx\"; CREATE INDEX Report_Idx ON `history` (READING, TIMESTAMP)'
"; $rec .= "Depending on your database size this command may running a long time.
"; } } @@ -5202,10 +5192,10 @@ sub DbLog_chartQuery($@) { return $jsonstring; } -# +################################################################ # get ReadingsVal # get ReadingsTimestamp -# +################################################################ sub DbLog_dbReadings($@) { my($hash,@a) = @_; @@ -5230,6 +5220,41 @@ sub DbLog_dbReadings($@) { return "Syntax error: $a[1]"; } +################################################################ +# Versionierungen des Moduls setzen +# Die Verwendung von Meta.pm und Packages wird berücksichtigt +################################################################ +sub DbLog_setVersionInfo($) { + my ($hash) = @_; + my $name = $hash->{NAME}; + + my $v = (sortTopicNum("desc",keys %DbLog_vNotesIntern))[0]; + my $type = $hash->{TYPE}; + $hash->{HELPER}{PACKAGE} = __PACKAGE__; + $hash->{HELPER}{VERSION} = $v; + + 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{SMAPortal}{META}} + if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id$ 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$ im Kopf komplett! vorhanden ) + if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) { + # es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen + # mit {->VERSION()} im FHEMWEB kann Modulversion abgefragt werden + use version 0.77; our $VERSION = FHEM::Meta::Get( $hash, 'version' ); + } + } else { + # herkömmliche Modulstruktur + $hash->{VERSION} = $v; + } + +return; +} + 1; =pod @@ -5793,7 +5818,7 @@ sub DbLog_dbReadings($@) { An integer used to set the limit for the sql used for query 'getTableData'

- Examples: + Examples:
  • get logdb - webchart "" "" "" getcharts
    Retrieves all saved charts from the Database
  • @@ -5816,7 +5841,9 @@ sub DbLog_dbReadings($@) { Attributes

    -
      addStateEvent +
        + +
      • addStateEvent
          attr <device> addStateEvent [0|1]
          @@ -5828,10 +5855,13 @@ sub DbLog_dbReadings($@) { Try it if you have trouble with the default adjustment.
        +

      -
        asyncMode +
          + +
        • asyncMode
            attr <device> asyncMode [1|0]
            @@ -5846,10 +5876,13 @@ sub DbLog_dbReadings($@) { In synchronous mode (normal mode) the events won't be cached im memory and get saved into database immediately. If the database isn't available the events are get lost.
          +

        -
          commitMode +
            + +
          • commitMode
              attr <device> commitMode [basic_ta:on | basic_ta:off | ac:on_ta:on | ac:on_ta:off | ac:off_ta:on]
              @@ -5867,10 +5900,13 @@ sub DbLog_dbReadings($@) {
          +

        -
          cacheEvents +
            + +
          • cacheEvents
              attr <device> cacheEvents [2|1|0]
              @@ -5881,10 +5917,13 @@ sub DbLog_dbReadings($@) { the database.
          +

        -
          cacheLimit +
            + +
          • cacheLimit
              attr <device> cacheLimit <n> @@ -5894,10 +5933,13 @@ sub DbLog_dbReadings($@) { in cache has reached (default: 500). Thereby the timer of asynchronous logging mode will be set new to the value of attribute "syncInterval". In case of error the next write attempt will be started at the earliest after syncInterval/2.
            +

          -
            colEvent +
              + +
            • colEvent
                attr <device> colEvent <n> @@ -5909,10 +5951,13 @@ sub DbLog_dbReadings($@) { Note:
                If the attribute is set, all of the field length limits are valid also for SQLite databases as noticed in Internal COLUMNS !
              +

            -
              colReading +
                + +
              • colReading
                  attr <device> colReading <n> @@ -5924,10 +5969,13 @@ sub DbLog_dbReadings($@) { Note:
                  If the attribute is set, all of the field length limits are valid also for SQLite databases as noticed in Internal COLUMNS !
                +

              -
                colValue +
                  + +
                • colValue
                    attr <device> colValue <n> @@ -5939,10 +5987,13 @@ sub DbLog_dbReadings($@) { Note:
                    If the attribute is set, all of the field length limits are valid also for SQLite databases as noticed in Internal COLUMNS !
                  +

                -
                  DbLogType +
                    + +
                  • DbLogType
                      attr <device> DbLogType [Current|History|Current/History] @@ -5975,17 +6026,20 @@ sub DbLog_dbReadings($@) { Note:
                      The current-table has to be used to get a Device:Reading-DropDown list when a SVG-Plot will be created.
                    +

                  -
                    DbLogSelectionMode +
                      + +
                    • DbLogSelectionMode
                        attr <device> DbLogSelectionMode [Exclude|Include|Exclude/Include]
                        Thise DbLog-Device-Attribute specifies how the device specific Attributes DbLogExclude and DbLogInclude are handled. - If this Attribute is missing it defaults to "Exclude". + If this Attribute is missing it defaults to "Exclude".

                        • 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
                        • @@ -5997,10 +6051,13 @@ sub DbLog_dbReadings($@) { excluded reading.
                      +

                    -
                      DbLogInclude +
                        + +
                      • DbLogInclude
                          attr <device> DbLogInclude regex:MinInterval,[regex:MinInterval] ... @@ -6017,10 +6074,13 @@ sub DbLog_dbReadings($@) { attr MyDevice1 DbLogInclude .*
                          attr MyDevice2 DbLogInclude state,(floorplantext|MyUserReading):300,battery:3600
                        +

                      -
                        DbLogExclude +
                          + +
                        • DbLogExclude
                            attr <device> DbLogExclude regex:MinInterval,[regex:MinInterval] ... @@ -6037,10 +6097,28 @@ sub DbLog_dbReadings($@) { attr MyDevice1 DbLogExclude .*
                            attr MyDevice2 DbLogExclude state,(floorplantext|MyUserReading):300,battery:3600
                          +
                        • +
                        +
                        + +
                          + +
                        • disable +
                            + + attr <device> disable [0|1] +
                            + + Disables the DbLog device (1) or enables it (0). +
                            +
                          +

                        -
                          excludeDevs +
                            + +
                          • excludeDevs
                              attr <device> excludeDevs <devspec1>[#Reading],<devspec2>[#Reading],<devspec...> @@ -6069,9 +6147,12 @@ sub DbLog_dbReadings($@) { # The event containing device "SMA_Energymeter" and reading "Bezug_WirkP_Zaehler_Diff" are excluded from logging.
                          +
                          -
                            expimpdir +
                              + +
                            • expimpdir
                                attr <device> expimpdir <directory> @@ -6087,10 +6168,13 @@ sub DbLog_dbReadings($@) { attr <device> expimpdir /opt/fhem/cache/
                              +

                            -
                              exportCacheAppend +
                                + +
                              • exportCacheAppend
                                  attr <device> exportCacheAppend [1|0] @@ -6100,10 +6184,13 @@ sub DbLog_dbReadings($@) { export file. If there is no exististing export file, it will be new created.
                                  If the attribute not set, every export process creates a new export file . (default)
                                +

                              -
                                noNotifyDev +
                                  + +
                                • noNotifyDev
                                    attr <device> noNotifyDev [1|0] @@ -6111,10 +6198,13 @@ sub DbLog_dbReadings($@) { Enforces that NOTIFYDEV won't set and hence won't used.
                                  +

                                -
                                  noSupportPK +
                                    + +
                                  • noSupportPK
                                      attr <device> noSupportPK [1|0] @@ -6122,29 +6212,26 @@ sub DbLog_dbReadings($@) { Deactivates the support of a set primary key by the module.
                                    +

                                  -
                                    syncEvents +
                                      + +
                                    • syncEvents
                                        attr <device> syncEvents [1|0]
                                        events of reading syncEvents will be created.
                                      -
                                    -
                                    - -
                                      shutdownWait -
                                        - attr <device> shutdownWait -
                                        - causes fhem shutdown to wait n seconds for pending database commit
                                        -
                                      +

                                    -
                                      showproctime +
                                        + +
                                      • showproctime
                                          attr <device> [1|0]
                                          @@ -6153,10 +6240,13 @@ sub DbLog_dbReadings($@) { for a single sql-statement, but the summary of all sql-statements necessary for within an executed DbLog-function in background. The reading "background_processing_time" shows the total time used in background.
                                        +

                                      -
                                        showNotifyTime +
                                          + +
                                        • showNotifyTime
                                            attr <device> showNotifyTime [1|0]
                                            @@ -6166,10 +6256,13 @@ sub DbLog_dbReadings($@) { required when the operation mode was switched from synchronous to the asynchronous mode.
                                          +

                                        -
                                          syncInterval +
                                            + +
                                          • syncInterval
                                              attr <device> syncInterval <n>
                                              @@ -6178,43 +6271,55 @@ sub DbLog_dbReadings($@) { used for storage the in memory cached events into the database. THe default value is 30 seconds.
                                            +

                                          -
                                            suppressAddLogV3 +
                                              + +
                                            • suppressAddLogV3
                                                attr <device> suppressAddLogV3 [1|0]
                                                - If set, verbose3-Logfileentries done by the addLog-function will be suppressed.
                                                + If set, verbose 3 Logfileentries done by the addLog-function will be suppressed.
                                              +

                                            -
                                              suppressUndef +
                                                + +
                                              • suppressUndef
                                                  - attr <device> ignoreUndef + attr <device> suppressUndef
                                                  - suppresses all undef values when returning data from the DB via get
                                                  + suppresses all undef values when returning data from the DB via get

                                                  Example
                                                  #DbLog eMeter:power:::$val=($val>1500)?undef:$val
                                                +

                                              -
                                                timeout +
                                                  + +
                                                • timeout
                                                    attr <device> timeout
                                                    setup timeout of the write cycle into database in asynchronous mode (default 86400s)
                                                  +

                                                -
                                                  traceFlag +
                                                    + +
                                                  • traceFlag
                                                      attr <device> traceFlag [ALL|SQL|CON|ENC|DBD|TXN] @@ -6237,10 +6342,13 @@ sub DbLog_dbReadings($@) {
                                                    +

                                                  -
                                                    traceLevel +
                                                      + +
                                                    • traceLevel
                                                        attr <device> traceLevel [0|1|2|3|4|5|6|7] @@ -6265,10 +6373,13 @@ sub DbLog_dbReadings($@) {
                                                      +

                                                    -
                                                      useCharfilter +
                                                        + +
                                                      • useCharfilter
                                                          attr <device> useCharfilter [0|1] @@ -6277,10 +6388,13 @@ sub DbLog_dbReadings($@) { That are the characters " A-Za-z0-9!"#$%&'()*+,-.\/:;<=>?@[\\]^_`{|}~" .
                                                          Mutated vowel and "€" are transcribed (e.g. ä to ae). (default: 0).
                                                        +

                                                      -
                                                        valueFn +
                                                          + +
                                                        • valueFn
                                                            attr <device> valueFn {} @@ -6307,10 +6421,13 @@ sub DbLog_dbReadings($@) {
                                                            # set the unit of device "Dum.Energy" to "W" if reading is "TotalConsumption"

                                                          +

                                                        -
                                                          verbose4Devs +
                                                            + +
                                                          • verbose4Devs
                                                              attr <device> verbose4Devs <device1>,<device2>,<device..> @@ -6318,7 +6435,7 @@ sub DbLog_dbReadings($@) { If verbose level 4 is used, only output of devices set in this attribute will be reported in FHEM central logfile. If this attribute isn't set, output of all relevant devices will be reported if using verbose level 4. - The given devices are evaluated as Regex.
                                                              + The given devices are evaluated as Regex.

                                                              Example
                                                              @@ -6327,6 +6444,7 @@ sub DbLog_dbReadings($@) { # The devices starting with "sys", "Cam" respectively devices are containing "5000" in its name and the device "global" will be reported in FHEM central Logfile if verbose=4 is set.
                                                            +

                                                          @@ -6953,7 +7071,8 @@ sub DbLog_dbReadings($@) { Ein Integer um den Limitwert für die Abfrage 'getTableData' festzulegen


                                                        - Beispiele: + + Beispiele:
                                                        • get logdb - webchart "" "" "" getcharts
                                                          Liefert alle gespeicherten Charts aus der Datenbank
                                                        • @@ -6981,7 +7100,9 @@ sub DbLog_dbReadings($@) { Attribute

                                                          -
                                                            addStateEvent +
                                                              + +
                                                            • addStateEvent
                                                                attr <device> addStateEvent [0|1]
                                                                @@ -6994,10 +7115,13 @@ sub DbLog_dbReadings($@) { Versuchen sie bitte diese Einstellung, falls es mit dem Standard Probleme geben sollte.
                                                              +

                                                            -
                                                              asyncMode +
                                                                + +
                                                              • asyncMode
                                                                  attr <device> asyncMode [1|0]
                                                                  @@ -7012,10 +7136,13 @@ sub DbLog_dbReadings($@) { Im synchronen Modus (Normalmodus) werden die Events nicht gecacht und sofort in die Datenbank geschrieben. Ist die Datenbank nicht verfügbar gehen sie verloren.
                                                                +

                                                              -
                                                                commitMode +
                                                                  + +
                                                                • commitMode
                                                                    attr <device> commitMode [basic_ta:on | basic_ta:off | ac:on_ta:on | ac:on_ta:off | ac:off_ta:on]
                                                                    @@ -7031,13 +7158,15 @@ sub DbLog_dbReadings($@) {
                                                                  • ac:on_ta:on - Autocommit ein / Transaktion ein
                                                                  • ac:on_ta:off - Autocommit ein / Transaktion aus
                                                                  • ac:off_ta:on - Autocommit aus / Transaktion ein (Autocommit "aus" impliziert Transaktion "ein")
                                                                  • -
                                                                  - +
                                                              +

                                                            -
                                                              cacheEvents +
                                                                + +
                                                              • cacheEvents
                                                                  attr <device> cacheEvents [2|1|0]
                                                                  @@ -7048,10 +7177,13 @@ sub DbLog_dbReadings($@) { Datensätze.
                                                              +

                                                            -
                                                              cacheLimit +
                                                                + +
                                                              • cacheLimit
                                                                  attr <device> cacheLimit <n> @@ -7061,10 +7193,13 @@ sub DbLog_dbReadings($@) { im Cache erreicht ist (Default: 500). Der Timer des asynchronen Logmodus wird dabei neu auf den Wert des Attributs "syncInterval" gesetzt. Im Fehlerfall wird ein erneuter Schreibversuch frühestens nach syncInterval/2 gestartet.
                                                                +

                                                              -
                                                                colEvent +
                                                                  + +
                                                                • colEvent
                                                                    attr <device> colEvent <n> @@ -7076,10 +7211,13 @@ sub DbLog_dbReadings($@) { Hinweis:
                                                                    Mit gesetztem Attribut gelten alle Feldlängenbegrenzungen auch für SQLite DB wie im Internal COLUMNS angezeigt !
                                                                  +

                                                                -
                                                                  colReading +
                                                                    + +
                                                                  • colReading
                                                                      attr <device> colReading <n> @@ -7091,10 +7229,13 @@ sub DbLog_dbReadings($@) { Hinweis:
                                                                      Mit gesetztem Attribut gelten alle Feldlängenbegrenzungen auch für SQLite DB wie im Internal COLUMNS angezeigt !
                                                                    +

                                                                  -
                                                                    colValue +
                                                                      + +
                                                                    • colValue
                                                                        attr <device> colValue <n> @@ -7106,10 +7247,13 @@ sub DbLog_dbReadings($@) { Hinweis:
                                                                        Mit gesetztem Attribut gelten alle Feldlängenbegrenzungen auch für SQLite DB wie im Internal COLUMNS angezeigt !
                                                                      +

                                                                    -
                                                                      DbLogType +
                                                                        + +
                                                                      • DbLogType
                                                                          attr <device> DbLogType [Current|History|Current/History|SampleFill/History] @@ -7142,10 +7286,13 @@ sub DbLog_dbReadings($@) { Die Current-Tabelle muß genutzt werden um eine Device:Reading-DropDownliste zur Erstellung eines SVG-Plots zu erhalten.
                                                                        +

                                                                      -
                                                                        DbLogSelectionMode +
                                                                          + +
                                                                        • DbLogSelectionMode
                                                                            attr <device> DbLogSelectionMode [Exclude|Include|Exclude/Include] @@ -7167,10 +7314,13 @@ sub DbLog_dbReadings($@) { werden somit dennoch geloggt.
                                                                        +

                                                                      -
                                                                        DbLogInclude +
                                                                          + +
                                                                        • DbLogInclude
                                                                            attr <device> DbLogInclude regex:MinInterval,[regex:MinInterval] ... @@ -7188,10 +7338,13 @@ sub DbLog_dbReadings($@) { attr MyDevice1 DbLogInclude .*
                                                                            attr MyDevice2 DbLogInclude state,(floorplantext|MyUserReading):300,battery:3600
                                                                          +

                                                                        -
                                                                          DbLogExclude +
                                                                            + +
                                                                          • DbLogExclude
                                                                              attr <device> DbLogExclude regex:MinInterval,[regex:MinInterval] ... @@ -7207,10 +7360,28 @@ sub DbLog_dbReadings($@) { attr MyDevice1 DbLogExclude .*
                                                                              attr MyDevice2 DbLogExclude state,(floorplantext|MyUserReading):300,battery:3600
                                                                            +

                                                                          -
                                                                            excludeDevs +
                                                                              + +
                                                                            • disable +
                                                                                + + attr <device> disable [0|1] +
                                                                                + + Das DbLog Device wird disabled (1) bzw. enabled (0). +
                                                                                +
                                                                              +
                                                                            • +
                                                                            +
                                                                            + +
                                                                              + +
                                                                            • excludeDevs
                                                                                attr <device> excludeDevs <devspec1>[#Reading],<devspec2>[#Reading],<devspec...> @@ -7239,10 +7410,13 @@ sub DbLog_dbReadings($@) { # Es wird der Event mit Device "SMA_Energymeter" und Reading "Bezug_WirkP_Zaehler_Diff" vom Logging ausgeschlossen.
                                                                              +

                                                                            -
                                                                              expimpdir +
                                                                                + +
                                                                              • expimpdir
                                                                                  attr <device> expimpdir <directory> @@ -7257,10 +7431,13 @@ sub DbLog_dbReadings($@) { attr <device> expimpdir /opt/fhem/cache/
                                                                                +

                                                                              -
                                                                                exportCacheAppend +
                                                                                  + +
                                                                                • exportCacheAppend
                                                                                    attr <device> exportCacheAppend [1|0] @@ -7270,10 +7447,13 @@ sub DbLog_dbReadings($@) { Exportfile angehängt. Ist noch kein Exportfile vorhanden, wird es neu angelegt.
                                                                                    Ist das Attribut nicht gesetzt, wird bei jedem Exportvorgang ein neues Exportfile angelegt. (default)
                                                                                  +

                                                                                -
                                                                                  noNotifyDev +
                                                                                    + +
                                                                                  • noNotifyDev
                                                                                      attr <device> noNotifyDev [1|0] @@ -7281,10 +7461,13 @@ sub DbLog_dbReadings($@) { Erzwingt dass NOTIFYDEV nicht gesetzt und somit nicht verwendet wird.
                                                                                    +

                                                                                  -
                                                                                    noSupportPK +
                                                                                      + +
                                                                                    • noSupportPK
                                                                                        attr <device> noSupportPK [1|0] @@ -7292,21 +7475,13 @@ sub DbLog_dbReadings($@) { Deaktiviert die programmtechnische Unterstützung eines gesetzten Primary Key durch das Modul.
                                                                                      +

                                                                                    -
                                                                                      shutdownWait -
                                                                                        - - attr <device> shutdownWait -
                                                                                        - - FHEM wartet während des shutdowns fuer n Sekunden, um die Datenbank korrekt zu beenden
                                                                                        -
                                                                                      -
                                                                                    -
                                                                                    - -
                                                                                      showproctime +
                                                                                        + +
                                                                                      • showproctime
                                                                                          attr <device> showproctime [1|0]
                                                                                          @@ -7316,10 +7491,13 @@ sub DbLog_dbReadings($@) { jeweiligen Funktion betrachtet. Das Reading "background_processing_time" zeigt die im Kindprozess BlockingCall verbrauchte Zeit.
                                                                                        +

                                                                                      -
                                                                                        showNotifyTime +
                                                                                          + +
                                                                                        • showNotifyTime
                                                                                            attr <device> showNotifyTime [1|0]
                                                                                            @@ -7329,20 +7507,26 @@ sub DbLog_dbReadings($@) { im Zeitbedarf bei der Umschaltung des synchronen in den asynchronen Modus festzustellen.
                                                                                          +

                                                                                        -
                                                                                          syncEvents +
                                                                                            + +
                                                                                          • syncEvents
                                                                                              attr <device> syncEvents [1|0]
                                                                                              es werden Events für Reading NextSync erzeugt.
                                                                                            +

                                                                                          -
                                                                                            syncInterval +
                                                                                              + +
                                                                                            • syncInterval
                                                                                                attr <device> syncInterval <n>
                                                                                                @@ -7351,42 +7535,54 @@ sub DbLog_dbReadings($@) { der im Speicher gecachten Events in die Datenbank eingestellt. Der Defaultwert ist 30 Sekunden.
                                                                                              +

                                                                                            -
                                                                                              suppressAddLogV3 +
                                                                                                + +
                                                                                              • suppressAddLogV3
                                                                                                  attr <device> suppressAddLogV3 [1|0]
                                                                                                  - Wenn gesetzt werden verbose3-Logeinträge durch die addLog-Funktion unterdrückt.
                                                                                                  + Wenn gesetzt werden verbose 3 Logeinträge durch die addLog-Funktion unterdrückt.
                                                                                                +

                                                                                              -
                                                                                                suppressUndef +
                                                                                                  + +
                                                                                                • suppressUndef
                                                                                                    - attr <device> ignoreUndef + attr <device> suppressUndef
                                                                                                    - Unterdrueckt alle undef Werte die durch eine Get-Anfrage zb. Plot aus der Datenbank selektiert werden
                                                                                                    + Unterdrueckt alle undef Werte die durch eine Get-Anfrage zb. Plot aus der Datenbank selektiert werden

                                                                                                    Beispiel
                                                                                                    #DbLog eMeter:power:::$val=($val>1500)?undef:$val
                                                                                                  +

                                                                                                -
                                                                                                  timeout +
                                                                                                    + +
                                                                                                  • timeout
                                                                                                      attr <device> timeout
                                                                                                      Setzt den Timeout-Wert für den Schreibzyklus in die Datenbank im asynchronen Modus (default 86400s).
                                                                                                    +

                                                                                                  -
                                                                                                    traceFlag +
                                                                                                      + +
                                                                                                    • traceFlag
                                                                                                        attr <device> traceFlag [ALL|SQL|CON|ENC|DBD|TXN] @@ -7409,10 +7605,13 @@ sub DbLog_dbReadings($@) {
                                                                                                      +

                                                                                                    -
                                                                                                      traceLevel +
                                                                                                        + +
                                                                                                      • traceLevel
                                                                                                          attr <device> traceLevel [0|1|2|3|4|5|6|7] @@ -7438,10 +7637,13 @@ sub DbLog_dbReadings($@) {
                                                                                                        +

                                                                                                      -
                                                                                                        useCharfilter +
                                                                                                          + +
                                                                                                        • useCharfilter
                                                                                                            attr <device> useCharfilter [0|1] @@ -7450,10 +7652,13 @@ sub DbLog_dbReadings($@) { Das sind die Zeichen " A-Za-z0-9!"#$%&'()*+,-.\/:;<=>?@[\\]^_`{|}~".
                                                                                                            Umlaute und "€" werden umgesetzt (z.B. ä nach ae, € nach EUR).
                                                                                                          +

                                                                                                        -
                                                                                                          valueFn +
                                                                                                            + +
                                                                                                          • valueFn
                                                                                                              attr <device> valueFn {} @@ -7481,10 +7686,13 @@ sub DbLog_dbReadings($@) {
                                                                                                              # setzt die Einheit des Devices "Dum.Energy" auf "W" wenn das Reading = "TotalConsumption" ist

                                                                                                            +

                                                                                                          -
                                                                                                            verbose4Devs +
                                                                                                              + +
                                                                                                            • verbose4Devs
                                                                                                                attr <device> verbose4Devs <device1>,<device2>,<device..> @@ -7492,7 +7700,7 @@ sub DbLog_dbReadings($@) { Mit verbose Level 4 werden nur Ausgaben bezüglich der in diesem Attribut aufgeführten Devices im Logfile protokolliert. Ohne dieses Attribut werden mit verbose 4 Ausgaben aller relevanten Devices im Logfile protokolliert. - Die angegebenen Devices werden als Regex ausgewertet.
                                                                                                                + Die angegebenen Devices werden als Regex ausgewertet.

                                                                                                                Beispiel
                                                                                                                @@ -7501,6 +7709,7 @@ sub DbLog_dbReadings($@) { # Es werden Devices beginnend mit "sys", "Cam" bzw. Devices die "5000" enthalten und das Device "global" protokolliert falls verbose=4 eingestellt ist.
                                                                                                              +

                                                                                                            @@ -7508,6 +7717,63 @@ sub DbLog_dbReadings($@) { =end html_DE +=for :application/json;q=META.json 93_DbLog.pm +{ + "abstract": "logs events into a database", + "x_lang": { + "de": { + "abstract": "loggt Events in eine Datenbank" + } + }, + "keywords": [ + "dblog", + "database", + "events", + "logging", + "asynchronous" + ], + "version": "v1.1.1", + "release_status": "stable", + "author": [ + "Heiko Maaz " + ], + "x_fhem_maintainer": [ + "DS_Starter" + ], + "x_fhem_maintainer_github": [ + "nasseeder1" + ], + "prereqs": { + "runtime": { + "requires": { + "FHEM": 5.00918799, + "perl": 5.014, + "Data::Dumper": 0, + "DBI": 0, + "DBD::mysql" :0, + "DBD::SQLite" :0, + "Blocking": 0, + "Time::HiRes": 0, + "Time::Local": 0, + "Encode": 0 + }, + "recommends": { + "FHEM::Meta": 0, + "DBD::Pg" :0 + }, + "suggests": { + } + } + }, + "resources": { + "x_wiki": { + "web": "https://wiki.fhem.de/wiki/DbLog", + "title": "DbLog" + } + } +} +=end :application/json;q=META.json + =cut