Class: LogStash::Filters::FixProtocol

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FixProtocol

Returns a new instance of FixProtocol.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/logstash/filters/fix_protocol.rb', line 23

def initialize(options = {})
  super(options)

  fail "Need to configure a valid data dictionary path" unless config["data_dictionary_path"]

  @data_dictionary = DataDictionary.new(config["data_dictionary_path"])

  # Set session data dictionary variable if using > FIX 5.0
  session_dict = config["session_dictionary_path"]
  @session_dictionary = session_dict.present? ? DataDictionary.new(session_dict) : @data_dictionary
end

Instance Attribute Details

#data_dictionaryObject (readonly)

Returns the value of attribute data_dictionary.



14
15
16
# File 'lib/logstash/filters/fix_protocol.rb', line 14

def data_dictionary
  @data_dictionary
end

#session_dictionaryObject (readonly)

Returns the value of attribute session_dictionary.



14
15
16
# File 'lib/logstash/filters/fix_protocol.rb', line 14

def session_dictionary
  @session_dictionary
end

Instance Method Details

#filter(event) ⇒ Object



39
40
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
# File 'lib/logstash/filters/fix_protocol.rb', line 39

def filter(event)
  message_string = event[config["fix_message"]]

  if message_string
    fix_message = nil

    begin
      fix_message = FixMessage.new(message_string, data_dictionary, session_dictionary)
    rescue Java::Quickfix::InvalidMessage, ArgumentError
      event["tags"] = ["_fix_parse_failure"]
    end

    if fix_message
      fix_hash = fix_message.to_hash

      # TODO: Unknown tags are only set after calling #to_hash
      # this creates an implicit timing issue
      if fix_message.unknown_fields.any?
        event["unknown_fields"] = fix_message.unknown_fields
        event["tags"] = ["_fix_field_not_found"]
      end

      fix_hash.each do |key, value|
        event[key] = value
      end
    end
  end
  # filter_matched should go in the last line of our successful code
  filter_matched(event)
end

#registerObject



35
36
37
# File 'lib/logstash/filters/fix_protocol.rb', line 35

def register
  # just here because you complain otherwise
end