Class: LogStash::Filters::SchemaCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/schema_check.rb

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/logstash/filters/schema_check.rb', line 82

def filter(event)
  if @schema_path
    if needs_refresh?
      lock_for_write do
        if needs_refresh?
          load_schema
          @next_refresh = Time.now + @refresh_interval
          @logger.info("refreshing schema file")
        end
      end
    end
  end

  begin
    event_obj = event.to_hash
    if @debug_output
      output = JSON::Validator.fully_validate(@schema, event_obj, :strict => @strict, :fragment => @fragment, :validate_schema => validate_schema)
      unless output.empty?
        @tag_on_failure.each {|tag| event.tag(tag)}
        event.set(@failures_field, output)
      end
    else
      unless JSON::Validator.validate(@schema, event_obj, :strict => @strict, :fragment => @fragment, :validate_schema => validate_schema)
        @tag_on_failure.each {|tag| event.tag(tag)}
      end
    end
    filter_matched(event)
  rescue Exception => e
    @logger.error("Something went wrong when checking schema", :exception => e, :event => event)
  end
end

#registerObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/logstash/filters/schema_check.rb', line 58

def register
  rw_lock = java.util.concurrent.locks.ReentrantReadWriteLock.new
  @read_lock = rw_lock.readLock
  @write_lock = rw_lock.writeLock

  if @schema_path && !@schema.empty?
    raise LogStash::ConfigurationError, I18n.t(
      "logstash.agent.configuration.invalid_plugin_register",
      :plugin => "filter",
      :type => "schema_check",
      :error => "The configuration options 'schema' and 'schema_path' are mutually exclusive"
    )
  end

 if @schema_path
   @next_refresh = Time.now + @refresh_interval
   raise_exception = true
   lock_for_write { load_schema(raise_exception) }
 end

  @logger.debug? and @logger.debug("#{self.class.name}: schema - ", :schema => @schema)
end