Class: LogStash::Outputs::Azuresearch

Inherits:
Base
  • Object
show all
Includes:
Stud::Buffer
Defined in:
lib/logstash/outputs/azuresearch.rb

Instance Method Summary collapse

Instance Method Details

#flush(events, close = false) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/logstash/outputs/azuresearch.rb', line 67

def flush (events, close=false)

  documents = []  #this is the array of hashes to add Azure search
  events.each do |event|
    document = {}
    event_hash = event.to_hash()

    ## Check if event contains primary item that should be stored as 
    ## primary key in Azure Search
    if not event_hash.include?(@primary_key_in_event)
      $logger.warn( "The event does not contain primary item!!: " + (event_hash.to_json).to_s)
      next
    end

    @column_names.each_with_index do|k, i|
      ikey = @key_names[i]
      ival = event_hash.include?(ikey) ? event_hash[ikey] : ''
      document[k] = ival
    end
    documents.push(document)
  end

  ## Skip in case there are no candidate documents to deliver
  if documents.length < 1
    return
  end

  begin
    @client.add_documents(@search_index, documents)
  rescue RestClient::ExceptionWithResponse => rcex
    exdict = JSON.parse(rcex.response)
    $logger.error("RestClient Error: '#{rcex.response}', data=>" + (documents.to_json).to_s)
  rescue => ex
    $logger.error( "Error: '#{ex}'" + ", data=>" + (documents.to_json).to_s)
  end

end

#receive(event) ⇒ Object



60
61
62
63
# File 'lib/logstash/outputs/azuresearch.rb', line 60

def receive(event)
  # Simply save an event for later delivery
  buffer_receive(event)
end

#registerObject

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/logstash/outputs/azuresearch.rb', line 37

def register
  require_relative 'azuresearch/client'

  ## Configure
  if @key_names.length < 1
    @key_names = @column_names
  end
  raise ArgumentError, 'NOT match keys number: column_names and key_names' \
        if @key_names.length != @column_names.length

  @primary_key_in_event = @key_names[0]
  ## Initialize Azure Search client Instance
  @client=AzureSearch::Client::new( @endpoint, @api_key )

  buffer_initialize(
      :max_items => @flush_items,
      :max_interval => @flush_interval_time,
      :logger => @logger
    )

end