logstash-filter-phpserialize 1.0 → 1.1

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
  SHA1:
3
- metadata.gz: a3932a9341d306d9566fd430aa6519c78b7b5595
4
- data.tar.gz: 0538a0022ad134b8a4d7d0b8ac1ba2461766eaf3
3
+ metadata.gz: 6e270d256ba5929961c6ed3c7b3b0a968351a813
4
+ data.tar.gz: 4ea5454e356cf6fff18440385588188fb2c1f2ba
5
5
  SHA512:
6
- metadata.gz: 4cf09a14ddb6eb8a2e769e5831a7e291016f4efae20b7ef2938cb251a48409334d704be67c43677d7d2b839c07a219803c71baffc6486d6c8b2a61e4f29452bd
7
- data.tar.gz: b25b30061f055bc8abda8089339ad27ad749e5fdf4d1a7ce77b40e71b7200a514faeae5072d82ba24c17b0de78a554e0992f659db595a1e4fba4843437007022
6
+ metadata.gz: a09bab6fabc5821918fe547f5cd14ed20f3ca558df836e7ead803074a1f27e3459aff8a0d9de53ab73c3e7d5014031af52b8fb2c74d2970b223304b62aee0a35
7
+ data.tar.gz: 10edb10d4eab626aa3fe3d280176656a2444224218038725b9896e72c099dc1b35d892dbdf02c3fe1ab57fd29bf96ed97f59818a18ccfbdc91dc208bf9e2b689
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1
2
+ - Include proper error handling
3
+ - default target field to "message"
4
+ - Add more tests
5
+
1
6
  ## 1.0
2
7
  - Simple implementation
3
8
 
@@ -20,8 +20,8 @@ class LogStash::Filters::Phpserialize < LogStash::Filters::Base
20
20
  config_name "phpserialize"
21
21
 
22
22
  config :source, :validate => :string, :default => "message"
23
- config :target, :validate => :string
24
-
23
+ config :target, :validate => :string, :default => "message"
24
+ config :tag_on_failure, :validate => :array, :default => ["_phpunserializefailure"]
25
25
 
26
26
  public
27
27
  def register
@@ -30,10 +30,15 @@ class LogStash::Filters::Phpserialize < LogStash::Filters::Base
30
30
 
31
31
  public
32
32
  def filter(event)
33
+ source = event.get(@source)
34
+ return if source.nil?
33
35
 
34
- data = PHP.unserialize(event.get(@source))
35
- if @source
36
+ begin
37
+ data = PHP.unserialize(source)
36
38
  event.set(@target, data)
39
+ rescue StandardError
40
+ @tag_on_failure.each {|tag| event.tag(tag)}
41
+ return
37
42
  end
38
43
 
39
44
  # filter_matched should go in the last line of our successful code
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-phpserialize'
3
- s.version = '1.0'
3
+ s.version = '1.1'
4
4
  s.licenses = ['BSD-3-Clause']
5
5
  s.summary = 'Allow to decode phpserialized values'
6
6
  s.homepage = 'https://github.com/has-to-be/logstash-filter-phpserialize'
@@ -7,15 +7,72 @@ describe LogStash::Filters::Phpserialize do
7
7
  let(:config) do <<-CONFIG
8
8
  filter {
9
9
  phpserialize {
10
- target => "php"
11
10
  }
12
11
  }
13
12
  CONFIG
14
13
  end
15
14
 
16
- sample("message" => 's:11:"Hello World";') do
17
- expect(subject).to include('php')
18
- expect(subject.get('php')).to eq('Hello World')
15
+ sample('s:11:"Hello World";') do
16
+ expect(subject.get('message')).to eq('Hello World')
17
+ end
18
+ end
19
+
20
+ describe "parse empty field" do
21
+ let(:config) do <<-CONFIG
22
+ filter {
23
+ phpserialize {
24
+ }
25
+ }
26
+ CONFIG
27
+ end
28
+
29
+ sample('') do
30
+ expect(subject.get('message')).to eq('')
31
+ end
32
+ end
33
+
34
+ describe "parse non-existing field" do
35
+ let(:config) do <<-CONFIG
36
+ filter {
37
+ phpserialize {
38
+ source => "in"
39
+ }
40
+ }
41
+ CONFIG
42
+ end
43
+
44
+ sample('') do
45
+ expect(subject.get('message')).to eq('')
46
+ expect(subject.get('tags')).to be_nil
47
+ end
48
+ end
49
+
50
+ describe "parse null value" do
51
+ let(:config) do <<-CONFIG
52
+ filter {
53
+ phpserialize {
54
+ }
55
+ }
56
+ CONFIG
57
+ end
58
+
59
+ sample('N;') do
60
+ expect(subject.get('message')).to be_nil
61
+ end
62
+ end
63
+
64
+ describe "parse corrupt value" do
65
+ let(:config) do <<-CONFIG
66
+ filter {
67
+ phpserialize {
68
+ }
69
+ }
70
+ CONFIG
71
+ end
72
+
73
+ sample('Hello World') do
74
+ expect(subject.get('message')).to eq('Hello World')
75
+ expect(subject.get('tags')).to include('_phpunserializefailure')
19
76
  end
20
77
  end
21
78
 
@@ -23,16 +80,30 @@ describe LogStash::Filters::Phpserialize do
23
80
  let(:config) do <<-CONFIG
24
81
  filter {
25
82
  phpserialize {
26
- source => "php_in"
27
- target => "php_out"
83
+ source => "in"
84
+ }
85
+ }
86
+ CONFIG
87
+ end
88
+
89
+ sample("in" => 'i:42;') do
90
+ expect(subject.get('message')).to eq(42)
91
+ end
92
+ end
93
+
94
+ describe "parse into target field" do
95
+ let(:config) do <<-CONFIG
96
+ filter {
97
+ phpserialize {
98
+ target => "php"
28
99
  }
29
100
  }
30
101
  CONFIG
31
102
  end
32
103
 
33
- sample("php_in" => 'i:42;') do
34
- expect(subject).to include('php_out')
35
- expect(subject.get('php_out')).to eq(42)
104
+ sample('i:42;') do
105
+ expect(subject).to include('php')
106
+ expect(subject.get('php')).to eq(42)
36
107
  end
37
108
  end
38
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-phpserialize
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Angerer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.5.1
92
+ rubygems_version: 2.5.2
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Allow to decode phpserialized values