logstash-output-azure_service_bus 0.1.6 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86afcaf954af103be089a59d6fecb8f6fe4f2d69b5190f7ffd6ad33648a46054
4
- data.tar.gz: 29e8e7fa58b69b713df750609609a96e4a4f0d2000f37362cae92d20a36104ad
3
+ metadata.gz: d92fdd5d7f0480de294337224352219cbf9d3d716f52af0ab4e80ce9a15cda76
4
+ data.tar.gz: f71204c35cdb3ec8d8366e21c2a6704e267d2385084e40e55786f3159bb885f0
5
5
  SHA512:
6
- metadata.gz: 242299e9ab1b5bc4ca4adb3af61976d05fe5216331a82b91dad00e19099187faeb0b90daa870b987a404ddbc50af18c13c44344a7adea648f83d967dd1431d64
7
- data.tar.gz: 31fca87e475ae0e52ff5654f88b59f9a5efa84c739425938c853b4691f50b3ed241306bb7ec249f1e240571b55293a2fd7ee40301043f01d807b112a16057961
6
+ metadata.gz: cb50873e64d439fc6114e748c9fd86c53b70b6d7ca3ca3eb271c71950941ccaa92fc2927259e8143c2349bd32b2f56313ec1a257dc3bfc01a07afcfc55375efb
7
+ data.tar.gz: 5fd4b7d91de58c9e439cbf39f4d935a6f688b149ace2b0135743f3a1ed6684951828689066a73f447fa8a15f928cdd3c0affa1b02e9a5f5920b31edf9f6dd0e5
data/README.md CHANGED
@@ -7,7 +7,7 @@ This plugin is hosted on RubyGems.org: [https://rubygems.org/gems/logstash-outpu
7
7
  ## Install
8
8
  To install, use the plugin tool that is part of your Logstash installation:
9
9
  ```
10
- $LOGSTASH_INSTALL/bin/logstash-plugin install logstash-output-azure_service_bus
10
+ $LOGSTASH_PATH/bin/logstash-plugin install logstash-output-azure_service_bus
11
11
  ```
12
12
 
13
13
  ## Pipeline Configuration
@@ -22,6 +22,26 @@ output {
22
22
  }
23
23
  }
24
24
  ```
25
+ There is one optional setting (`messageid_field`) which sets the Service Bus `MessageId` value to an existing, unique field. If this setting is not used, Service Bus will generate an id when the message is created. The value of the provided field _must_ be unique or Service Bus will reject the message. A sample config might look like:
26
+ ```
27
+ input { ... }
28
+ filter {
29
+ uuid {
30
+ target => "[@metadata][uuid]"
31
+ }
32
+ }
33
+ output {
34
+ azure_service_bus {
35
+ service_bus_namespace => "service-bus-name"
36
+ service_bus_entity => "queue-or-topic-name"
37
+ messageid_field => "[@metadata][uuid]"
38
+ }
39
+ elasticsearch {
40
+ ...
41
+ document_id => "%{[@metadata][uuid]}"
42
+ }
43
+ }
44
+ ```
25
45
 
26
46
  ## Service Bus Configuration
27
47
  This plugin will retry sending messages if the Service Bus connection times out or returns a bad response. To avoid idempotence issues, you should enable duplicate detection on the destination queue or topic.
@@ -10,23 +10,24 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
10
10
 
11
11
  config :service_bus_namespace, :validate => :string, :required => true
12
12
  config :service_bus_entity, :validate => :string, :required => true
13
+ config :messageid_field, :validate => :string
13
14
 
14
15
  def register
15
16
  retry_options = {
16
- max: 3,
17
+ max: 5,
17
18
  interval: 1,
18
19
  interval_randomness: 0.5,
19
20
  backoff_factor: 2,
20
21
  retry_statuses: [429, 500],
21
22
  exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::RetriableResponse],
22
23
  methods: %i[get post],
23
- retry_block: ->(env, _options, retries, exception) { @logger.error("Error (#{exception}) for #{env.method.upcase} #{env.url} - #{retries + 1} retry(s) left") }
24
+ retry_block: ->(env, _options, retries, exception) { @logger.warn("Problem (#{exception}) for #{env.method.upcase} #{env.url} - #{retries + 1} retry(s) left") }
24
25
  }
25
26
  @token_conn = Faraday.new(
26
27
  url: 'http://169.254.169.254/metadata/identity/oauth2/token',
27
28
  params: { 'api-version' => '2018-02-01', 'resource' => 'https://servicebus.azure.net/' },
28
29
  headers: { 'Metadata' => 'true' },
29
- request: { timeout: 1 }
30
+ request: { timeout: 4 }
30
31
  ) do |f|
31
32
  f.request :retry, retry_options
32
33
  end
@@ -48,18 +49,26 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
48
49
  def send_events(events)
49
50
  messages = []
50
51
  events.each do |event|
51
- messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json' } })
52
+ if @messageid_field.nil?
53
+ messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json' } })
54
+ else
55
+ messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json', 'MessageId' => event.get(@messageid_field) } })
56
+ end
52
57
  end
53
58
  post_messages(messages)
54
59
  end
55
60
 
56
61
  def post_messages(messages)
57
62
  refresh_access_token if access_token_needs_refresh?
58
- response = @service_bus_conn.post('messages') do |req|
59
- req.body = JSON.generate(messages)
60
- req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
63
+ begin
64
+ response = @service_bus_conn.post('messages') do |req|
65
+ req.body = JSON.generate(messages)
66
+ req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
67
+ end
68
+ rescue StandardError => e
69
+ @logger.error("Error (#{e}) while sending message to Service Bus")
61
70
  end
62
- raise "Error while sending message to Service Bus: HTTP #{response.status}" if response.status != 201
71
+ @logger.error("HTTP error while sending message to Service Bus: HTTP #{response.status}") if response.status != 201
63
72
 
64
73
  @logger.debug("Sent #{messages.length} message(s) to Service Bus")
65
74
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-azure_service_bus'
3
- s.version = '0.1.6'
3
+ s.version = '0.2.2'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Send Logstash messages to Azure Service Bus.'
6
6
  s.homepage = 'https://github.com/gharryg/logstash-output-azure_service_bus'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-azure_service_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harrison Golden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement