Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
15 changes: 7 additions & 8 deletions lib/syslog_protocol/parser.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'time'

module SyslogProtocol

def self.parse(msg, origin=nil)
packet = Packet.new
original_msg = msg.dup
Expand Down Expand Up @@ -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
Expand All @@ -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
end
11 changes: 11 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down