Sha256: 9caae79106980f6929448ac2e57b7d8f0c489c72fa3c9bac099c4ee8032c6819

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

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

# Validate your JSON data using given JSON schema file.
# 
# This filter returns "Invalid JSON data" or "Valid JSON data"
# as a value of field "validation".

class LogStash::Filters::Schemavalid < LogStash::Filters::Base

  config_name "schemavalid"

  # The JSON schema is taken from the given path.
  # file_path is required!
  # 
  # Example:
  # [source, ruby]
  # 	filter {
  #	  schemavalid {
  #	    file_path => "/absolute/path/to/the/schema.json"
  #	  }
  #	}

  config :file_path, :required => true, :validate => :string 
  
  public
  def register
  end # def register

  public
  def filter(event)

      if JSON::Validator.validate(@file_path, event["message"])
        validation = "Valid JSON data" 
      else
        validation = "Invalid JSON data"
      end
      event["validation"] = validation
      filter_matched(event)

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-filter-schemavalid-0.1.0 lib/logstash/filters/schemavalid.rb