Skip Menu |
 

This queue is for tickets about the Net-Syslog CPAN distribution.

Report information
The Basics
Id: 46898
Status: resolved
Priority: 0/
Queue: Net-Syslog

People
Owner: Nobody in particular
Requestors: mjvincent [...] comcast.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Stricter RFC 3168 adherence INCLUDING PATCH!
Date: Fri, 12 Jun 2009 19:38:11 +0000 (UTC)
To: bug-Net-Syslog [...] rt.cpan.org
From: mjvincent [...] comcast.net
Download (untitled) / with headers
text/plain 5.1k
I've been using Net::Syslog (current version 0.03) to test a syslogd I wrote in Perl and found that the message format from Net::Syslog differed from other devices that sent syslog messages (they themselves didn't seem to adhere to a standard).  I read RFC 3168 and found there were some missing pieces in Net::Syslog easily remedied.  Also, previous bugs reported describe the missing "local7" facility. Using Activestate Perl v5.8.8 on Windows XP Pro SP3, I coded up some fixes: 1) The priority names were not standardized - easy fix to add the full names, keeping the existing abbreviations for backward compatability. 2) The facility names were not according to standard and some were missing.  Again, added missing ones, updated full standard names and kept existing ones for backward compatability. 3) Fixed minor issue when no arguments specified, the defaults were not set to what the POD says they were 4) Included new 'RFC3168' switch to send properly formatted RFC 3168 compliant syslog messages.  By default, the original Net::Syslog message format is sent (again, for backward compatability). 5) Minor updates to POD to document changes The following patch applies these fixes.  NOTE:  The following patch updates the version of Net::Syslog from 0.03 to 0.04. ----<CLIP HERE>---- --- Syslog.pm Mon Apr 27 13:18:10 2009 +++ Syslog.pm Fri Jun 12 15:22:49 2009 @@ -2,6 +2,7 @@    use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);  use IO::Socket; +use Sys::Hostname;    require Exporter;   @@ -12,35 +13,51 @@  @EXPORT = qw(     ); -$VERSION = '0.03'; +$VERSION = '0.04';      # Preloaded methods go here.    my %syslog_priorities=(   emerg   => 0, + emergency     => 0,   alert   => 1,   crit    => 2, + critical      => 2,   err     => 3, + error         => 3,   warning => 4,          notice  => 5,          info    => 6, +        informational => 6,   debug   => 7  );    my %syslog_facilities=(   kern => 0, + kernel    => 0,   user => 1,   mail => 2,   daemon => 3,  + system    => 3,   auth => 4, + security  => 4,   syslog => 5, + internal  => 5,   lpr => 6, + printer   => 6,   news  => 7,   uucp  => 8,   cron => 9, + clock     => 9,   authpriv=> 10, + security2 => 10,   ftp => 11, + FTP       => 11, + NTP       => 12, + audit     => 13, + alert     => 14, + clock2    => 15,   local0 => 16,   local1 => 17,   local2 => 18, @@ -48,8 +65,10 @@   local4 => 20,   local5 => 21,   local6 => 22, + local7    => 23  );   +my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);    sub new{    my $class = shift; @@ -59,7 +78,7 @@    }    my $self = { Name     => $name,                 Facility => 'local5', -               Priority => 'err', +               Priority => 'error',                 SyslogPort    => 514,                 SyslogHost    => '127.0.0.1'};    bless $self,$class; @@ -80,18 +99,21 @@    }      my $pid=$$; -  my $facility_i=$syslog_facilities{$local{Facility}}; -  my $priority_i=$syslog_priorities{$local{Priority}};  - -  if(!defined $facility_i){ -    $facility_i=21; -  } -  if(!defined $priority_i){ -    $priority_i=4; -  } +  my $facility_i = $syslog_facilities{$local{Facility}} || 21; +  my $priority_i = $syslog_priorities{$local{Priority}} || 3;       my $d=(($facility_i<<3)|($priority_i)); -  my $message = "<$d>$local{Name}\[$pid\]: $msg"; + +  my $host = inet_ntoa((gethostbyname(hostname))[4]); +  my @time = localtime(); +  my $ts   = $month[$time[4]] . " " . (($time[3] < 10)?(" " . $time[3]):$time[3]) . " " . (($time[2] < 10)?("0" . $time[2]):$time[2]) . ":" . (($time[1] < 10)?("0" . $time[1]):$time[1]) . ":" . (($time[0] < 10)?("0" . $time[0]):$time[0]); +  my $message = ''; + +  if ($local{rfc3164}) { +      $message = "<$d>$ts $host $local{Name}\[$pid\]: $msg" +  } else { +      $message = "<$d>$local{Name}\[$pid\]: $msg" +  }      my $sock=new IO::Socket::INET(PeerAddr => $local{SyslogHost},                          PeerPort => $local{SyslogPort}, @@ -133,18 +155,22 @@     Name  <calling script name>   Facility  local5 - Priority  err + Priority  error   SyslogPort     514   SyslogHost     127.0.0.1    Valid Facilities are: - kern, user, mail, daemon, auth, syslog, lpr, news, uucp, cron, - authpriv, ftp, local0, local1, local2, local3, local4, local5, local6 + kernel, user, mail, system, security, internal, printer, news, + uucp, clock, security2, FTP, NTP, audit, alert, clock2, local0, + local1, local2, local3, local4, local5, local6, local7    Valid Priorities are: - emerg, alert, crit, err, warning, notice, info, debug - + emergency, alert, critical, error, warning, notice, informational, +        debug   +Use: +        rfc3164 => 1 +to enable RFC 3164 messages including timestamp and hostname.    =head1 AUTHOR   ----<CLIP HERE>----
Resolved in v0.04, just submitted to CPAN. Thx


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.