logstash-filter-dns 3.1.5 → 3.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: 2bfbc599a24bf91ca96cb549cbee80394e3660b968178c94739437b96b2639b4
4
- data.tar.gz: 18f7cde848f00e8164cabd416e4fb1f2f0f6ee699bae018ae4c1f327e781adb1
3
+ metadata.gz: 53553697483fd03bdf2c112a17de6797e1433cfe9788c85a4503a748c0e4df3d
4
+ data.tar.gz: 8e4f0800c03f7d3d3894ea7d5aa9d7f74ea1f2caf1ac95fc828163fdd8676026
5
5
  SHA512:
6
- metadata.gz: 4b899b43f760b97f33f88637591cd4367edc9c919c2d55db9d7726e783ba424396a2641a1f54c3cba1eb1562d54eb0d413456e70f21cf83c5585bb766eb3f104
7
- data.tar.gz: a94cd76f11a1f4f85e4981f8b3b8d6d8cd9de2f625a1a87c22544876254f899c0099915eb39f1cea38b5c2075663826768c9ee663c30fe135d6b05def2508b63
6
+ metadata.gz: 3e706cb9f6424adba08d42ea7e686b4020f467557ffbcdc9420e211b10c0adeb6d4ea0db23d189bf81529916b86f326e94c149a69282f0340cc44f6df9ffbc6c
7
+ data.tar.gz: 92e0a9fec287c122d1ba68a3f15164988420e1174e89d1278e8d12c9bc9ddcdbc9016ef64fa76372ab8b2ee0f7e2db15601c00c5ac9dbfd14f5f93ae30533ffd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
+ ## 3.2.0
2
+ - Support adding tag(s) on DNS lookup times out, defaults to `["_dnstimeout"]` [#67](https://github.com/logstash-plugins/logstash-filter-dns/pull/67)
3
+ - As timeouts can be received through tags now, DNS lookup timeouts are logged in debug logs only. [#67](https://github.com/logstash-plugins/logstash-filter-dns/pull/67)
4
+
1
5
  ## 3.1.5
2
- - Fixed an issue where a non-string value existing in the resolve/reverse field could cause the plugin to crash
6
+ - Fixed an issue where a non-string value existing in the resolve/reverse field could cause the plugin to crash [#65](https://github.com/logstash-plugins/logstash-filter-dns/pull/65)
3
7
 
4
8
  ## 3.1.4
5
9
  - Replaced Timeout::timeout block with `Resolv::DNS::timeouts=` [#62](https://github.com/logstash-plugins/logstash-filter-dns/pull/62)
data/docs/index.asciidoc CHANGED
@@ -58,6 +58,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
58
58
  | <<plugins-{type}s-{plugin}-nameserver>> |<<hash,hash>>|No
59
59
  | <<plugins-{type}s-{plugin}-resolve>> |<<array,array>>|No
60
60
  | <<plugins-{type}s-{plugin}-reverse>> |<<array,array>>|No
61
+ | <<plugins-{type}s-{plugin}-tag_on_timeout>> |<<array,array>>|No
61
62
  | <<plugins-{type}s-{plugin}-timeout>> |<<number,number>>|No
62
63
  |=======================================================================
63
64
 
@@ -173,6 +174,13 @@ Reverse resolve one or more fields.
173
174
 
174
175
  `resolv` calls will be wrapped in a timeout instance
175
176
 
177
+ [id="plugins-{type}s-{plugin}-tag_on_timeout"]
178
+ ===== `tag_on_timeout`
179
+
180
+ * Value type is <<array,array>>
181
+ * Defaults to `["_dnstimeout"]`.
182
+
183
+ Add tag(s) on DNS lookup time out.
176
184
 
177
185
 
178
186
  [id="plugins-{type}s-{plugin}-common-options"]
@@ -86,6 +86,9 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
86
86
  # Use custom hosts file(s). For example: `["/var/db/my_custom_hosts"]`
87
87
  config :hostsfile, :validate => :array
88
88
 
89
+ # Tag(s) to apply if a DNS lookup times out. Defaults to `["_dnstimeout"]`.
90
+ config :tag_on_timeout, :validate => :string, :list => true, :default => ["_dnstimeout"]
91
+
89
92
  attr_reader :hit_cache
90
93
  attr_reader :failed_cache
91
94
 
@@ -219,8 +222,9 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
219
222
  end
220
223
  rescue Resolv::ResolvTimeout
221
224
  @failed_cache[raw] = true if @failed_cache
222
- @logger.warn("DNS: timeout on resolving the hostname.",
225
+ @logger.debug("DNS: timeout on resolving the hostname.",
223
226
  :field => field, :value => raw)
227
+ @tag_on_timeout.each { |tag| event.tag(tag) }
224
228
  return
225
229
  rescue SocketError => e
226
230
  @logger.error("DNS: Encountered SocketError.",
@@ -305,8 +309,9 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
305
309
  end
306
310
  rescue Resolv::ResolvTimeout
307
311
  @failed_cache[raw] = true if @failed_cache
308
- @logger.warn("DNS: timeout on resolving address.",
312
+ @logger.debug("DNS: timeout on resolving address.",
309
313
  :field => field, :value => raw)
314
+ @tag_on_timeout.each { |tag| event.tag(tag) }
310
315
  return
311
316
  rescue SocketError => e
312
317
  @logger.error("DNS: Encountered SocketError.",
@@ -345,7 +350,7 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
345
350
  tries = 0
346
351
  begin
347
352
  block.call
348
- rescue Resolv::ResolvTimeout, SocketError
353
+ rescue Resolv::ResolvTimeout, SocketError
349
354
  if tries < @max_retries
350
355
  tries = tries + 1
351
356
  retry
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-dns'
4
- s.version = '3.1.5'
4
+ s.version = '3.2.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Performs a standard or reverse DNS lookup"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -7,6 +7,7 @@ require "logstash/filters/dns/resolv_patch"
7
7
 
8
8
 
9
9
  describe LogStash::Filters::DNS do
10
+
10
11
  describe "with stubbed Resolv" do
11
12
  before(:each) do
12
13
  # We use `Resolv#each_address` and `Resolv#each_name`, which have
@@ -621,4 +622,115 @@ describe LogStash::Filters::DNS do
621
622
  end
622
623
  end
623
624
  end
625
+
626
+ describe "dns forward timeout" do
627
+
628
+ let(:subject) { LogStash::Filters::DNS.new(config) }
629
+
630
+ before(:each) do
631
+ allow(subject).to receive(:getaddress).and_raise(Resolv::ResolvTimeout)
632
+ subject.register
633
+ subject.filter(event)
634
+ end
635
+
636
+ context "when using the default tag" do
637
+ let(:config) { { "resolve" => ["message"] } }
638
+ let(:event) { LogStash::Event.new("message" => "carrera.databits.net") }
639
+
640
+ it "should add the default DNS timeout tag" do
641
+ expect(event.get("tags")).to eq(["_dnstimeout"])
642
+ end
643
+ end
644
+
645
+ context "when using a custom tag" do
646
+ let(:config) { { "resolve" => ["message"], "tag_on_timeout" => ["dns_custom_timeout"] } }
647
+ let(:event) { LogStash::Event.new("message" => "carrera.databits.net") }
648
+
649
+ it "should add the custom DNS timeout tag" do
650
+ expect(event.get("tags")).to eq(["dns_custom_timeout"])
651
+ end
652
+ end
653
+
654
+ context "when using no tags" do
655
+ let(:config) { { "resolve" => ["message"], "tag_on_timeout" => [] } }
656
+ let(:event) { LogStash::Event.new("message" => "carrera.databits.net") }
657
+
658
+ it "should not add any failure tags" do
659
+ expect(event.get("tags")).to eq(nil)
660
+ end
661
+ end
662
+
663
+ context "when logging" do
664
+
665
+ context "with debug" do
666
+ let(:config) { { "resolve" => ["message"] } }
667
+ let(:event) { LogStash::Event.new("message" => "127.0.0.1") }
668
+
669
+ before do
670
+ allow(subject.logger).to receive(:debug).with(any_args)
671
+ end
672
+
673
+ it "logs on timeout exception" do
674
+ subject.filter(event)
675
+ expect(subject.logger).to have_received(:debug).with("DNS: timeout on resolving the hostname.", :field => "message", :value => "127.0.0.1")
676
+ end
677
+ end
678
+ end
679
+ end
680
+
681
+ describe "dns reverse timeout" do
682
+
683
+ let(:subject) { LogStash::Filters::DNS.new(config) }
684
+
685
+ before(:each) do
686
+ allow(subject).to receive(:getname).and_raise(Resolv::ResolvTimeout)
687
+ subject.register
688
+ subject.filter(event)
689
+ end
690
+
691
+ context "when using the default tag" do
692
+ let(:config) { { "reverse" => ["message"] } }
693
+ let(:event) { LogStash::Event.new("message" => "127.0.0.1") }
694
+
695
+ it "should add the default DNS timeout tag" do
696
+ expect(event.get("tags")).to eq(["_dnstimeout"])
697
+ end
698
+ end
699
+
700
+ context "when using a custom tag" do
701
+ let(:config) { { "reverse" => ["message"], "tag_on_timeout" => ["dns_custom_timeout"] } }
702
+ let(:event) { LogStash::Event.new("message" => "127.0.0.1") }
703
+
704
+ it "should add the custom DNS timeout tag" do
705
+ expect(event.get("tags")).to eq(["dns_custom_timeout"])
706
+ end
707
+ end
708
+
709
+ context "when using no tags" do
710
+ let(:config) { { "reverse" => ["message"], "tag_on_timeout" => [] } }
711
+ let(:event) { LogStash::Event.new("message" => "127.0.0.1") }
712
+
713
+ it "should not add any failure tags" do
714
+ expect(event.get("tags")).to eq(nil)
715
+ end
716
+ end
717
+
718
+ context "when logging" do
719
+
720
+ context "with debug" do
721
+ let(:config) { { "reverse" => ["message"] } }
722
+ let(:event) { LogStash::Event.new("message" => "127.0.0.1") }
723
+
724
+ before do
725
+ allow(subject.logger).to receive(:debug).with(any_args)
726
+ end
727
+
728
+ it "logs timeout exception" do
729
+ subject.filter(event)
730
+ expect(subject.logger).to have_received(:debug).with("DNS: timeout on resolving address.", :field => "message", :value => "127.0.0.1")
731
+ end
732
+ end
733
+ end
734
+ end
735
+
624
736
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-20 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement