Logstash custom filter is not taking the field, and takes the filed name as the string instead


(Isra) #1

The following is my filter .rb file

# encoding: utf-8

require "logstash/filters/base"
require "logstash/namespace"
require 'java'
require 'myProject.jar'

$CLASSPATH << 'lib'

class LogStash::Filters::Analyze < LogStash::Filters::Base
 
  config_name "analyze"
  config :text, :validate => :string

  public
  def register
    @result = JavaUtilities.get_proxy_class('MyClass.myMethod')
    @result_ = @result.new()
    @final_result = @result _.myMethod(@text)
  end

  public
  def filter(event)
      event["text_being_proccessed"] = @text
    filter_matched(event)
  end

end

And the following is my configuration filter:

analyze {
   text => {%{text}}  #note that the field I wanna analyze is also called text
}

However, the result is text and not the value of text. WHy is that??? HELP PLEASE

Thanks.


(Magnus B├Ąck) #2
text => {%{text}}

Do you actually mean

text => "%{text}"

? In that case you need to access the contents of the text field with event.sprintf(@text).


(Isra) #4

Okay, I see. Using (event) wouldn't work inside the register method tho, right? only within the filter method?


(Isra) #5

Oh everything is working for me now, thank you so much :slight_smile:


(system) #6