Class: LogStash::Filters::SchemaValidation

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

Overview

This filter will replace the contents of the default message field with whatever you specify in the configuration.

It is only intended to be used as an .

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/logstash/filters/schema_validation.rb', line 41

def filter(event)

  schemaFilePath = generate_filepath(event)

  if File.exists?(schemaFilePath)

    validationErrors = JSON::Validator.fully_validate(schemaFilePath, event.to_hash, :strict => @strict, :fragment => @fragment, :parse_data => false)

    if validationErrors.empty?
      filter_matched(event)
    else
      tag_unsuccessful_lookup(event)

      unless @report_field.nil? || @report_field.empty?
        event.set(@report_field, validationErrors)
      end
    end

  else

    @logger.fatal? && @logger.fatal("Schema file '" + schemaFilePath + "' does not exists!")

    tag_unsuccessful_lookup(event)

    unless @report_field.nil? || @report_field.empty?
      event.set(@report_field, ["Schema file '" + schemaFilePath + "' does not exists!"])
    end

  end

end

#registerObject



36
37
38
# File 'lib/logstash/filters/schema_validation.rb', line 36

def register
  @schema = File.expand_path(@schema)
end

#tag_unsuccessful_lookup(event) ⇒ Object



73
74
75
76
# File 'lib/logstash/filters/schema_validation.rb', line 73

def tag_unsuccessful_lookup(event)
  @logger.debug? && @logger.debug("Event data is not valide!", :event => event)
  @tag_on_failure.each{|tag| event.tag(tag)}
end