Skip to content

Commit

Permalink
Make sure our program name is valid for syslog
Browse files Browse the repository at this point in the history
Convert a ":", " " and brackets to a dash.
  • Loading branch information
eric committed May 3, 2012
1 parent 9f9a242 commit 306ec8f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/remote_syslog/reader.rb
Expand Up @@ -42,12 +42,16 @@ def initialize(path, destination_address, destination_port, options = {})
@packet.facility = options[:facility] || 'user'
@packet.severity = options[:severity] || 'notice'

tag = options[:program] || File.basename(path) || File.basename($0)
tag = options[:program] || File.basename(path) || File.basename($0)

# Remove characters that can't be in a tag
tag = tag.gsub(%r{[: \]\[\\]+}, '-')

# Make sure the tag isn't too long
if tag.length > 32
tag = tag[0..31]
end

@packet.tag = tag
end

Expand Down

0 comments on commit 306ec8f

Please sign in to comment.