mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
93_Log2Syslog.pm: version 2.2.0
git-svn-id: https://svn.fhem.de/fhem/trunk@14916 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
bbd26f65ee
commit
08acf01875
@ -22,11 +22,14 @@
|
|||||||
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# The module based on idea and input from betateilchen 92_rsyslog.pm
|
# The module based on idea and input from betateilchen 92_rsyslog.pm
|
||||||
# Implements the Syslog Protocol of RFC 5424 (https://tools.ietf.org/html/rfc5424)
|
# Implements the Syslog Protocol of RFC 5424 https://tools.ietf.org/html/rfc5424
|
||||||
|
# and RFC 3164 https://tools.ietf.org/html/rfc3164
|
||||||
#
|
#
|
||||||
#######################################################################################################
|
#######################################################################################################
|
||||||
# Versions History:
|
# Versions History:
|
||||||
#
|
#
|
||||||
|
# 2.2.0 17.08.2017 set BSD data length, set only acceptable characters (USASCII) in payload
|
||||||
|
# commandref revised
|
||||||
# 2.1.0 17.08.2017 sub setsock created
|
# 2.1.0 17.08.2017 sub setsock created
|
||||||
# 2.0.0 16.08.2017 create syslog without SYS::SYSLOG
|
# 2.0.0 16.08.2017 create syslog without SYS::SYSLOG
|
||||||
# 1.1.1 13.08.2017 registrate fhemlog_log to %loginform in case of sending fhem-log
|
# 1.1.1 13.08.2017 registrate fhemlog_log to %loginform in case of sending fhem-log
|
||||||
@ -41,7 +44,7 @@ use warnings;
|
|||||||
eval "use IO::Socket::INET;1" or my $MissModulSocket = "IO::Socket::INET";
|
eval "use IO::Socket::INET;1" or my $MissModulSocket = "IO::Socket::INET";
|
||||||
eval "use Net::Domain qw(hostfqdn);1" or my $MissModulNDom = "Net::Domain";
|
eval "use Net::Domain qw(hostfqdn);1" or my $MissModulNDom = "Net::Domain";
|
||||||
|
|
||||||
my $Log2SyslogVn = "2.0.0";
|
my $Log2SyslogVn = "2.2.0";
|
||||||
|
|
||||||
# Mappinghash BSD-Formatierung Monat
|
# Mappinghash BSD-Formatierung Monat
|
||||||
my %Log2Syslog_BSDMonth = (
|
my %Log2Syslog_BSDMonth = (
|
||||||
@ -59,6 +62,11 @@ my %Log2Syslog_BSDMonth = (
|
|||||||
"12" => "Dec"
|
"12" => "Dec"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Längenvorgaben nach RFC3164
|
||||||
|
my %RFC3164len = ("TAG" => 32, # max. Länge TAG-Feld
|
||||||
|
"DL" => 1024 # max. Lange Message insgesamt
|
||||||
|
);
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub Log2Syslog_Initialize($) {
|
sub Log2Syslog_Initialize($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
@ -172,7 +180,6 @@ sub event_Log($$) {
|
|||||||
my ($hash,$dev) = @_;
|
my ($hash,$dev) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $rex = $hash->{HELPER}{EVNTLOG};
|
my $rex = $hash->{HELPER}{EVNTLOG};
|
||||||
my $sock = $hash->{HELPER}{SOCK};
|
|
||||||
my ($prival,$sock);
|
my ($prival,$sock);
|
||||||
|
|
||||||
return if(IsDisabled($name) || !$rex);
|
return if(IsDisabled($name) || !$rex);
|
||||||
@ -187,12 +194,13 @@ sub event_Log($$) {
|
|||||||
for (my $i = 0; $i < $max; $i++) {
|
for (my $i = 0; $i < $max; $i++) {
|
||||||
my $s = $events->[$i];
|
my $s = $events->[$i];
|
||||||
$s = "" if(!defined($s));
|
$s = "" if(!defined($s));
|
||||||
|
$s =~ tr/ A-Za-z0-9!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~//cd; # nur erlaubte Zeichen in payload, ASCII %d32-126
|
||||||
|
|
||||||
my $tim = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
|
my $tim = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
|
||||||
my ($date,$time) = split(" ",$tim);
|
my ($date,$time) = split(" ",$tim);
|
||||||
|
|
||||||
if($n =~ m/^$rex$/ || "$n:$s" =~ m/^$rex$/ || "$tim:$n:$s" =~ m/^$rex$/) {
|
if($n =~ m/^$rex$/ || "$n:$s" =~ m/^$rex$/ || "$tim:$n:$s" =~ m/^$rex$/) {
|
||||||
my $otp = "$n -> $s";
|
my $otp = "$n $s";
|
||||||
$otp = "$tim $otp" if AttrVal($name,'addTimestamp',0);
|
$otp = "$tim $otp" if AttrVal($name,'addTimestamp',0);
|
||||||
$prival = setprival($s);
|
$prival = setprival($s);
|
||||||
|
|
||||||
@ -216,14 +224,15 @@ sub fhemlog_Log($$) {
|
|||||||
my ($name,$raw) = @_;
|
my ($name,$raw) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
my $rex = $hash->{HELPER}{FHEMLOG};
|
my $rex = $hash->{HELPER}{FHEMLOG};
|
||||||
my $sock = $hash->{HELPER}{SOCK};
|
|
||||||
my ($prival,$sock);
|
my ($prival,$sock);
|
||||||
|
|
||||||
return if(IsDisabled($name) || !$rex);
|
return if(IsDisabled($name) || !$rex);
|
||||||
|
|
||||||
my ($date,$time,$vbose,undef,$text) = split(" ",$raw,5);
|
my ($date,$time,$vbose,undef,$text) = split(" ",$raw,5);
|
||||||
|
$text =~ tr/ A-Za-z0-9!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~//cd; # nur erlaubte Zeichen in payload, ASCII %d32-126
|
||||||
$date =~ s/\./-/g;
|
$date =~ s/\./-/g;
|
||||||
my $tim = $date." ".$time;
|
my $tim = $date." ".$time;
|
||||||
|
|
||||||
if($text =~ m/^$rex$/ || "$vbose: $text" =~ m/^$rex$/) {
|
if($text =~ m/^$rex$/ || "$vbose: $text" =~ m/^$rex$/) {
|
||||||
my $otp = "$vbose: $text";
|
my $otp = "$vbose: $text";
|
||||||
$otp = "$tim $otp" if AttrVal($name,'addTimestamp',0);
|
$otp = "$tim $otp" if AttrVal($name,'addTimestamp',0);
|
||||||
@ -237,8 +246,7 @@ sub fhemlog_Log($$) {
|
|||||||
$sock->close();
|
$sock->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -322,16 +330,18 @@ sub setpayload ($$$$$$) {
|
|||||||
$time = (split(".",$time))[0]; # msec ist nicht erlaubt
|
$time = (split(".",$time))[0]; # msec ist nicht erlaubt
|
||||||
$month = $Log2Syslog_BSDMonth{$month}; # Monatsmapping z.B. 01 -> Jan
|
$month = $Log2Syslog_BSDMonth{$month}; # Monatsmapping z.B. 01 -> Jan
|
||||||
$day =~ s/0/ /; # in Tagen < 10 muss 0 durch Space ersetzt werden
|
$day =~ s/0/ /; # in Tagen < 10 muss 0 durch Space ersetzt werden
|
||||||
|
$ident = substr($ident,0, $RFC3164len{TAG}); # Länge TAG Feld begrenzen
|
||||||
no warnings 'uninitialized';
|
no warnings 'uninitialized';
|
||||||
$data = "<$prival>$month $day $time $myhost $ident :$otp";
|
$data = "<$prival>$month $day $time $myhost TAG$ident: $otp";
|
||||||
use warnings;
|
use warnings;
|
||||||
|
$data = substr($data,0, $RFC3164len{DL}); # Länge Total begrenzen
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lf eq "IETF") {
|
if ($lf eq "IETF") {
|
||||||
# IETF Protokollformat https://tools.ietf.org/html/rfc5424
|
# IETF Protokollformat https://tools.ietf.org/html/rfc5424
|
||||||
my $pid = $hash->{HELPER}{PID};
|
my $pid = $hash->{HELPER}{PID};
|
||||||
my $mid = "FHEM"; # message ID, identify type of message, e.g. for firewalls
|
my $mid = "FHEM"; # message ID, identify type of message, e.g. for firewalls
|
||||||
my $tim = $date."T".$time."Z";
|
my $tim = $date."T".$time;
|
||||||
no warnings 'uninitialized';
|
no warnings 'uninitialized';
|
||||||
$data = "<$prival>1 $tim $myhost $ident $pid $mid - :$otp";
|
$data = "<$prival>1 $tim $myhost $ident $pid $mid - :$otp";
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -378,8 +388,6 @@ return($data);
|
|||||||
After definition the new device sends all new appearing fhem systemlog entries and events to the destination host,
|
After definition the new device sends all new appearing fhem systemlog entries and events to the destination host,
|
||||||
port=514/UDP format:IETF, immediately without further settings if the regex for fhem or event were set. <br>
|
port=514/UDP format:IETF, immediately without further settings if the regex for fhem or event were set. <br>
|
||||||
Without setting regex no fhem system log or event log will be forwarded. <br>
|
Without setting regex no fhem system log or event log will be forwarded. <br>
|
||||||
The module uses functions of Perls SYS::SYSLOG module. If you want know more, see for detailed descriptions
|
|
||||||
on <a href="http://perldoc.perl.org/Sys/Syslog.html">perldoc</a>. <br>
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Example to log anything: <br>
|
Example to log anything: <br>
|
||||||
@ -423,6 +431,8 @@ Mar 20 15:47:53 fhem-vm-8 fhem: 2016-03-20_15:47:53 global: INITIALIZED</pre>
|
|||||||
<br>
|
<br>
|
||||||
Set the syslog protocol format. <br>
|
Set the syslog protocol format. <br>
|
||||||
Default value is "IETF" if not specified.
|
Default value is "IETF" if not specified.
|
||||||
|
The implemented BSD protocol is defined in <a href="https://tools.ietf.org/html/rfc3164"> RFC3164 </a> and the
|
||||||
|
IETF protocol can be found in <a href="https://tools.ietf.org/html/rfc5424"> RFC5424 </a>
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<li><code>type [TCP|UDP]</code><br>
|
<li><code>type [TCP|UDP]</code><br>
|
||||||
@ -476,8 +486,6 @@ Mar 20 15:47:53 fhem-vm-8 fhem: 2016-03-20_15:47:53 global: INITIALIZED</pre>
|
|||||||
Direkt nach der Definition sendet das neue Device alle neu auftretenden FHEM Systemlog Einträge und Events ohne weitere
|
Direkt nach der Definition sendet das neue Device alle neu auftretenden FHEM Systemlog Einträge und Events ohne weitere
|
||||||
Einstellungen an den Zielhost, Port=514/UDP Format:IETF, wenn reguläre Ausdrücke für Events/FHEM angegeben wurden. <br>
|
Einstellungen an den Zielhost, Port=514/UDP Format:IETF, wenn reguläre Ausdrücke für Events/FHEM angegeben wurden. <br>
|
||||||
Wurde kein Regex gesetzt, erfolgt keine Weiterleitung von Events oder FHEM Systemlogs. <br>
|
Wurde kein Regex gesetzt, erfolgt keine Weiterleitung von Events oder FHEM Systemlogs. <br>
|
||||||
Das Modul verwendet Funktionen des Perl-Moduls SYS::SYSLOG. Weitere Informationen dazu sind auf
|
|
||||||
<a href="http://perldoc.perl.org/Sys/Syslog.html">perldoc</a> zu finden. <br>
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Beispiel:<br/>
|
Beispiel:<br/>
|
||||||
@ -522,7 +530,9 @@ Mar 20 15:47:53 fhem-vm-8 fhem: 2016-03-20_15:47:53 global: INITIALIZED</pre>
|
|||||||
<li><code>logFormat [BSD|IETF]</code><br>
|
<li><code>logFormat [BSD|IETF]</code><br>
|
||||||
<br>
|
<br>
|
||||||
Stellt das Protokollformat ein. <br>
|
Stellt das Protokollformat ein. <br>
|
||||||
Der Standardwert ist "IETF".
|
Der Standardwert ist "IETF". <br>
|
||||||
|
Das implementierte BSD Protokoll ist definiert in <a href="https://tools.ietf.org/html/rfc3164"> RFC3164 </a>. Das
|
||||||
|
weiterentwickelte IETF-Protokoll kann hier <a href="https://tools.ietf.org/html/rfc5424"> RFC5424 </a> nachgelesen werden.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<li><code>type [TCP|UDP]</code><br>
|
<li><code>type [TCP|UDP]</code><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user