93_Log2Syslog: don't use CRLF as end of data packet if EOF is used

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@23875 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2021-03-01 20:14:15 +00:00
parent 119f3bc85e
commit 01038ea8da
2 changed files with 68 additions and 43 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: 93_Log2Syslog: don't use CRLF as end of data packet if EOF is used
- feature: 49_IPCAM: added templates, improved logging - feature: 49_IPCAM: added templates, improved logging
- feature: 73_DoorBird: Maximum Size of files stored for Image, Video & Audio - feature: 73_DoorBird: Maximum Size of files stored for Image, Video & Audio
- bugfix: 49_SSCam: solve JS error, remove sscam_tooltip.js - bugfix: 49_SSCam: solve JS error, remove sscam_tooltip.js

View File

@ -3,7 +3,7 @@
########################################################################################################################## ##########################################################################################################################
# 93_Log2Syslog.pm # 93_Log2Syslog.pm
# #
# (c) 2017-2020 by Heiko Maaz # (c) 2017-2021 by Heiko Maaz
# e-mail: Heiko dot Maaz at t-online dot de # e-mail: Heiko dot Maaz at t-online dot de
# #
# This script is part of fhem. # This script is part of fhem.
@ -106,6 +106,7 @@ BEGIN {
# Versions History intern: # Versions History intern:
my %vNotesIntern = ( my %vNotesIntern = (
"5.12.4" => "27.02.2021 don't split data by CRLF if EOF is used (in getIfData) ",
"5.12.3" => "02.11.2020 avoid do Logfile archiving which was executed in seldom (unknown) cases ", "5.12.3" => "02.11.2020 avoid do Logfile archiving which was executed in seldom (unknown) cases ",
"5.12.2" => "15.05.2020 permit content of 'exclErrCond' to fhemLog strings ", "5.12.2" => "15.05.2020 permit content of 'exclErrCond' to fhemLog strings ",
"5.12.1" => "12.05.2020 add dev to check regex of 'exclErrCond' ", "5.12.1" => "12.05.2020 add dev to check regex of 'exclErrCond' ",
@ -237,18 +238,18 @@ my %vNotesExtern = (
# Mappinghash BSD-Formatierung Monat # Mappinghash BSD-Formatierung Monat
my %Log2Syslog_BSDMonth = ( my %Log2Syslog_BSDMonth = (
"01" => "Jan", "01" => "Jan",
"02" => "Feb", "02" => "Feb",
"03" => "Mar", "03" => "Mar",
"04" => "Apr", "04" => "Apr",
"05" => "May", "05" => "May",
"06" => "Jun", "06" => "Jun",
"07" => "Jul", "07" => "Jul",
"08" => "Aug", "08" => "Aug",
"09" => "Sep", "09" => "Sep",
"10" => "Oct", "10" => "Oct",
"11" => "Nov", "11" => "Nov",
"12" => "Dec", "12" => "Dec",
"Jan" => "01", "Jan" => "01",
"Feb" => "02", "Feb" => "02",
"Mar" => "03", "Mar" => "03",
@ -545,14 +546,16 @@ sub Read { ## no critic 'comple
if($hash->{TEMPORARY}) { if($hash->{TEMPORARY}) {
my $sname = $hash->{SNAME}; my $sname = $hash->{SNAME};
$rhash = $defs{$sname}; $rhash = $defs{$sname};
} else { }
else {
$rhash = $hash; $rhash = $hash;
} }
my $pp = $rhash->{PROFILE}; my $pp = $rhash->{PROFILE};
if($pp =~ /BSD/) { # Framelänge BSD-Format if($pp =~ /BSD/) { # Framelänge BSD-Format
$len = $RFC3164len{DL}; $len = $RFC3164len{DL};
} elsif ($pp =~ /IETF/) { # Framelänge IETF-Format }
elsif ($pp =~ /IETF/) { # Framelänge IETF-Format
$len = $RFC5425len{DL}; $len = $RFC5425len{DL};
} }
@ -562,9 +565,11 @@ sub Read { ## no critic 'comple
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return if(IsDisabled($name) || isMemLock($hash)); return if(IsDisabled($name) || isMemLock($hash));
my $mevt = AttrVal($name, "makeEvent", "intern"); # wie soll Reading/Event erstellt werden
my $sevevt = AttrVal($name, "respectSeverity", ""); # welcher Schweregrad soll berücksichtigt werden (default: alle) my $mevt = AttrVal($name, "makeEvent", "intern"); # wie soll Reading/Event erstellt werden
my $sevevt = AttrVal($name, "respectSeverity", "" ); # welcher Schweregrad soll berücksichtigt werden (default: alle)
my $uef = AttrVal($name, "useEOF", 0 ); # verwende EOF
if($socket) { if($socket) {
($st,$data,$hash) = getIfData($hash,$len,$mlen,$reread); ($st,$data,$hash) = getIfData($hash,$len,$mlen,$reread);
} }
@ -579,9 +584,11 @@ sub Read { ## no critic 'comple
$tail = $+{tail}; $tail = $+{tail};
$msg = substr($tail,0,$ocount); $msg = substr($tail,0,$ocount);
push @load, $msg; push @load, $msg;
if(length($tail) >= $ocount) { if(length($tail) >= $ocount) {
$tail = substr($tail,$ocount); $tail = substr($tail,$ocount);
} else { }
else {
$tail = substr($tail,length($msg)); $tail = substr($tail,length($msg));
} }
@ -597,9 +604,11 @@ sub Read { ## no critic 'comple
next if(!$tail); next if(!$tail);
$msg = substr($tail,0,$ocount); $msg = substr($tail,0,$ocount);
push @load, $msg; push @load, $msg;
if(length($tail) >= $ocount) { if(length($tail) >= $ocount) {
$tail = substr($tail,$ocount); $tail = substr($tail,$ocount);
} else { }
else {
$tail = substr($tail,length($msg)); $tail = substr($tail,length($msg));
} }
@ -607,10 +616,15 @@ sub Read { ## no critic 'comple
Log3slog ($hash, 5, "Log2Syslog $name -> MSG$i : $msg"); Log3slog ($hash, 5, "Log2Syslog $name -> MSG$i : $msg");
Log3slog ($hash, 5, "Log2Syslog $name -> LENGTH_MSG$i: ".length($msg)); Log3slog ($hash, 5, "Log2Syslog $name -> LENGTH_MSG$i: ".length($msg));
Log3slog ($hash, 5, "Log2Syslog $name -> TAIL$i : $tail"); Log3slog ($hash, 5, "Log2Syslog $name -> TAIL$i : $tail");
} }
}
} else { else {
@load = split("[\r\n]",$data); if($uef) {
push @load, $data;
}
else {
@load = split("[\r\n]",$data);
}
} }
for my $line (@load) { for my $line (@load) {
@ -622,17 +636,21 @@ sub Read { ## no critic 'comple
$pen++; $pen++;
readingsSingleUpdate($hash, 'Parse_Err_No', $pen, 1); readingsSingleUpdate($hash, 'Parse_Err_No', $pen, 1);
$st = "parse error - see logfile"; $st = "parse error - see logfile";
} elsif ($ignore) { }
elsif ($ignore) {
Log3slog ($hash, 5, "Log2Syslog $name -> dataset was ignored by parseFn"); Log3slog ($hash, 5, "Log2Syslog $name -> dataset was ignored by parseFn");
} else { }
else {
return if($sevevt && $sevevt !~ m/$sev/x); # Message nicht berücksichtigen return if($sevevt && $sevevt !~ m/$sev/x); # Message nicht berücksichtigen
$st = "active"; $st = "active";
if($mevt =~ /intern/) { # kein Reading, nur Event if($mevt =~ /intern/) { # kein Reading, nur Event
$pl = "$phost: $pl"; $pl = "$phost: $pl";
Trigger($hash,$ts,$pl); Trigger($hash,$ts,$pl);
} elsif ($mevt =~ /reading/x) { # Reading, Event abhängig von event-on-.* }
elsif ($mevt =~ /reading/x) { # Reading, Event abhängig von event-on-.*
readingsSingleUpdate($hash, "MSG_$phost", $pl, 1); readingsSingleUpdate($hash, "MSG_$phost", $pl, 1);
} else { # Reading ohne Event }
else { # Reading ohne Event
readingsSingleUpdate($hash, "MSG_$phost", $pl, 0); readingsSingleUpdate($hash, "MSG_$phost", $pl, 0);
} }
} }
@ -664,12 +682,15 @@ return;
# (sSiehe auch "list TYPE=FHEMWEB", bzw. "man -s2 accept") # (sSiehe auch "list TYPE=FHEMWEB", bzw. "man -s2 accept")
# #
############################################################################### ###############################################################################
sub getIfData { ## no critic 'complexity' sub getIfData { ## no critic 'complexity'
my ($hash,$len,$mlen,$reread) = @_; my $hash = shift;
my $name = $hash->{NAME}; my $len = shift;
my $socket = $hash->{SERVERSOCKET}; my $mlen = shift;
my $protocol = lc(AttrVal($name, "protocol", "udp")); my $reread = shift;
my ($eof,$buforun) = (0,0); my $name = $hash->{NAME};
my $socket = $hash->{SERVERSOCKET};
my $protocol = lc(AttrVal($name, "protocol", "udp"));
my ($eof,$buforun) = (0,0);
if($hash->{TEMPORARY}) { if($hash->{TEMPORARY}) {
# temporäre Instanz abgelegt durch TcpServer_Accept # temporäre Instanz abgelegt durch TcpServer_Accept
@ -689,7 +710,8 @@ sub getIfData { ## no critic
Log3slog ($hash, 3, "Log2Syslog $name - Seq \"$hash->{SEQNO}\" invalid data: $data"); Log3slog ($hash, 3, "Log2Syslog $name - Seq \"$hash->{SEQNO}\" invalid data: $data");
$data = '' if(length($data) == 0); $data = '' if(length($data) == 0);
$st = "receive error - see logfile"; $st = "receive error - see logfile";
} else { }
else {
my $dl = length($data); my $dl = length($data);
Log3slog ($hash, 5, "Log2Syslog $name - Buffer ".$dl." chars ready to parse:\n$data"); Log3slog ($hash, 5, "Log2Syslog $name - Buffer ".$dl." chars ready to parse:\n$data");
} }
@ -728,21 +750,22 @@ sub getIfData { ## no critic
$shash->{HELPER}{TCPPADDR} = $hash->{PEER}; $shash->{HELPER}{TCPPADDR} = $hash->{PEER};
my $buf; my $buf;
my $off = 0; my $off = 0;
$ret = sysread($c, $buf, $len); # returns undef on error, 0 at end of file and Integer, number of bytes read on success. $ret = sysread($c, $buf, $len); # returns undef on error, 0 at end of file and Integer, number of bytes read on success.
if(!defined($ret) && $! == EWOULDBLOCK()){ # error if(!defined($ret) && $! == EWOULDBLOCK()){ # error
$hash->{wantWrite} = 1 if(TcpServer_WantWrite($hash)); $hash->{wantWrite} = 1 if(TcpServer_WantWrite($hash));
$hash = $shash; $hash = $shash;
Log3slog ($hash, 2, "Log2Syslog $sname - ERROR - TCP stack error: $!"); Log3slog ($hash, 2, "Log2Syslog $sname - ERROR - TCP stack error: $!");
return ($st,undef,$hash); return ($st,undef,$hash);
}
} elsif (!$ret) { # EOF or error elsif (!$ret) { # EOF or error
Log3slog ($shash, 4, "Log2Syslog $sname - Connection closed for $cname: ".(defined($ret) ? 'EOF' : $!)); Log3slog ($shash, 4, "Log2Syslog $sname - Connection closed for $cname: ".(defined($ret) ? 'EOF' : $!));
if(!defined($ret)) { # error if(!defined($ret)) { # error
CommandDelete(undef, $cname); CommandDelete(undef, $cname);
$hash = $shash; $hash = $shash;
return ($st,undef,$hash); return ($st,undef,$hash);
} else { # EOF }
else { # EOF
$eof = 1; $eof = 1;
$data = $hash->{BUF}; $data = $hash->{BUF};
CommandDelete(undef, $cname); CommandDelete(undef, $cname);
@ -3231,7 +3254,8 @@ $CONT = (split(">",$CONT))[1] if($CONT =~ /^<.*>.*$/);
After every transmission the TCP-connection will be terminated with signal EOF. <br><br> After every transmission the TCP-connection will be terminated with signal EOF. <br><br>
<b>Model Collector: </b><br> <b>Model Collector: </b><br>
No parsing until the sender has send an EOF signal. If TLS is used, this attribute has no effect. No parsing until the sender has send an EOF signal. CRLF is not considered as data separator.
If not set, CRLF will be considered as a record separator.
<br> <br>
<br> <br>
@ -4005,8 +4029,8 @@ $CONT = (split(">",$CONT))[1] if($CONT =~ /^<.*>.*$/);
Nach jedem Sendevorgang wird eine TCP-Verbindung mit EOF beendet. <br><br> Nach jedem Sendevorgang wird eine TCP-Verbindung mit EOF beendet. <br><br>
<b>Model Collector: </b><br> <b>Model Collector: </b><br>
Es wird mit dem Parsing gewartet, bis der Sender ein EOF Signal gesendet hat. Wird TLS verwendet, hat dieses Attribut Es wird mit dem Parsing gewartet, bis der Sender ein EOF Signal gesendet hat. CRLF wird nicht als Datentrenner
keine Auswirkung. berücksichtigt. Wenn nicht gesetzt, wird CRLF als Trennung von Datensätzen gewertet.
<br> <br>
<br> <br>