# 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