lib/logstash/inputs/mongoprofile.rb in logstash-input-mongoprofile-0.1.14 vs lib/logstash/inputs/mongoprofile.rb in logstash-input-mongoprofile-0.1.15
- old
+ new
@@ -18,15 +18,16 @@
config :message, :validate => :string, :default => "Default message"
config :interval, :validate => :number, :default => 10
config :url, :validate => :string, :required => true
config :path, :validate => :string, :required => true
config :client_host, :validate => :string, :default => '127.0.0.1'
+ config :generate_id, :validate => :boolean, :default => false
public
def register
@host = Socket.gethostname
- @controller = Controller.new(@host, @url, 'system.profile', 1000, @path, @client_host, @logger)
+ @controller = Controller.new(@host, @url, 'system.profile', 1000, @path, @client_host, @logger, @generate_id)
end
# def register
def run(queue)
@@ -81,11 +82,12 @@
@collection.find({:client => {:$ne => @client_host}}).limit(limit).sort(:ts => -1)
end
end
class ProfileCollection
- def initialize(documents, parser)
+ def initialize(documents, parser, generate_id)
+ @generate_id = generate_id
@documents = []
documents.each do |document|
@documents.push(document)
end
@@ -93,11 +95,14 @@
@parser = parser
end
def each
@documents.each do |document|
- document['_id'] = generate_id.to_s
+ if @generate_id
+ document['_id'] = generate_id.to_s
+ end
+
yield @parser.parse(document)
end
end
def get_last_document_date
@@ -152,14 +157,15 @@
File.read(@file_full_name)
end
end
class Controller
- def initialize(event, url, collection, limit, path, client_host, logger)
+ def initialize(event, url, collection, limit, path, client_host, logger, generate_id)
@mongo_accessor = MongoAccessor.new(url, collection, client_host)
@last_value_store = LastValueStore.new(path, collection)
@document_parser = DocumentParser.new(event, logger)
+ @generate_id = generate_id
@limit = limit
@logger = logger
end
def get_next_events
@@ -171,10 +177,10 @@
else
@logger.info("Getting documents from mongo start at #{last_date_value}")
documents = @mongo_accessor.get_documents_by_ts(last_date_value, @limit)
end
- profile_collection = ProfileCollection.new(documents, @document_parser)
+ profile_collection = ProfileCollection.new(documents, @document_parser, @generate_id)
if profile_collection.get_last_document_date != nil
@last_value_store.save_last_value(profile_collection.get_last_document_date)
end
@logger.info('Nothing to get...')
\ No newline at end of file