Fixing relative path issues left over from flatjar era

Use plugin_path and pattern_path

closes 1377
This commit is contained in:
Aaron Mildenstein 2014-05-14 19:33:21 -05:00
parent d6b94edc5d
commit ab9985c26a
6 changed files with 24 additions and 25 deletions

View file

@ -45,7 +45,7 @@ class LogStash::Codecs::Netflow < LogStash::Codecs::Base
@templates = Vash.new() @templates = Vash.new()
# Path to default Netflow v9 field definitions # Path to default Netflow v9 field definitions
filename = File.join(File.dirname(__FILE__), "netflow/netflow.yaml") filename = LogStash::Environment.plugin_path("codecs/netflow/netflow.yaml")
begin begin
@fields = YAML.load_file(filename) @fields = YAML.load_file(filename)
@ -162,7 +162,7 @@ class LogStash::Codecs::Netflow < LogStash::Codecs::Base
# Purge any expired templates # Purge any expired templates
@templates.cleanup! @templates.cleanup!
end end
end end
when 256..65535 when 256..65535
# Data flowset # Data flowset
#key = "#{flowset.source_id}|#{event["source"]}|#{record.flowset_id}" #key = "#{flowset.source_id}|#{event["source"]}|#{record.flowset_id}"
@ -180,7 +180,7 @@ class LogStash::Codecs::Netflow < LogStash::Codecs::Base
# Template shouldn't be longer than the record and there should # Template shouldn't be longer than the record and there should
# be at most 3 padding bytes # be at most 3 padding bytes
if template.num_bytes > length or ! (length % template.num_bytes).between?(0, 3) if template.num_bytes > length or ! (length % template.num_bytes).between?(0, 3)
@logger.warn("Template length doesn't fit cleanly into flowset", :template_id => record.flowset_id, :template_length => template.num_bytes, :record_length => length) @logger.warn("Template length doesn't fit cleanly into flowset", :template_id => record.flowset_id, :template_length => template.num_bytes, :record_length => length)
next next
end end

View file

@ -31,5 +31,13 @@ module LogStash
def vendor_path(path) def vendor_path(path)
return ::File.join(LOGSTASH_HOME, "vendor", path) return ::File.join(LOGSTASH_HOME, "vendor", path)
end end
def plugin_path(path)
return ::File.join(LOGSTASH_HOME, "lib/logstash", path)
end
def pattern_path(path)
return ::File.join(LOGSTASH_HOME, "patterns", path)
end
end end
end end

View file

@ -99,7 +99,7 @@ require "set"
# #
# (?<queue_id>[0-9A-F]{10,11}) # (?<queue_id>[0-9A-F]{10,11})
# #
# Alternately, you can create a custom patterns file. # Alternately, you can create a custom patterns file.
# #
# * Create a directory called `patterns` with a file in it called `extra` # * Create a directory called `patterns` with a file in it called `extra`
# (the file name doesn't matter, but name it meaningfully for yourself) # (the file name doesn't matter, but name it meaningfully for yourself)
@ -202,7 +202,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
# #
# filter { # filter {
# grok { # grok {
# match => [ # match => [
# "message", # "message",
# "%{SYSLOGBASE} %{DATA:message}" # "%{SYSLOGBASE} %{DATA:message}"
# ] # ]
@ -216,7 +216,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
# Detect if we are running from a jarfile, pick the right path. # Detect if we are running from a jarfile, pick the right path.
@@patterns_path ||= Set.new @@patterns_path ||= Set.new
@@patterns_path += ["#{File.dirname(__FILE__)}/../../../patterns/*"] @@patterns_path += [LogStash::Environment.pattern_path("*")]
public public
def initialize(params) def initialize(params)
@ -342,7 +342,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
syntax, semantic, coerce = capture.split(":") syntax, semantic, coerce = capture.split(":")
# each_capture do |fullname, value| # each_capture do |fullname, value|
# capture_handlers[fullname].call(value, event) # capture_handlers[fullname].call(value, event)
# end # end
code = [] code = []
@ -350,7 +350,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
code << "lambda do |value, event|" code << "lambda do |value, event|"
#code << " p :value => value, :event => event" #code << " p :value => value, :event => event"
if semantic.nil? if semantic.nil?
if @named_captures_only if @named_captures_only
# Abort early if we are only keeping named (semantic) captures # Abort early if we are only keeping named (semantic) captures
# and this capture has no semantic name. # and this capture has no semantic name.
code << " return" code << " return"

View file

@ -102,7 +102,7 @@ class LogStash::Filters::Multiline < LogStash::Filters::Base
# Detect if we are running from a jarfile, pick the right path. # Detect if we are running from a jarfile, pick the right path.
@@patterns_path = Set.new @@patterns_path = Set.new
@@patterns_path += ["#{File.dirname(__FILE__)}/../../../patterns/*"] @@patterns_path += [LogStash::Environment.pattern_path("*")]
public public
def initialize(config = {}) def initialize(config = {})

View file

@ -269,15 +269,9 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
public public
def get_template def get_template
if @template.nil? if @template.nil?
if File.exists?("elasticsearch-template.json") @template = LogStash::Environment.plugin_path("outputs/elasticsearch/elasticsearch-template.json")
@template = "elasticsearch-template.json" if !File.exists?(@template)
else raise "You must specify 'template => ...' in your elasticsearch output (I looked for '#{@template}')"
path = File.join(File.dirname(__FILE__), "elasticsearch/elasticsearch-template.json")
if File.exists?(path)
@template = path
else
raise "You must specify 'template => ...' in your elasticsearch_http output"
end
end end
end end
template_json = IO.read(@template).gsub(/\n/,'') template_json = IO.read(@template).gsub(/\n/,'')

View file

@ -173,17 +173,14 @@ class LogStash::Outputs::ElasticSearchHTTP < LogStash::Outputs::Base
public public
def get_template_json def get_template_json
if @template.nil? if @template.nil?
if File.exists?("elasticsearch-template.json") @template = LogStash::Environment.plugin_path("outputs/elasticsearch/elasticsearch-template.json")
@template = "elasticsearch-template.json" if !File.exists?(@template)
elsif File.exists?("lib/logstash/outputs/elasticsearch/elasticsearch-template.json") raise "You must specify 'template => ...' in your elasticsearch_http output (I looked for '#{@template}')"
@template = "lib/logstash/outputs/elasticsearch/elasticsearch-template.json"
else
raise "You must specify 'template => ...' in your elasticsearch_http output"
end end
end end
@template_json = IO.read(@template).gsub(/\n/,'') @template_json = IO.read(@template).gsub(/\n/,'')
@logger.info("Using mapping template", :template => @template_json) @logger.info("Using mapping template", :template => @template_json)
end # def get_template end # def get_template_json
public public
def receive(event) def receive(event)