mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
93_Log2Syslog: support time-secfrac of RFC 3339, minor fix
git-svn-id: https://svn.fhem.de/fhem/trunk@21614 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5134c6c502
commit
84d2ce6323
@ -1,5 +1,6 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- feature: 93_Log2Syslog: support time-secfrac of RFC 3339, minor fix
|
||||
- feature: 93_Log2Syslog: new attribute 'timeSpec', send and parse messages
|
||||
according to UTC or Local tiime,
|
||||
some code changes (e.g. for Octet count format msg)
|
||||
|
@ -44,6 +44,7 @@ eval "use FHEM::Meta;1" or my $mod
|
||||
|
||||
# Versions History intern:
|
||||
my %Log2Syslog_vNotesIntern = (
|
||||
"5.10.1" => "06.04.2020 support time-secfrac of RFC 3339, minor fix ",
|
||||
"5.10.0" => "04.04.2020 new attribute 'timeSpec', send and parse messages according to UTC or Local time, some minor fixes (e.g. for Octet Count) ",
|
||||
"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 ",
|
||||
@ -339,15 +340,14 @@ sub Log2Syslog_Define {
|
||||
|
||||
$hash->{MYFQDN} = $myfqdn // $hash->{MYHOST};
|
||||
|
||||
if(int(@a)-3 < 0){
|
||||
# Einrichtung Servermode (Collector)
|
||||
if(int(@a)-3 < 0){ # Einrichtung Servermode (Collector)
|
||||
$hash->{MODEL} = "Collector";
|
||||
$hash->{PROFILE} = "Automatic";
|
||||
readingsSingleUpdate ($hash, 'Parse_Err_No', 0, 1); # Fehlerzähler für Parse-Errors auf 0
|
||||
Log2Syslog_Log3slog ($hash, 3, "Log2Syslog $name - entering Syslog servermode ...");
|
||||
Log2Syslog_initServer("$name,global");
|
||||
} else {
|
||||
# Sendermode
|
||||
|
||||
} else { # Sendermode
|
||||
$hash->{MODEL} = "Sender";
|
||||
Log2Syslog_setidrex($hash,$a[3]) if($a[3]);
|
||||
Log2Syslog_setidrex($hash,$a[4]) if($a[4]);
|
||||
@ -408,6 +408,7 @@ sub Log2Syslog_initServer {
|
||||
InternalTimer(gettimeofday()+1, "Log2Syslog_initServer", "$name,$global", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
# Inititialisierung FHEM ist fertig -> Attribute geladen
|
||||
my $port = AttrVal($name, "TLS", 0)?AttrVal($name, "port", 6514):AttrVal($name, "port", 1514);
|
||||
my $protocol = lc(AttrVal($name, "protocol", "udp"));
|
||||
@ -445,7 +446,7 @@ sub Log2Syslog_initServer {
|
||||
$hash->{PROTOCOL} = $protocol;
|
||||
$hash->{SEQNO} = 1; # PROCID wird kontinuierlich pro empfangenen Datensatz hochgezählt
|
||||
$hash->{HELPER}{OLDSEQNO} = $hash->{SEQNO}; # Init Sequenznummer f. Ratenbestimmung
|
||||
$hash->{INTERFACE} = $lh?$lh:"global";
|
||||
$hash->{INTERFACE} = $lh // "global";
|
||||
|
||||
Log2Syslog_Log3slog ($hash, 3, "Log2Syslog $name - port $hash->{PORT}/$protocol opened for Syslog Collector on interface \"$hash->{INTERFACE}\"");
|
||||
readingsSingleUpdate ($hash, "state", "initialized", 1);
|
||||
@ -513,13 +514,13 @@ sub Log2Syslog_Read {
|
||||
my $i = 0;
|
||||
$ocount = $+{ocount};
|
||||
$tail = $+{tail};
|
||||
if(length($tail) >= $ocount) {
|
||||
$msg = substr($tail,0,$ocount);
|
||||
} else {
|
||||
$msg = $tail;
|
||||
}
|
||||
$msg = substr($tail,0,$ocount);
|
||||
push @load, $msg;
|
||||
$tail = substr($tail,$ocount);
|
||||
if(length($tail) >= $ocount) {
|
||||
$tail = substr($tail,$ocount);
|
||||
} else {
|
||||
$tail = "";
|
||||
}
|
||||
|
||||
Log2Syslog_Log3slog ($hash, 5, "Log2Syslog $name -> OCTETCOUNT$i: $ocount");
|
||||
Log2Syslog_Log3slog ($hash, 5, "Log2Syslog $name -> MSG$i : $msg");
|
||||
@ -746,8 +747,8 @@ sub Log2Syslog_parsePayload {
|
||||
|
||||
# Hash zur Umwandlung Felder in deren Variablen
|
||||
my ($prival,$ts,$host,$date,$time,$id,$pid,$mid,$sdfield,$cont);
|
||||
my $fac = "";
|
||||
my $sev = "";
|
||||
my ($fac,$sev,$msec) = ("","","");
|
||||
|
||||
my %fh = (PRIVAL => \$prival,
|
||||
FAC => \$fac,
|
||||
SEV => \$sev,
|
||||
@ -874,11 +875,12 @@ sub Log2Syslog_parsePayload {
|
||||
if($prival && $ietf) {
|
||||
# Standard IETF-Syslog incl. VERSION
|
||||
if($ietf == 1) {
|
||||
$data =~ /^<(?<prival>\d{1,3})>(?<ietf>\d{0,2})\s?(?<date>\d{4}-\d{2}-\d{2})T(?<time>\d{2}:\d{2}:\d{2})(?<to>\S*)?\s(?<host>\S*)\s(?<id>\S*)\s?(?<pid>\S*)\s?(?<mid>\S*)\s?(?<sdfield>(\[.*?(?!\\\]).\]|-))\s(?<cont>.*)$/;
|
||||
$data =~ /^<(?<prival>\d{1,3})>(?<ietf>\d{0,2})\s?(?<date>\d{4}-\d{2}-\d{2})T(?<time>\d{2}:\d{2}:\d{2})(?<msec>\.\d+)?(?<to>\S*)?\s(?<host>\S*)\s(?<id>\S*)\s?(?<pid>\S*)\s?(?<mid>\S*)\s?(?<sdfield>(\[.*?(?!\\\]).\]|-))\s(?<cont>.*)$/;
|
||||
$prival = $+{prival}; # must
|
||||
$ietf = $+{ietf}; # should
|
||||
$date = $+{date}; # must
|
||||
$time = $+{time}; # must
|
||||
$msec = $+{msec}; # can
|
||||
$to = $+{to}; # Time Offset (UTC etc.)
|
||||
$host = $+{host}; # should
|
||||
$id = $+{id}; # should
|
||||
@ -892,10 +894,11 @@ sub Log2Syslog_parsePayload {
|
||||
}
|
||||
} else {
|
||||
# IETF-Syslog ohne VERSION
|
||||
$data =~ /^<(?<prival>\d{1,3})>(?<date>\d{4}-\d{2}-\d{2})T(?<time>\d{2}:\d{2}:\d{2})(?<to>\S*)?\s(?<host>\S*)\s(?<id>\S*)\s?(?<pid>\S*)\s?(?<mid>\S*)\s?(?<sdfield>(\[.*?(?!\\\]).\]|-))?\s(?<cont>.*)$/;
|
||||
$data =~ /^<(?<prival>\d{1,3})>(?<date>\d{4}-\d{2}-\d{2})T(?<time>\d{2}:\d{2}:\d{2})(?<msec>\.\d+)?(?<to>\S*)?\s(?<host>\S*)\s(?<id>\S*)\s?(?<pid>\S*)\s?(?<mid>\S*)\s?(?<sdfield>(\[.*?(?!\\\]).\]|-))?\s(?<cont>.*)$/;
|
||||
$prival = $+{prival}; # must
|
||||
$date = $+{date}; # must
|
||||
$time = $+{time}; # must
|
||||
$msec = $+{msec}; # can
|
||||
$to = $+{to}; # Time Offset (UTC etc.)
|
||||
$host = $+{host}; # should
|
||||
$id = $+{id}; # should
|
||||
@ -910,7 +913,7 @@ sub Log2Syslog_parsePayload {
|
||||
Log2Syslog_Log3slog ($hash, 2, "Log2Syslog $name - ERROR parse msg -> $data");
|
||||
Log2Syslog_Log3slog ($hash, 5, "Log2Syslog $name - parsed fields -> PRI: ".($prival // '').", IETF: ".($ietf // '').", DATE: ".($date // '').", TIME: ".($time // '').", OFFSET: ".($to // '').", HOST: ".($host // '').", ID: ".($id // '').", PID: ".($pid // '').", MID: ".($mid // '').", SDFIELD: ".($sdfield // '').", CONT: ".($cont // ''));
|
||||
} else {
|
||||
$ts = Log2Syslog_getTimeFromOffset ($name,$to,$date,$time);
|
||||
$ts = Log2Syslog_getTimeFromOffset ($name,$to,$date,$time,$msec);
|
||||
#$ts = "$date $time";
|
||||
|
||||
if(looks_like_number($prival)) {
|
||||
@ -1145,7 +1148,7 @@ return ($err,$ignore,$sev,$phost,$ts,$pl);
|
||||
#
|
||||
################################################################
|
||||
sub Log2Syslog_getTimeFromOffset {
|
||||
my ($name,$to,$date,$time) = @_;
|
||||
my ($name,$to,$date,$time,$msec) = @_;
|
||||
|
||||
my $dt = "$date $time";
|
||||
return ($dt) if(!$to);
|
||||
@ -1162,7 +1165,8 @@ sub Log2Syslog_getTimeFromOffset {
|
||||
|
||||
my ($offset,$utc);
|
||||
my $localts = fhemTimeLocal($sec, $min, $hour, $mday, $month, $year);
|
||||
|
||||
$localts .= $msec if($msec && $msec =~ /^\.\d+/);
|
||||
|
||||
if($to =~ /Z/ && $tz ne "UTC") { # Zulu Time wurde geliefert -> Umrechnung auf Local
|
||||
$offset = fhemTzOffset($localts); # Offset zwischen Localtime und UTC
|
||||
$utc = $localts - $offset;
|
||||
@ -1514,7 +1518,7 @@ sub Log2Syslog_Attr {
|
||||
|
||||
if ($aName =~ /rateCalcRerun/) {
|
||||
unless ($aVal =~ /^[0-9]+$/) { return "Value of $aName is not valid. Use only figures 0-9 without decimal places !";}
|
||||
$_[3] = 60 if($aVal < 60);
|
||||
return qq{Value of "$aName" must be >= 60. Please correct it} if($aVal < 60);
|
||||
RemoveInternalTimer($hash, "Log2Syslog_trate");
|
||||
InternalTimer(gettimeofday()+5, "Log2Syslog_trate", $hash, 0);
|
||||
}
|
||||
@ -1552,9 +1556,8 @@ sub Log2Syslog_Attr {
|
||||
}
|
||||
|
||||
if ($cmd eq "set" && $aName =~ /parseFn/) {
|
||||
$_[3] = "{$aVal}" if($aVal !~ m/^\{.*\}$/s);
|
||||
$aVal = $_[3];
|
||||
my %specials = (
|
||||
return qq{The function syntax is wrong. "$aName" must be enclosed by "{...}".} if($aVal !~ m/^\{.*\}$/s);
|
||||
my %specials = (
|
||||
"%IGNORE" => "0",
|
||||
"%DATA" => "1",
|
||||
"%PRIVAL" => "1",
|
||||
@ -1569,9 +1572,9 @@ sub Log2Syslog_Attr {
|
||||
"%FAC" => "1",
|
||||
"%SDFIELD" => "1",
|
||||
"%SEV" => "1"
|
||||
);
|
||||
my $err = perlSyntaxCheck($aVal, %specials);
|
||||
return $err if($err);
|
||||
);
|
||||
my $err = perlSyntaxCheck($aVal, %specials);
|
||||
return $err if($err);
|
||||
}
|
||||
|
||||
if ($aName =~ /parseProfile/) {
|
||||
@ -1627,8 +1630,6 @@ sub Log2Syslog_eventlog {
|
||||
my ($prival,$data,$sock,$pid,$sevAstxt);
|
||||
|
||||
if(IsDisabled($name)) {
|
||||
# $st = AttrVal($name, "disable", "0");
|
||||
# $st = ($st =~ /maintenance/)?$st:"disabled";
|
||||
my $evt = ($st eq $hash->{HELPER}{OLDSTATE})?0:1;
|
||||
readingsSingleUpdate($hash, "state", $st, $evt);
|
||||
$hash->{HELPER}{OLDSTATE} = $st;
|
||||
@ -1704,8 +1705,6 @@ sub Log2Syslog_fhemlog {
|
||||
my ($prival,$sock,$err,$ret,$data,$pid,$sevAstxt);
|
||||
|
||||
if(IsDisabled($name)) {
|
||||
# $st = AttrVal($name, "disable", "1");
|
||||
# $st = ($st =~ /maintenance/)?$st:"disabled";
|
||||
my $evt = ($st eq $hash->{HELPER}{OLDSTATE})?0:1;
|
||||
readingsSingleUpdate($hash, "state", $st, $evt);
|
||||
$hash->{HELPER}{OLDSTATE} = $st;
|
||||
@ -2048,8 +2047,8 @@ sub Log2Syslog_setpayload {
|
||||
my ($hash,$prival,$date,$time,$otp,$lt) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $ident = ($hash->{HELPER}{IDENT}?$hash->{HELPER}{IDENT}:$name)."_".$lt;
|
||||
my $myhost = $hash->{MYHOST}?$hash->{MYHOST}:"0.0.0.0";
|
||||
my $myfqdn = $hash->{MYFQDN}?$hash->{MYFQDN}:$myhost;
|
||||
my $myhost = $hash->{MYHOST} // "0.0.0.0";
|
||||
my $myfqdn = $hash->{MYFQDN} // $myhost;
|
||||
my $lf = AttrVal($name, "logFormat", "IETF");
|
||||
my $cdl = AttrVal($name, "contDelimiter", ""); # Trennzeichen vor Content (z.B. für Synology nötig)
|
||||
my $data;
|
||||
@ -2818,7 +2817,7 @@ attr <name> exclErrCond Error: none,
|
||||
The following variables are commited to the function. They can be used for programming, processing and for
|
||||
value return. Variables which are provided as blank, are marked as "". <br>
|
||||
In case of restrictions the expected format of variables return is specified in "()".
|
||||
Otherwise the variable is usable for free.
|
||||
Otherwise the variable is usable for free. The function must be enclosed by { }.
|
||||
<br><br>
|
||||
|
||||
<ul>
|
||||
@ -2969,9 +2968,8 @@ $CONT = (split(">",$CONT))[1] if($CONT =~ /^<.*>.*$/);
|
||||
<a name="rateCalcRerun"></a>
|
||||
<li><b>rateCalcRerun <Zeit in Sekunden> </b><br>
|
||||
<br>
|
||||
Rerun cycle for calculation of log transfer rate (Reading "Transfered_logs_per_minute") in seconds (>=60).
|
||||
Values less than 60 seconds are corrected to 60 seconds automatically.
|
||||
Default is 60 seconds.
|
||||
Rerun cycle for calculation of log transfer rate (Reading "Transfered_logs_per_minute") in seconds (>=60).
|
||||
Default: 60 seconds.
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
@ -3589,7 +3587,7 @@ attr <name> exclErrCond Error: none,
|
||||
empfangene Syslog-Meldung angewendet. Der Funktion werden folgende Variablen übergeben die zur Verarbeitung
|
||||
und zur Werterückgabe genutzt werden können. Leer übergebene Variablen sind als "" gekennzeichnet. <br>
|
||||
Das erwartete Rückgabeformat einer Variable wird in "()" angegeben sofern sie Restriktionen unterliegt.
|
||||
Ansonsten ist die Variable frei verfügbar.
|
||||
Ansonsten ist die Variable frei verfügbar. Die Funktion ist in { } einzuschließen.
|
||||
<br><br>
|
||||
|
||||
<ul>
|
||||
@ -3741,9 +3739,8 @@ $CONT = (split(">",$CONT))[1] if($CONT =~ /^<.*>.*$/);
|
||||
<a name="rateCalcRerun"></a>
|
||||
<li><b>rateCalcRerun <Zeit in Sekunden> </b><br>
|
||||
<br>
|
||||
Wiederholungszyklus für die Bestimmung der Log-Transferrate (Reading "Transfered_logs_per_minute") in Sekunden (>=60).
|
||||
Eingegebene Werte <60 Sekunden werden automatisch auf 60 Sekunden korrigiert.
|
||||
Default sind 60 Sekunden.
|
||||
Wiederholungszyklus für die Bestimmung der Log-Transferrate (Reading "Transfered_logs_per_minute") in Sekunden (>=60).
|
||||
Default: 60 Sekunden.
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
@ -340,15 +340,14 @@ sub Log2Syslog_Define {
|
||||
|
||||
$hash->{MYFQDN} = $myfqdn // $hash->{MYHOST};
|
||||
|
||||
if(int(@a)-3 < 0){
|
||||
# Einrichtung Servermode (Collector)
|
||||
if(int(@a)-3 < 0){ # Einrichtung Servermode (Collector)
|
||||
$hash->{MODEL} = "Collector";
|
||||
$hash->{PROFILE} = "Automatic";
|
||||
readingsSingleUpdate ($hash, 'Parse_Err_No', 0, 1); # Fehlerzähler für Parse-Errors auf 0
|
||||
Log2Syslog_Log3slog ($hash, 3, "Log2Syslog $name - entering Syslog servermode ...");
|
||||
Log2Syslog_initServer("$name,global");
|
||||
} else {
|
||||
# Sendermode
|
||||
|
||||
} else { # Sendermode
|
||||
$hash->{MODEL} = "Sender";
|
||||
Log2Syslog_setidrex($hash,$a[3]) if($a[3]);
|
||||
Log2Syslog_setidrex($hash,$a[4]) if($a[4]);
|
||||
@ -409,6 +408,7 @@ sub Log2Syslog_initServer {
|
||||
InternalTimer(gettimeofday()+1, "Log2Syslog_initServer", "$name,$global", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
# Inititialisierung FHEM ist fertig -> Attribute geladen
|
||||
my $port = AttrVal($name, "TLS", 0)?AttrVal($name, "port", 6514):AttrVal($name, "port", 1514);
|
||||
my $protocol = lc(AttrVal($name, "protocol", "udp"));
|
||||
|
Loading…
Reference in New Issue
Block a user