2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-04 05:16:45 +00:00

93_DbLog.pm: contrib V 5.10.0

git-svn-id: https://svn.fhem.de/fhem/trunk@28654 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2024-03-13 13:28:07 +00:00
parent 696730e0df
commit a2b2705aef

View File

@ -142,8 +142,7 @@ my %DbLog_vNotesIntern = (
); );
# Steuerhashes # Steuerhashes
############### ################
my %DbLog_hset = ( # Hash der Set-Funktion my %DbLog_hset = ( # Hash der Set-Funktion
listCache => { fn => \&_DbLog_setlistCache }, listCache => { fn => \&_DbLog_setlistCache },
clearReadings => { fn => \&_DbLog_setclearReadings }, clearReadings => { fn => \&_DbLog_setclearReadings },
@ -165,18 +164,19 @@ my %DbLog_hset = (
); );
my %DbLog_hget = ( # Hash der Get-Funktion my %DbLog_hget = ( # Hash der Get-Funktion
ReadingsVal => { fn => \&_DbLog_dbReadings }, ReadingsVal => { fn => \&_DbLog_dbReadings },
ReadingsTimestamp => { fn => \&_DbLog_dbReadings }, ReadingsTimestamp => { fn => \&_DbLog_dbReadings },
ReadingsValTimestamp => { fn => \&_DbLog_dbReadings }, ReadingsValTimestamp => { fn => \&_DbLog_dbReadings },
ReadingsMaxVal => { fn => \&_DbLog_dbReadings }, ReadingsMaxVal => { fn => \&_DbLog_dbReadings },
ReadingsMaxValTimestamp => { fn => \&_DbLog_dbReadings }, ReadingsMaxValTimestamp => { fn => \&_DbLog_dbReadings },
ReadingsMinVal => { fn => \&_DbLog_dbReadings }, ReadingsMinVal => { fn => \&_DbLog_dbReadings },
ReadingsMinValTimestamp => { fn => \&_DbLog_dbReadings }, ReadingsMinValTimestamp => { fn => \&_DbLog_dbReadings },
ReadingsAvgVal => { fn => \&_DbLog_dbReadings }, ReadingsAvgVal => { fn => \&_DbLog_dbReadings },
webchart => { fn => \&_DbLog_chartQuery }, webchart => { fn => \&_DbLog_chartQuery },
plotdata => { fn => \&_DbLog_plotData }, plotdata => { fn => \&_DbLog_plotData },
retrieve => { fn => \&_DbLog_chartQuery }, retrieve => { fn => \&_DbLog_chartQuery },
configCheck => { fn => \&DbLog_configcheck }, configCheck => { fn => \&DbLog_configcheck },
showConfigFile => { fn => \&_DbLog_showConfigFile },
); );
my %DbLog_columns = ("DEVICE" => 64, my %DbLog_columns = ("DEVICE" => 64,
@ -5722,30 +5722,28 @@ return $retv;
} }
################################################################################### ###################################################################################
# Verbindungen zur DB aufbauen # Konfiguration lesen und auswerten
################################################################################### ###################################################################################
sub DbLog_readCfg { sub DbLog_readCfg {
my $hash = shift; my $hash = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $configfilename = $hash->{CONFIGURATION};
my $configfilename= $hash->{CONFIGURATION}; my ($err, $dbconfig) = _DbLog_confRead ($hash, $configfilename);
my %dbconfig;
# use generic fileRead to get configuration data
my ($err, @config) = FileRead($configfilename);
return $err if($err); return $err if($err);
eval join("\n", @config); $hash->{dbconn} = $dbconfig->{connection};
return "could not read user" if(!defined $dbconfig->{user});
return "could not read connection" if (!defined $dbconfig{connection});
$hash->{dbconn} = $dbconfig{connection}; $hash->{dbuser} = $dbconfig->{user};
return "could not read user" if (!defined $dbconfig{user}); return "could not read password" if(!defined $dbconfig->{password});
$hash->{dbuser} = $dbconfig{user};
return "could not read password" if (!defined $dbconfig{password}); $attr{"sec$name"}{secret} = $dbconfig->{password};
$attr{"sec$name"}{secret} = $dbconfig{password};
#check the database model #check the database model
if($hash->{dbconn} =~ m/pg:/i) { ###########################
if ($hash->{dbconn} =~ m/pg:/i) {
$hash->{MODEL} = 'POSTGRESQL'; $hash->{MODEL} = 'POSTGRESQL';
} }
elsif ($hash->{dbconn} =~ m/mysql:/i) { elsif ($hash->{dbconn} =~ m/mysql:/i) {
@ -5773,17 +5771,36 @@ sub DbLog_readCfg {
delete $hash->{COMPRESSION}; delete $hash->{COMPRESSION};
if ($hash->{MODEL} =~ /MYSQL/xs) { if ($hash->{MODEL} =~ /MYSQL/xs) {
$hash->{UTF8} = defined $dbconfig{utf8} ? $dbconfig{utf8} : 0; $hash->{UTF8} = defined $dbconfig->{utf8} ? $dbconfig->{utf8} : 0;
$hash->{COMPRESSION} = defined $dbconfig{compression} ? $dbconfig{compression} : 0; $hash->{COMPRESSION} = defined $dbconfig->{compression} ? $dbconfig->{compression} : 0;
} }
if ($hash->{MODEL} =~ /MARIADB/xs) { if ($hash->{MODEL} =~ /MARIADB/xs) {
$hash->{COMPRESSION} = defined $dbconfig{compression} ? $dbconfig{compression} : 0; $hash->{COMPRESSION} = defined $dbconfig->{compression} ? $dbconfig->{compression} : 0;
} }
return; return;
} }
###################################################################################
# Konfiguration lesen
###################################################################################
sub _DbLog_confRead {
my $hash = shift;
my $configfilename = shift // $hash->{CONFIGURATION};
my %dbconfig;
my ($err, @config) = FileRead ($configfilename);
return $err if($err);
eval join "\n", @config;
return "could not read connection" if(!defined $dbconfig{connection});
return ($err, \%dbconfig);
}
################################################################# #################################################################
# DBHU Verwaltung im Hauptprozess (Universal DB Handle) # DBHU Verwaltung im Hauptprozess (Universal DB Handle)
# #
@ -5962,14 +5979,33 @@ sub DbLog_Get {
return $getlist; return $getlist;
} }
######################################################################################## ###################################################################################
# Konfigurationfile anzeigen
###################################################################################
sub _DbLog_showConfigFile {
my $paref = shift;
my $hash = $paref->{hash};
my ($err, $dbconfig) = _DbLog_confRead ($hash);
return $err if($err);
my $ret = '';
for my $k (sort keys %{$dbconfig}) {
$ret .= "$k => $dbconfig->{$k} <br>";
}
return $ret;
}
###################################################################################
# get <dbLog> ReadingsVal <device> <reading> <default> # get <dbLog> ReadingsVal <device> <reading> <default>
# get <dbLog> ReadingsTimestamp <device> <reading> <default> # get <dbLog> ReadingsTimestamp <device> <reading> <default>
# get <dbLog> ReadingsValTimestamp <device> <reading> <default> # get <dbLog> ReadingsValTimestamp <device> <reading> <default>
# get <dbLog> ReadingsMaxVal[Timestamp] <device> <reading> <default> # get <dbLog> ReadingsMaxVal[Timestamp] <device> <reading> <default>
# get <dbLog> ReadingsMinVal[Timestamp] <device> <reading> <default> # get <dbLog> ReadingsMinVal[Timestamp] <device> <reading> <default>
# get <dbLog> ReadingsAvgVal <device> <reading> <default> # get <dbLog> ReadingsAvgVal <device> <reading> <default>
######################################################################################## ###################################################################################
sub _DbLog_dbReadings { sub _DbLog_dbReadings {
my $paref = shift; my $paref = shift;
@ -8599,8 +8635,9 @@ sub DbLog_fhemwebFn {
my $name = "SVG_${d}_$newIdx"; my $name = "SVG_${d}_$newIdx";
my $dstyle = qq{style='padding-left: 10px; padding-right: 10px; padding-top: 3px; padding-bottom: 3px; white-space:nowrap;'}; # TD-Style my $dstyle = qq{style='padding-left: 10px; padding-right: 10px; padding-top: 3px; padding-bottom: 3px; white-space:nowrap;'}; # TD-Style
my $cmdchk = qq{"FW_cmd('$FW_ME$FW_subdir?XHR=1&cmd=get $d configCheck', function(data){FW_okDialog(data)})"}; my $cmdchk = qq{"FW_cmd('$FW_ME$FW_subdir?XHR=1&cmd=get $d configCheck', function(data){FW_okDialog(data)})"};
my $cmdfile = qq{"FW_cmd('$FW_ME$FW_subdir?XHR=1&cmd=get $d showConfigFile', function(data){FW_okDialog(data)})"};
my $svgimg = FW_makeImage('time_graph@grey'); my $svgimg = FW_makeImage('time_graph@grey');
my $svgtitle = 'Create SVG plot from DbLog'; my $svgtitle = 'Create SVG plot from DbLog';
@ -8612,11 +8649,16 @@ sub DbLog_fhemwebFn {
$img = FW_makeImage('edit_settings@grey'); $img = FW_makeImage('edit_settings@grey');
my $chkicon = "<a onClick=$cmdchk>$img</a>"; my $chkicon = "<a onClick=$cmdchk>$img</a>";
my $chktitle = 'Run Configuration Check'; my $chktitle = 'Run Configuration Check';
$img = FW_makeImage('control_hamburger_s@grey');
my $filicon = "<a onClick=$cmdfile>$img</a>";
my $filtitle = 'Show Configuration File Content';
if (AttrVal ('global', 'language', 'EN') eq 'DE') { if (AttrVal ('global', 'language', 'EN') eq 'DE') {
$svgtitle = "SVG-Diagramm aus DbLog erstellen"; $svgtitle = "SVG-Diagramm aus DbLog erstellen";
$fthtitle = "DbLog Forum öffnen"; $fthtitle = "DbLog Forum öffnen";
$chktitle = 'Konfigurationsprüfung ausführen'; $chktitle = 'Konfigurationsprüfung ausführen';
$filtitle = 'Inhalt der Konfigurationsdatei anzeigen';
} }
my $class = qq{<table width='10%'>}; my $class = qq{<table width='10%'>};
@ -8629,6 +8671,7 @@ sub DbLog_fhemwebFn {
$ret .= qq{<tr>}; $ret .= qq{<tr>};
$ret .= FW_pH ("cmd=define $name SVG $d:templateDB:HISTORY;set $name copyGplotFile&detail=$name", $ret .= FW_pH ("cmd=define $name SVG $d:templateDB:HISTORY;set $name copyGplotFile&detail=$name",
"<div class=\"dval\">$class</div>", 1, "dval", 1); "<div class=\"dval\">$class</div>", 1, "dval", 1);
$ret .= qq{<td align="left" title="$filtitle" $dstyle> $filicon </td>};
$ret .= qq{<td align="left" title="$chktitle" $dstyle> $chkicon </td>}; $ret .= qq{<td align="left" title="$chktitle" $dstyle> $chkicon </td>};
$ret .= qq{<td align="left" title="$fthtitle" $dstyle> $fthicon </td>}; $ret .= qq{<td align="left" title="$fthtitle" $dstyle> $fthicon </td>};
$ret .= qq{</tr>}; $ret .= qq{</tr>};