Using ActionView from rails in custom filter plugin

I'm trying to write a filter plugin which will strip html tags from a given event property. I'd rather not re-invent the wheel so I was trying to find a gem that already included this function. I found 'sanitizer' and spent hours trying to install it to no avail (due to some missing dev tool errors on my mac, but that's a whole other story...). I then came across ActionView::Base.full_sanitzer.sanitize, which should do exactly what I want. So I tried requiring action_view and using it, but this ends up messing up the filter and throwing a logstash error "Couldn't find any filter plugin named 'sanitizer'".

Here is my plugin code:

# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require "action_view"

class LogStash::Filters::Sanitizer < LogStash::Filters::Base

  config_name "sanitizer"

  config :field, :validate => :string, :required => true

  public
  def register
  end # def register

  public
  def filter(event)

    # get specified event field
    @content = event.get(@field)

    # sanitize content
    @sanitized = ActionView::Base.full_sanitizer.sanitize(@content)

    # update event with sanitized content
    event.set(@field, @sanitized)

    # filter_matched should go in the last line of our successful code
    filter_matched(event)

  end # def filter
end # class LogStash::Filters::Sanitize

I'm new to Ruby, so please excuse my ignorance :slight_smile:

I tried this solution, as I saw it being done similarly here.

Am I missing something obvious here?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.