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()
# 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
@fields = YAML.load_file(filename)
@ -162,7 +162,7 @@ class LogStash::Codecs::Netflow < LogStash::Codecs::Base
# Purge any expired templates
@templates.cleanup!
end
end
end
when 256..65535
# Data flowset
#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
# be at most 3 padding bytes
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
end

View file

@ -31,5 +31,13 @@ module LogStash
def vendor_path(path)
return ::File.join(LOGSTASH_HOME, "vendor", path)
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

View file

@ -99,7 +99,7 @@ require "set"
#
# (?<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`
# (the file name doesn't matter, but name it meaningfully for yourself)
@ -202,7 +202,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
#
# filter {
# grok {
# match => [
# match => [
# "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.
@@patterns_path ||= Set.new
@@patterns_path += ["#{File.dirname(__FILE__)}/../../../patterns/*"]
@@patterns_path += [LogStash::Environment.pattern_path("*")]
public
def initialize(params)
@ -342,7 +342,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
syntax, semantic, coerce = capture.split(":")
# each_capture do |fullname, value|
# capture_handlers[fullname].call(value, event)
# capture_handlers[fullname].call(value, event)
# end
code = []
@ -350,7 +350,7 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
code << "lambda do |value, event|"
#code << " p :value => value, :event => event"
if semantic.nil?
if @named_captures_only
if @named_captures_only
# Abort early if we are only keeping named (semantic) captures
# and this capture has no semantic name.
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.
@@patterns_path = Set.new
@@patterns_path += ["#{File.dirname(__FILE__)}/../../../patterns/*"]
@@patterns_path += [LogStash::Environment.pattern_path("*")]
public
def initialize(config = {})

View file

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

View file

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