2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

92_rsyslog.pm:

error handling on multiple definitions,
attribute rsl_timestamp added,
commandref added

git-svn-id: https://svn.fhem.de/fhem/trunk@11101 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2016-03-20 15:00:59 +00:00
parent 56a9ce2ef5
commit f5b0015f2b

View File

@ -20,6 +20,7 @@ sub rsyslog_Initialize($) {
my @attrList = qw(
disable:0,1
disabledForIntervals
rsl_timestamp:0,1
);
use warnings 'qw';
$hash->{AttrList} = join(" ", @attrList);
@ -30,6 +31,9 @@ sub rsyslog_Initialize($) {
sub rsyslog_Define($@) {
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
return "You must not define more than one rsyslog device!" if int(devspec2array('TYPE=rsyslog')) > 1;
return "wrong syntax: define <name> rsyslog <ident> <logopt> <facility> <regexp>"
if(int(@a) != 6);
@ -39,16 +43,18 @@ sub rsyslog_Define($@) {
openlog($a[2],$a[3],$a[4]);
# $hash->{ident} = $a[2];
# $hash->{logopt} = $a[3];
# $hash->{facility} = $a[4];
$hash->{REGEXP} = $a[5];
$hash->{STATE} = "active";
notifyRegexpChanged($hash, $a[5]);
# notifyRegexpChanged($hash, $a[5]);
return undef;
}
sub rsyslog_Undef($$) {
closelog();
return undef;
}
sub rsyslog_Log($$) {
my ($log, $dev) = @_;
@ -69,15 +75,71 @@ sub rsyslog_Log($$) {
my $t = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/ || "$t:$n:$s" =~ m/^$re$/) {
$t =~ s/ /_/;
syslog("info","$n: $s") if defined &syslog;
my $output = "$n: $s";
$output = "$t $output" if AttrVal($ln,'rsl_timestamp',0);
syslog("info",$output) if defined &syslog;
}
}
return "";
}
sub rsyslog_Undef($$) {
closelog();
return undef;
}
1;
=pod
=item helper
=begin html
<a name="rsyslog"></a>
<h3>rsyslog</h3>
<ul>
Log fhem events to local syslog instance.<br/>
<br/>
<b>Prerequisits</b>
<ul>
<br/>
Additional perl module Sys::Syslog must be installed on your system. Install this package from cpan or <br/>
by <code>apt-get install libsys-syslog-perl</code> (only on Debian based installations)<br/>
</ul>
<br/>
<a name="rsyslogdefine"></a>
<b>Define</b>
<ul>
<br/>
<code>define &lt;name&gt; rsyslog &lt;ident&gt; &lt;logopt&gt; &lt;facility&gt; &lt;regexp&gt;</code><br/>
<br/>
Detailed descriptions of parameters ident, logopt, facility can be found on <a href="http://perldoc.perl.org/Sys/Syslog.html">perldoc</a><br/>
<br/>
Example to log anything:<br/>
<br/>
<code>define rsl rsyslog fhem ndelay local0 .* </code><br/>
<br/>
will produce output like:<br/>
<pre>Mar 20 15:25:22 fhem-vm-8 fhem: global: SAVE
Mar 20 15:25:44 fhem-vm-8 fhem: global: SHUTDOWN
Mar 20 15:25:57 fhem-vm-8 fhem: global: INITIALIZED
Mar 20 15:26:05 fhem-vm-8 fhem: PegelCux: Niedrigwasser-1: 20.03.2016 18:03
Mar 20 15:26:05 fhem-vm-8 fhem: PegelCux: Hochwasser-1: 20.03.2016 23:45</pre>
</ul>
<br/>
<a name="rsyslogattr"></a>
<b>Attributes</b>
<ul>
<br/>
<a name="rsl_timestamp"></a>
<li><code>rsl_timestamp</code><br>
<br/>
If set to 1, fhem timestamps will be looged, too.<br/>
Default behavior is to not log these timestamps, because syslog uses own timestamps.<br/>
Maybe useful if mseclog is activated in fhem.<br/>
<br/>
Example output:<br/>
<pre>Mar 20 15:47:42 fhem-vm-8 fhem: 2016-03-20_15:47:42 global: SAVE
Mar 20 15:47:46 fhem-vm-8 fhem: 2016-03-20_15:47:46 global: SHUTDOWN
Mar 20 15:47:53 fhem-vm-8 fhem: 2016-03-20_15:47:53 global: INITIALIZED</pre>
</li><br>
</ul>
<br/>
</ul>
=end html