logstash-filter-delta 1.0.1 → 1.1.0

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
  SHA1:
3
- metadata.gz: c8c0c909e697bf09071d2d95c11a7e8f2782d176
4
- data.tar.gz: 40c3997a60da39404bb21fbb079fc841ce4ba707
3
+ metadata.gz: 1f5e44d2824a950b7d381a2769b3b4d71be155ca
4
+ data.tar.gz: 8ee30261a9d8bdbb3765dc2a10a62fd7fb3182fc
5
5
  SHA512:
6
- metadata.gz: 90593fe58f559559795b45abf45d90c3bf7c6670398d6f1536a56ae443cbc17333bb91ac7fe577416572739a8c4ac1fa142a45c965ab82bcfb906f62b9092da0
7
- data.tar.gz: d10514747b04579e102aa3a7283b91cc9118e89a4675b98553c38aba8bf449f8c10238e60fed5044f2df980bf440f6a1d94011913df7112b737874c1c637f5eb
6
+ metadata.gz: 1a3a5bd6139c7bcd1984abab12940762edfe319be5149c83ab2e291c856d0bce68ad1cb9ce2f70d3b6cb151ebd90917929b79575da5679f7d560ee3f74391064
7
+ data.tar.gz: b11c7cdb422e50d24566b6f06137fdce5b5f63267d9dc6269fd31acb9c4e1a8bbee24a864b69b320dba1e580ee71bd605bc4cb2e9e85ff9fbbab2ae55a3cc989
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.1.0
2
+ - Cast string input values to integer and float
3
+
1
4
  ## 1.0.1
2
5
  - Add support for Logstash 2.4 and plugin API 1.0
3
6
 
@@ -33,8 +33,20 @@ class LogStash::Filters::Delta < LogStash::Filters::Base
33
33
  end
34
34
 
35
35
  private
36
- def is_numeric(value)
37
- return (value.is_a?(Integer) or value.is_a?(Float))
36
+ def cast_string_to_numeric(value)
37
+ begin
38
+ return Integer(value)
39
+ rescue ArgumentError
40
+ return Float(value)
41
+ end
42
+ end
43
+
44
+ private
45
+ def ensure_numeric(value)
46
+ if (value.is_a? Float or value.is_a? Integer)
47
+ return value
48
+ end
49
+ return cast_string_to_numeric(value)
38
50
  end
39
51
 
40
52
  public
@@ -54,15 +66,12 @@ class LogStash::Filters::Delta < LogStash::Filters::Base
54
66
  return filter_failed(event, @tag_on_failure)
55
67
  end
56
68
 
57
- to = event.get(to)
58
- from = event.get(from)
59
-
60
- if !is_numeric(to) or !is_numeric(from)
69
+ begin
70
+ delta = ensure_numeric(event.get(to)) - ensure_numeric(event.get(from))
71
+ rescue ArgumentError
61
72
  return filter_failed(event, @tag_on_failure)
62
73
  end
63
74
 
64
- delta = to - from
65
-
66
75
  if @min and delta < @min
67
76
  return filter_failed(event, @tag_on_min_failure)
68
77
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-delta'
3
- s.version = '1.0.1'
3
+ s.version = '1.1.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "This filter helps you to calculate integer or float delta."
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using `logstash-plugin install logstash-filter-delta`. This gem is not a stand-alone program"
@@ -29,6 +29,28 @@ describe LogStash::Filters::Delta do
29
29
  end
30
30
  end
31
31
 
32
+ describe "Test string casting" do
33
+ sample("start" => "100", "end" => "250.5") do
34
+ expect(subject.get("output")).to eq(150.5)
35
+ expect(subject.get("tags")).to eq(nil)
36
+ end
37
+
38
+ sample("start" => "100.3", "end" => "250.5") do
39
+ expect(subject.get("output")).to eq(150.2)
40
+ expect(subject.get("tags")).to eq(nil)
41
+ end
42
+
43
+ sample("start" => "100", "end" => "250") do
44
+ expect(subject.get("output")).to eq(150)
45
+ expect(subject.get("tags")).to eq(nil)
46
+ end
47
+
48
+ sample("start" => "abc", "end" => "250") do
49
+ expect(subject.get("output")).to eq(nil)
50
+ expect(subject.get("tags")).to eq(["_deltafailure"])
51
+ end
52
+ end
53
+
32
54
  describe "Write delta to field" do
33
55
  sample("start" => 100, "end" => 250) do
34
56
  expect(subject.get("output")).to eq(150)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-delta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Tisäter