diff --git a/Gemfile b/Gemfile index e45e65f..fa75df1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,3 @@ -source :rubygems +source 'https://rubygems.org' + gemspec diff --git a/Rakefile b/Rakefile index d4f7da8..5c38b7c 100644 --- a/Rakefile +++ b/Rakefile @@ -60,7 +60,7 @@ task :coverage do sh "open coverage/index.html" end -require 'rake/rdoctask' +require 'rdoc/task' Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "#{name} #{version}" diff --git a/lib/syslog_protocol/parser.rb b/lib/syslog_protocol/parser.rb index a5f7db1..2195bc4 100644 --- a/lib/syslog_protocol/parser.rb +++ b/lib/syslog_protocol/parser.rb @@ -1,7 +1,7 @@ require 'time' module SyslogProtocol - + def self.parse(msg, origin=nil) packet = Packet.new original_msg = msg.dup @@ -33,9 +33,9 @@ def self.parse(msg, origin=nil) end packet end - + private - + def self.parse_pri(msg) pri = msg.slice!(/<(\d\d?\d?)>/) pri = pri.slice(/\d\d?\d?/) if pri @@ -45,13 +45,12 @@ def self.parse_pri(msg) return pri end end - + def self.parse_time(msg) msg.slice!(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\s|[1-9])\d\s\d\d:\d\d:\d\d\s/) end - + def self.parse_hostname(msg) - msg.slice!(/^[\x21-\x7E]+\s/).rstrip + msg.slice!(/^\s*[\x21-\x7E]+\s/).strip end - -end \ No newline at end of file +end diff --git a/test/test_parser.rb b/test/test_parser.rb index a03b5e6..a50befa 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -22,6 +22,17 @@ p.time.should.equal Time.parse("Feb 5 17:32:18") end + it "parse packet with space between date and pri" do + p = SyslogProtocol.parse("<14> Jun 15 14:25:39 127.0.0.1 mgr: SME TELNET from 127.0.0.1 - MANAGER Mode") + p.facility.should.equal 1 + p.severity.should.equal 6 + p.pri.should.equal 14 + p.hostname.should.equal "127.0.0.1" + p.tag.should.equal 'mgr' + p.content.should.equal " SME TELNET from 127.0.0.1 - MANAGER Mode" + p.time.should.equal Time.parse("Jun 15 14:25:39") + end + it "treat a packet with no valid PRI as all content, setting defaults" do p = SyslogProtocol.parse("nomnom") p.facility.should.equal 1