Skip to content

Commit a01f322

Browse files
authored
Test: fix and add ECS compatibility specs (#310)
1 parent 5b9a287 commit a01f322

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

spec/patterns/core_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
require "spec_helper"
33
require "logstash/patterns/core"
44

5-
describe "SYSLOGLINE" do
5+
describe_pattern "SYSLOGLINE", ['legacy', 'ecs-v1'] do
6+
7+
let(:message) { "Mar 16 00:01:25 evita postfix/smtpd[1713]: connect from camomile.cloud9.net[168.100.1.3]" }
68

7-
let(:value) { "Mar 16 00:01:25 evita postfix/smtpd[1713]: connect from camomile.cloud9.net[168.100.1.3]" }
8-
let(:grok) { grok_match(subject, value) }
99
it "a pattern pass the grok expression" do
1010
expect(grok).to pass
1111
end
1212

13-
it "matches a simple message" do
14-
expect(subject).to match(value)
15-
end
16-
1713
it "generates the program field" do
18-
expect(grok_match(subject, value)).to include("program" => "postfix/smtpd")
14+
if ecs_compatibility?
15+
expect(grok).to include("process" => hash_including('name' => 'postfix/smtpd'))
16+
else
17+
expect(grok).to include("program" => "postfix/smtpd")
18+
end
1919
end
2020

2121
end

spec/patterns/redis_spec.rb

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134

135135
end
136136

137-
describe_pattern "REDISMONLOG" do
137+
describe_pattern "REDISMONLOG", [ 'legacy', 'ecs-v1' ] do
138138

139139
context 'two param command' do
140140

@@ -149,23 +149,43 @@
149149
end
150150

151151
it "generates the database field" do
152-
expect(grok).to include("database" => "0")
152+
if ecs_compatibility?
153+
expect(grok).to include("redis" => hash_including('database' => hash_including('id' => '0')))
154+
else
155+
expect(grok).to include("database" => "0")
156+
end
153157
end
154158

155159
it "generates the client field" do
156-
expect(grok).to include("client" => "127.0.0.1")
160+
if ecs_compatibility?
161+
expect(grok).to include("client" => hash_including('ip' => '127.0.0.1'))
162+
else
163+
expect(grok).to include("client" => "127.0.0.1")
164+
end
157165
end
158166

159167
it "generates the port field" do
160-
expect(grok).to include("port" => "39404")
168+
if ecs_compatibility?
169+
expect(grok).to include("client" => hash_including('port' => 39404))
170+
else
171+
expect(grok).to include("port" => "39404")
172+
end
161173
end
162174

163175
it "generates the command field" do
164-
expect(grok).to include("command" => "rpush")
176+
if ecs_compatibility?
177+
expect(grok).to include("redis" => hash_including('command' => hash_including('name' => 'rpush')))
178+
else
179+
expect(grok).to include("command" => "rpush")
180+
end
165181
end
166182

167183
it "generates the params field" do
168-
expect(grok).to include("params" => "\"my:special:key\" \"{\\\"data\\\":\"cdr\\\",\\\"payload\\\":\\\"json\\\"}\"")
184+
if ecs_compatibility?
185+
expect(grok).to include("redis" => hash_including('command' => hash_including('args' => "\"my:special:key\" \"{\\\"data\\\":\"cdr\\\",\\\"payload\\\":\\\"json\\\"}\"")))
186+
else
187+
expect(grok).to include("params" => "\"my:special:key\" \"{\\\"data\\\":\"cdr\\\",\\\"payload\\\":\\\"json\\\"}\"")
188+
end
169189
end
170190

171191
end
@@ -183,23 +203,43 @@
183203
end
184204

185205
it "generates the database field" do
186-
expect(grok).to include("database" => "15")
206+
if ecs_compatibility?
207+
expect(grok).to include("redis" => hash_including('database' => hash_including('id' => '15')))
208+
else
209+
expect(grok).to include("database" => "15")
210+
end
187211
end
188212

189213
it "generates the client field" do
190-
expect(grok).to include("client" => "195.168.1.1")
214+
if ecs_compatibility?
215+
expect(grok).to include("client" => hash_including('ip' => '195.168.1.1'))
216+
else
217+
expect(grok).to include("client" => "195.168.1.1")
218+
end
191219
end
192220

193221
it "generates the port field" do
194-
expect(grok).to include("port" => "52500")
222+
if ecs_compatibility?
223+
expect(grok).to include("client" => hash_including('port' => 52500))
224+
else
225+
expect(grok).to include("port" => "52500")
226+
end
195227
end
196228

197229
it "generates the command field" do
198-
expect(grok).to include("command" => "intentionally")
230+
if ecs_compatibility?
231+
expect(grok).to include("redis" => hash_including('command' => hash_including('name' => 'intentionally')))
232+
else
233+
expect(grok).to include("command" => "intentionally")
234+
end
199235
end
200236

201237
it "generates the params field" do
202-
expect(grok).to include("params" => "\"broken\" \"variadic\" \"log\" \"entry\"")
238+
if ecs_compatibility?
239+
expect(grok).to include("redis" => hash_including('command' => hash_including('args' => "\"broken\" \"variadic\" \"log\" \"entry\"")))
240+
else
241+
expect(grok).to include("params" => "\"broken\" \"variadic\" \"log\" \"entry\"")
242+
end
203243
end
204244

205245
end

0 commit comments

Comments
 (0)