Class: LogStash::Filters::Checksum

Inherits:
Base show all
Defined in:
lib/logstash/filters/checksum.rb

Overview

This filter let’s you create a checksum based on various parts of the logstash event. This can be useful for deduplication of messages or simply to provide a custom unique identifier.

This is VERY experimental and is largely a proof-of-concept

Constant Summary collapse

ALGORITHMS =
["md5", "sha", "sha1", "sha256", "sha384",]

Constants inherited from Base

Base::RESERVED

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize, #threadsafe?

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Filters::Base

Instance Method Details

#filter(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/logstash/filters/checksum.rb', line 34

def filter(event)
  return unless filter?(event)

  @logger.debug("Running checksum filter", :event => event)

  @keys.sort.each do |k|
    @logger.debug("Adding key to string", :current_key => k)
    @to_checksum << "|#{k}|#{event[k]}"
  end
  @to_checksum << "|"
  @logger.debug("Final string built", :to_checksum => @to_checksum)

  digested_string = OpenSSL::Digest.hexdigest(@algorithm, @to_checksum)
  @logger.debug("Digested string", :digested_string => digested_string)
  event['logstash_checksum'] = digested_string
end

#registerObject



28
29
30
31
# File 'lib/logstash/filters/checksum.rb', line 28

def register
  require 'openssl'
  @to_checksum = ""
end