31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/logstash/outputs/loganalytics.rb', line 31
def receive(event)
begin
body = event.to_json
date = Time.now.httpdate
string_to_hash = "POST\n#{body.bytesize}\napplication/json\nx-ms-date:#{date}\n/api/logs"
hashed_string = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), Base64.decode64(@client_secret), string_to_hash.encode('utf-8')))
= {}
['Content-Type'] = 'application/json'
['Authorization'] = "SharedKey #{@client_id}:#{hashed_string}"
['Log-Type'] = @table
['x-ms-date'] = date
unless @time_generated_field.empty?
['time-generated-field'] = @time_generated_field
end
response = RestClient.post(@uri, body, )
unless response.code == 200
@logger.error("DataCollector API request failure: error code: #{response.code}, data=>#{event}")
end
rescue Exception => ex
@logger.error("Exception occured in posting to DataCollector API: '#{ex}', data=>#{event}")
end
end
|