logstash-output-loganalytics 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecd7903598f40592f66d67105c1722dde37404b65485db3fdbf070c82510608b
4
- data.tar.gz: bc23be8507bba4d28105ae3af58ea993d6b3c1c8ce9a6058229cf7c6aebb986e
3
+ metadata.gz: 1e42bcd913718ac95939b864d050d3ac6ac89286ae63dc1b96eb13af0dada1f1
4
+ data.tar.gz: 5fd60780a81eaf8482e4cb4bfd51dfd5e716b4a02cf7aa13dd6fe0cf8f5c02af
5
5
  SHA512:
6
- metadata.gz: 817a115933bbc78367636dd02dbe4af1f5b894cf74b799c70de80e982dc92e7829b3a717d693af05ec4bc047eca822cea5791ac7d237087ce71a76bda6ac7ad6
7
- data.tar.gz: b54896e448febaeb48afe53503111c3d135c1349603a89dd7c66e86dc30e250a3e282595023194a07be8117eb4f78f4341446b44ba648c534b1baa3e330d76b9
6
+ metadata.gz: 71e115f3a2c9feb10a1a44fd0e7fbcbef6b5e1c2c0efbb3259909eec3205b62b623385f6e629e70b49d074a798c30b2a53752f4a3d824b759635e61cc48b65dc
7
+ data.tar.gz: 86d0f659d0ded7e622aaef9d9f5ce280e8df0e3e9480bf0142fa5a8de0464f2bf163232e8f8a271f5b777f3edfa030feae6c9e97ed8d7eba49ce61b56b2778e2
@@ -11,43 +11,50 @@ class LogStash::Outputs::Loganalytics < LogStash::Outputs::Base
11
11
  config_name "loganalytics"
12
12
 
13
13
  # Your Operations Management Suite workspace ID
14
- config :customer_id, :validate => :string, :required => true
14
+ config :client_id, :validate => :string, :required => true
15
15
 
16
16
  # The primary or the secondary Connected Sources client authentication key
17
- config :shared_key, :validate => :string, :required => true
17
+ config :client_secret, :validate => :string, :required => true
18
18
 
19
19
  # The name of the event type that is being submitted to Log Analytics. This must be only alpha characters.
20
- config :log_type, :validate => :string, :required => true
20
+ config :table, :validate => :string, :required => true
21
21
 
22
22
  # The name of the time generated field. Be carefule that the value of field should strictly follow the ISO 8601 format (YYYY-MM-DDThh:mm:ssZ)
23
23
  config :time_generated_field, :validate => :string, :default => '', :required => false
24
24
 
25
25
  public
26
26
  def register
27
- raise ArgumentError, 'log_type must be only alpha characters and less than 100 characters' unless @log_type.match(/^[a-zA-Z]{1,100}$/)
28
- @uri = "https://#{@customer_id}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01"
27
+ raise ArgumentError, 'log type must be only alpha characters and less than 100 characters' unless @table.match(/^[a-zA-Z]{1,100}$/)
28
+ @uri = "https://#{@client_id}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01"
29
29
  end
30
30
 
31
31
  def receive(event)
32
32
  begin
33
33
  body = event.to_json
34
+ #puts body
34
35
  date = Time.now.httpdate
36
+ #puts date
35
37
  string_to_hash = "POST\n#{body.bytesize}\napplication/json\nx-ms-date:#{date}\n/api/logs"
36
- hashed_string = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), Base64.decode64(@shared_key), string_to_hash.encode('utf-8')))
38
+ #puts string_to_hash
39
+ hashed_string = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), Base64.decode64(@client_secret), string_to_hash.encode('utf-8')))
40
+ #puts hashed_string
37
41
  headers = {}
38
42
  headers['Content-Type'] = 'application/json'
39
- headers['Authorization'] = "SharedKey #{@customer_id}:#{hashed_string}"
40
- headers['Log-Type'] = @log_type
43
+ headers['Authorization'] = "SharedKey #{@client_id}:#{hashed_string}"
44
+ headers['Log-Type'] = @table
41
45
  headers['x-ms-date'] = date
42
46
  unless @time_generated_field.empty?
43
47
  headers['time-generated-field'] = @time_generated_field
44
48
  end
45
49
  response = RestClient.post(@uri, body, headers)
50
+ #puts response.code
46
51
  unless response.code == 200
47
- $logger.error("DataCollector API request failure: error code: #{response.code}, data=>#{event}")
52
+ #puts "DataCollector API request failure: error code: #{response.code}, data=>#{event}"
53
+ @logger.error("DataCollector API request failure: error code: #{response.code}, data=>#{event}")
48
54
  end
49
55
  rescue Exception => ex
50
- $logger.error("Exception occured in posting to DataCollector API: '#{ex}', data=>#{event}")
56
+ #puts "Exception occured in posting to DataCollector API: '#{ex}', data=>#{event}"
57
+ @logger.error("Exception occured in posting to DataCollector API: '#{ex}', data=>#{event}")
51
58
  end
52
59
  end
53
60
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-loganalytics'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Logstash output plugin for Azure Log Analytics.'
6
6
  s.description = 'Logstash output plugin to send logs to Azure Log Analytics. Uses Log Analytics HTTP Data Collector API under the hood.'
@@ -5,18 +5,35 @@ require "logstash/codecs/plain"
5
5
  require "logstash/event"
6
6
 
7
7
  describe LogStash::Outputs::Loganalytics do
8
- let(:sample_event) { LogStash::Event.new }
9
- let(:output) { LogStash::Outputs::Loganalytics.new }
8
+ let(:client_id) { 'test' }
9
+ let(:client_secret) { 'test' }
10
+ let(:table) { 'logstashplugintest' }
11
+
12
+ let(:cfg) {
13
+ {
14
+ "client_id" => client_id,
15
+ "client_secret" => client_secret,
16
+ "table" => table
17
+ }
18
+ }
19
+
20
+ let(:output) { LogStash::Outputs::Loganalytics.new(cfg) }
10
21
 
11
22
  before do
12
23
  output.register
13
24
  end
14
25
 
15
- describe "receive message" do
16
- subject { output.receive(sample_event) }
26
+ describe "#receive" do
27
+ it "Should successfully send the event to log analytics" do
28
+ log = {
29
+ :logid => "628cc9db-0aec-4423-83d2-c78c11bd9b94",
30
+ :message => "this is a test",
31
+ :level => "info"
32
+ }
17
33
 
18
- it "returns a string" do
19
- expect(subject).to eq("Event received")
34
+ event = LogStash::Event.new(log)
35
+ expect {output.receive(event)}.to_not raise_error
20
36
  end
37
+
21
38
  end
22
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-loganalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bartsch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-24 00:00:00.000000000 Z
11
+ date: 2018-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement