diff --git a/contrib/DS_Starter/93_Log2Syslog.pm b/contrib/DS_Starter/93_Log2Syslog.pm index 91c247c25..970e79a25 100644 --- a/contrib/DS_Starter/93_Log2Syslog.pm +++ b/contrib/DS_Starter/93_Log2Syslog.pm @@ -1,5 +1,5 @@ ########################################################################################################################## -# $Id: 93_Log2Syslog.pm 21567 2020-03-31 20:03:58Z DS_Starter $ +# $Id: 93_Log2Syslog.pm 21582 2020-04-02 20:59:26Z DS_Starter $ ########################################################################################################################## # 93_Log2Syslog.pm # @@ -21,9 +21,13 @@ # You should have received a copy of the GNU General Public License # along with fhem. If not, see . # -# Implements the Syslog Protocol of RFC 5424 https://tools.ietf.org/html/rfc5424 -# and RFC 3164 https://tools.ietf.org/html/rfc3164 and -# TLS Transport according to RFC5425 https://tools.ietf.org/pdf/rfc5425.pdf as well +# The module is inspired by 92_rsyslog.pm (betateilchen) +# +# Implements the Syslog Protocol according to RFCs: +# RFC 5424 https://tools.ietf.org/html/rfc5424 +# RFC 3164 https://tools.ietf.org/html/rfc3164 and +# TLS Transport according to RFC 5425 https://tools.ietf.org/pdf/rfc5425.pdf +# Date and Time according to RFC 3339 https://tools.ietf.org/html/rfc3339 # ########################################################################################################################## package main; @@ -39,6 +43,7 @@ eval "use FHEM::Meta;1" or my $mod # Versions History intern: our %Log2Syslog_vNotesIntern = ( + "5.10.0" => "04.04.2020 new attribute 'timeSpec', send and parse messages according to UTC or Local time, minor fixes ", "5.9.0" => "01.04.2020 Parser UniFi Controller Syslog (BSD Format) and Netconsole messages, more code review (e.g. remove prototypes) ", "5.8.3" => "31.03.2020 fix warning uninitialized value \$pp in pattern match (m//) at line 465, Forum: topic,75426.msg1036553.html#msg1036553, some code review ", "5.8.2" => "28.07.2019 fix warning uninitialized value in numeric ge (>=) at line 662 ", @@ -107,6 +112,8 @@ our %Log2Syslog_vNotesIntern = ( # Versions History extern: our %Log2Syslog_vNotesExtern = ( + "5.10.0" => "04.04.2020 The new attribute 'timeSpec' can be set to send and receive/parse messages according to UTC or Local time format. ". + "Please refer to Date and Time on the Internet: Timestamps for further information ", "5.9.0" => "01.04.2020 The new option \"UniFi\" of attribute \"parseProfil\" provedes a new Parser for UniFi Controller Syslog messages ". "and Netconsole messages. It was tested with UniFi AP-AC-Lite but should run with all Unifi products. ", "5.8.1" => "23.07.2019 New attribute \"useParsefilter\" to remove other characters than ASCII from payload before parse it. ". @@ -286,6 +293,7 @@ sub Log2Syslog_Initialize { "sslCertPrefix ". "TLS:1,0 ". "timeout ". + "timeSpec:Local,UTC ". "useParsefilter:0,1 ". "useEOF:1,0 ". $readingFnAttributes @@ -314,7 +322,9 @@ sub Log2Syslog_Define { $hash->{MYHOST} = hostname(); # eigener Host (lt. RFC nur Hostname f. BSD) my $myfqdn = hostfqdn(); # MYFQDN eigener Host (f. IETF) - $hash->{MYFQDN} = $myfqdn?$myfqdn:$hash->{MYHOST}; + $myfqdn =~ s/\.$//x if($myfqdn); + + $hash->{MYFQDN} = $myfqdn // $hash->{MYHOST}; if(int(@a)-3 < 0){ # Einrichtung Servermode (Collector) @@ -485,8 +495,7 @@ sub Log2Syslog_Read { if($data) { # parse Payload my (@load,$mlen,$msg,$tail); - if($data =~ /^(?(\d+))\s(?.*)/s) { - # Syslog Sätze mit Octet Count -> Transmission of Syslog Messages over TCP https://tools.ietf.org/html/rfc6587 + if($data =~ /^(?(\d+))\s(?.*)/s) { # Syslog Sätze mit Octet Count -> Transmission of Syslog Messages over TCP https://tools.ietf.org/html/rfc6587 my $i = 0; $mlen = $+{mlen}; $tail = $+{tail}; @@ -503,6 +512,7 @@ sub Log2Syslog_Read { $msg = substr($tail,0,$mlen); chomp $msg; push @load, $msg; + next if(!$tail); $tail = substr($tail,$mlen); Log2Syslog_Log3slog ($hash, 5, "Log2Syslog $name -> LEN$i: $mlen, MSG$i: $msg, TAIL$i: $tail"); } @@ -510,7 +520,8 @@ sub Log2Syslog_Read { @load = split("[\r\n]",$data); } - for my $line (@load) { + for my $line (@load) { + next if(!$line); ($err,$ignore,$sev,$phost,$ts,$pl) = Log2Syslog_parsePayload($hash,$line); $hash->{SEQNO}++; if($err) { @@ -705,7 +716,7 @@ sub Log2Syslog_parsePayload { my $facility = ""; my @evf = split(",",AttrVal($name, "outputFields", "FAC,SEV,ID,CONT")); # auszugebene Felder im Event/Reading my $ignore = 0; - my ($Mmm,$dd,$day,$ietf,$err,$pl,$tail); + my ($to,$Mmm,$dd,$day,$ietf,$err,$pl,$tail); $data = Log2Syslog_parsefilter($data) if(AttrVal($name,"useParsefilter",0)); # Steuerzeichen werden entfernt (Achtung auch CR/LF) @@ -842,11 +853,12 @@ sub Log2Syslog_parsePayload { if($prival && $ietf) { # Standard IETF-Syslog incl. VERSION if($ietf == 1) { - $data =~ /^<(?\d{1,3})>(?\d{0,2})\s?(?\d{4}-\d{2}-\d{2})T(?