From ab9985c26a7db37427246310fdd33f2a73fa6505 Mon Sep 17 00:00:00 2001 From: Aaron Mildenstein Date: Wed, 14 May 2014 19:33:21 -0500 Subject: [PATCH] Fixing relative path issues left over from flatjar era Use plugin_path and pattern_path closes 1377 --- lib/logstash/codecs/netflow.rb | 6 +++--- lib/logstash/environment.rb | 8 ++++++++ lib/logstash/filters/grok.rb | 10 +++++----- lib/logstash/filters/multiline.rb | 2 +- lib/logstash/outputs/elasticsearch.rb | 12 +++--------- lib/logstash/outputs/elasticsearch_http.rb | 11 ++++------- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/logstash/codecs/netflow.rb b/lib/logstash/codecs/netflow.rb index 9e2d99de1..278cd214d 100644 --- a/lib/logstash/codecs/netflow.rb +++ b/lib/logstash/codecs/netflow.rb @@ -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 diff --git a/lib/logstash/environment.rb b/lib/logstash/environment.rb index fd234644c..f8c12ef59 100644 --- a/lib/logstash/environment.rb +++ b/lib/logstash/environment.rb @@ -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 diff --git a/lib/logstash/filters/grok.rb b/lib/logstash/filters/grok.rb index e992ccd5a..bac6ff0c1 100644 --- a/lib/logstash/filters/grok.rb +++ b/lib/logstash/filters/grok.rb @@ -99,7 +99,7 @@ require "set" # # (?[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" diff --git a/lib/logstash/filters/multiline.rb b/lib/logstash/filters/multiline.rb index bcee5757a..eafae06d1 100644 --- a/lib/logstash/filters/multiline.rb +++ b/lib/logstash/filters/multiline.rb @@ -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 = {}) diff --git a/lib/logstash/outputs/elasticsearch.rb b/lib/logstash/outputs/elasticsearch.rb index 6b92e3466..2e6458b09 100644 --- a/lib/logstash/outputs/elasticsearch.rb +++ b/lib/logstash/outputs/elasticsearch.rb @@ -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/,'') diff --git a/lib/logstash/outputs/elasticsearch_http.rb b/lib/logstash/outputs/elasticsearch_http.rb index 32a85d0f2..496e108e8 100644 --- a/lib/logstash/outputs/elasticsearch_http.rb +++ b/lib/logstash/outputs/elasticsearch_http.rb @@ -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)