Refacter known file lookups to a single method in LogStash::Environment

This commit is contained in:
Jordan Sissel 2014-05-02 11:06:32 -07:00
parent 98f28ad376
commit 0d2f0b9a11
3 changed files with 11 additions and 13 deletions

View file

@ -27,5 +27,9 @@ module LogStash
def jruby?
RUBY_PLATFORM == "java"
end
def vendor_path(path)
return ::File.join(LOGSTASH_HOME, "vendor", relative_path)
end
end
end

View file

@ -64,12 +64,9 @@ class LogStash::Filters::GeoIP < LogStash::Filters::Base
def register
require "geoip"
if @database.nil?
if File.exists?("GeoLiteCity.dat")
@database = "GeoLiteCity.dat"
elsif File.exists?("vendor/geoip/GeoLiteCity.dat")
@database = "vendor/geoip/GeoLiteCity.dat"
else
raise "You must specify 'database => ...' in your geoip filter"
@database = LogStash::Environment.vendor_path("geoip/GeoLiteCity.dat")
if !File.exists?(@database)
raise "You must specify 'database => ...' in your geoip filter (I looked for '#{@database}'"
end
end
@logger.info("Using geoip database", :path => @database)

View file

@ -116,15 +116,12 @@ class LogStash::Inputs::Collectd < LogStash::Inputs::Base
def register
@udp = nil
if @typesdb.nil?
if File.exists?("types.db")
@typesdb = ["types.db"]
elsif File.exists?("vendor/collectd/types.db")
@typesdb = ["vendor/collectd/types.db"]
else
raise "You must specify 'typesdb => ...' in your collectd input"
@typesdb = LogStash::Environment.vendor_path("collectd/types.db")
if !File.exists?(@typesdb)
raise "You must specify 'typesdb => ...' in your collectd input (I looked for '#{@typesdb}')"
end
@logger.info("Using internal types.db", :typesdb => @typesdb.to_s)
end
@logger.info("Using internal types.db", :typesdb => @typesdb.to_s)
if ([SECURITY_SIGN, SECURITY_ENCR].include?(@security_level))
if @authfile.nil?