logstash-filter-mautic 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTORS +11 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +92 -0
- data/lib/logstash/filters/mautic.rb +325 -0
- data/logstash-filter-mautic.gemspec +23 -0
- data/spec/filters/emails_spec.rb +139 -0
- data/spec/filters/forms_spec.rb +181 -0
- data/spec/filters/hit_spec.rb +132 -0
- data/spec/filters/leads_spec.rb +303 -0
- data/spec/spec_helper.rb +90 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4989fb37b968f02e249a43e4388a620314a98d3b
|
4
|
+
data.tar.gz: 81ba8474b2407c61c04effb51ebe7779c9b725f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82ae3685b774aeb7e4719136aed14ffa4522dde97a8c34ac4ca93dbbc867ba4edb9b759ed92b017618287d7c49b2ff9e7628b0d101399ebddefd4600d52d3aeb
|
7
|
+
data.tar.gz: 7e4d5beea13e819afada5b0624c060285791c97ae6a5e1bba2ea25d6694ebdda58bb4feff4453bda1527cce6b0ed29d1ea05a84902e1f769b2802bcb53c9d888
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
3
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
4
|
+
- Dependency on logstash-core update to 2.0
|
5
|
+
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Aaron Mildenstein (untergeek)
|
6
|
+
* Pier-Hugues Pellerin (ph)
|
7
|
+
|
8
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
9
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
10
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
11
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Build
|
4
|
+
Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-example-unit/)
|
5
|
+
|
6
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
7
|
+
|
8
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
9
|
+
|
10
|
+
|
11
|
+
1. Install this plugin using
|
12
|
+
```
|
13
|
+
./plugin install logstash-filter-mautic
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
2. Setup your Logstash configuration like so
|
18
|
+
|
19
|
+
```
|
20
|
+
input {
|
21
|
+
http {
|
22
|
+
host => "127.0.0.1"
|
23
|
+
port => "5543"
|
24
|
+
type => "mautic-lead"
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
28
|
+
filter {
|
29
|
+
|
30
|
+
if [type] == "mautic-lead" {
|
31
|
+
mautic {
|
32
|
+
source => "message"
|
33
|
+
remove_field => ["headers", "message", "host"]
|
34
|
+
}
|
35
|
+
if [type] == "lead"{
|
36
|
+
mutate {
|
37
|
+
replace => { "@timestamp" => "%{dateAdded}"}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
if [type] == "form_submission"{
|
41
|
+
mutate {
|
42
|
+
replace => { "@timestamp" => "%{dateSubmmited}"}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
if [type] == "email"{
|
46
|
+
mutate {
|
47
|
+
replace => { "@timestamp" => "%{dateSent}"}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
if [type] == "page_hit"{
|
51
|
+
mutate {
|
52
|
+
replace => { "@timestamp" => "%{dateHit}"}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
}
|
57
|
+
|
58
|
+
}
|
59
|
+
output {
|
60
|
+
if [type] == "lead" {
|
61
|
+
elasticsearch {
|
62
|
+
hosts => ["localhost:9200"]
|
63
|
+
index => ["mautic-leads"]
|
64
|
+
#document_id => "%{[leadid]}"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
else if [type] == "form_submission" {
|
68
|
+
elasticsearch {
|
69
|
+
hosts => ["localhost:9200"]
|
70
|
+
index => ["mautic-leads"]
|
71
|
+
document_id => "F%{[leadid]}-%{[form][id]}-%{[submissionid]}"
|
72
|
+
routing => "%{[leadid]}"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else if [type] == "page_hit" {
|
76
|
+
elasticsearch {
|
77
|
+
hosts => ["localhost:9200"]
|
78
|
+
index => ["mautic-leads"]
|
79
|
+
routing => "%{[leadid]}"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
else if [type] == "email" {
|
83
|
+
elasticsearch {
|
84
|
+
hosts => ["localhost:9200"]
|
85
|
+
index => ["mautic-leads"]
|
86
|
+
document_id => "E%{[leadid]}-%{[email][id]}-%{[emailopenid]}"
|
87
|
+
routing => "%{[leadid]}"
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
```
|
@@ -0,0 +1,325 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "logstash/json"
|
5
|
+
require "logstash/timestamp"
|
6
|
+
# This example filter will replace the contents of the default
|
7
|
+
# message field with whatever you specify in the configuration.
|
8
|
+
#
|
9
|
+
# It is only intended to be used as an example.
|
10
|
+
class LogStash::Filters::Mautic < LogStash::Filters::Base
|
11
|
+
|
12
|
+
# Setting the config_name here is required. This is how you
|
13
|
+
# configure this filter from your Logstash config.
|
14
|
+
#
|
15
|
+
# filter {
|
16
|
+
# example {
|
17
|
+
# message => "My message..."
|
18
|
+
# }
|
19
|
+
# }
|
20
|
+
#
|
21
|
+
config_name "mautic"
|
22
|
+
|
23
|
+
# Replace the message with this value.
|
24
|
+
config :source, :validate => :string, :required => true
|
25
|
+
config :tag_on_failure, :validate => :array, :default => ["_mauticparsefailure"]
|
26
|
+
|
27
|
+
|
28
|
+
public
|
29
|
+
def register
|
30
|
+
# Add instance variables
|
31
|
+
end # def register
|
32
|
+
|
33
|
+
public
|
34
|
+
def filter(event)
|
35
|
+
|
36
|
+
begin
|
37
|
+
json_data = LogStash::Json.load(event[@source])
|
38
|
+
rescue => e
|
39
|
+
tag = "_jsonparsefailure"
|
40
|
+
event["tags"] ||= []
|
41
|
+
event["tags"] << tag unless event["tags"].include?(tag)
|
42
|
+
@logger.warn("Trouble parsing json", :source => @source,
|
43
|
+
:raw => event[@source], :exception => e)
|
44
|
+
@logger.warn("Trouble parsing json", :exception => e)
|
45
|
+
return
|
46
|
+
end
|
47
|
+
tag = "_mauticparsefailure"
|
48
|
+
if json_data
|
49
|
+
# Replace the event message with our message as configured in the
|
50
|
+
# config file.
|
51
|
+
if json_data.is_a?(Hash)
|
52
|
+
matches = json_data.select{|k,v| k =~ /mautic.lead_post_save_update|mautic.lead_post_save_new|mautic.lead_points_change/}
|
53
|
+
end
|
54
|
+
if matches
|
55
|
+
matches.each do |k,v|
|
56
|
+
if v.is_a?(Hash) ##############Go here if it is a JSON object
|
57
|
+
|
58
|
+
parsed_data = processNewUpdateLead(v,k)
|
59
|
+
|
60
|
+
event_cloned = event.clone
|
61
|
+
event_cloned.timestamp = parsed_data['dateAdded']
|
62
|
+
|
63
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
64
|
+
event_cloned[k1] = v1
|
65
|
+
end
|
66
|
+
|
67
|
+
filter_matched(event_cloned)
|
68
|
+
yield event_cloned
|
69
|
+
else
|
70
|
+
v.each do |k2,v2| ######################## Go here if it is JSON array
|
71
|
+
|
72
|
+
parsed_data = processNewUpdateLead(k2,k)
|
73
|
+
|
74
|
+
event_cloned = event.clone
|
75
|
+
event_cloned.timestamp = parsed_data['dateAdded']
|
76
|
+
|
77
|
+
|
78
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
79
|
+
event_cloned[k1] = v1
|
80
|
+
end
|
81
|
+
|
82
|
+
filter_matched(event_cloned)
|
83
|
+
yield event_cloned
|
84
|
+
end # end loop
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end # end if
|
88
|
+
|
89
|
+
if json_data['mautic.email_on_open']
|
90
|
+
if json_data['mautic.email_on_open'].is_a?(Hash)
|
91
|
+
parsed_data = processEmail(json_data['mautic.email_on_open'])
|
92
|
+
|
93
|
+
event_cloned = event.clone
|
94
|
+
event_cloned.timestamp = parsed_data['dateSent']
|
95
|
+
|
96
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
97
|
+
event_cloned[k1] = v1
|
98
|
+
end
|
99
|
+
|
100
|
+
filter_matched(event_cloned)
|
101
|
+
yield event_cloned
|
102
|
+
|
103
|
+
else
|
104
|
+
json_data['mautic.email_on_open'].each do |value|
|
105
|
+
parsed_data = processEmail(value)
|
106
|
+
|
107
|
+
event_cloned = event.clone
|
108
|
+
event_cloned.timestamp = parsed_data['dateSent']
|
109
|
+
|
110
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
111
|
+
event_cloned[k1] = v1
|
112
|
+
end
|
113
|
+
|
114
|
+
filter_matched(event_cloned)
|
115
|
+
yield event_cloned
|
116
|
+
|
117
|
+
end # end loop
|
118
|
+
end
|
119
|
+
end # end if
|
120
|
+
|
121
|
+
if json_data['mautic.form_on_submit']
|
122
|
+
|
123
|
+
if json_data['mautic.form_on_submit'].is_a?(Array)
|
124
|
+
json_data['mautic.form_on_submit'].each do |value|
|
125
|
+
parsed_data = processForm(value)
|
126
|
+
|
127
|
+
event_cloned = event.clone
|
128
|
+
event_cloned.timestamp = parsed_data['dateSubmitted']
|
129
|
+
|
130
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
131
|
+
event_cloned[k1] = v1
|
132
|
+
end
|
133
|
+
|
134
|
+
filter_matched(event_cloned)
|
135
|
+
yield event_cloned
|
136
|
+
end # end loop
|
137
|
+
else
|
138
|
+
parsed_data = processForm(json_data['mautic.form_on_submit'])
|
139
|
+
|
140
|
+
event_cloned = event.clone
|
141
|
+
event_cloned.timestamp = parsed_data['dateSubmitted']
|
142
|
+
|
143
|
+
|
144
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
145
|
+
event_cloned[k1] = v1
|
146
|
+
end
|
147
|
+
|
148
|
+
filter_matched(event_cloned)
|
149
|
+
yield event_cloned
|
150
|
+
end # end if
|
151
|
+
end # end if
|
152
|
+
|
153
|
+
if json_data['mautic.page_on_hit']
|
154
|
+
if json_data['mautic.page_on_hit'].is_a?(Array)
|
155
|
+
json_data['mautic.page_on_hit'].each do |value|
|
156
|
+
parsed_data = processHit(value)
|
157
|
+
|
158
|
+
event_cloned = event.clone
|
159
|
+
event_cloned.timestamp = parsed_data['dateHit']
|
160
|
+
|
161
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
162
|
+
event_cloned[k1] = v1
|
163
|
+
end
|
164
|
+
|
165
|
+
filter_matched(event_cloned)
|
166
|
+
yield event_cloned
|
167
|
+
end # end loop
|
168
|
+
else
|
169
|
+
parsed_data = processHit(json_data['mautic.page_on_hit'])
|
170
|
+
|
171
|
+
event_cloned = event.clone
|
172
|
+
event_cloned.timestamp = parsed_data['dateHit']
|
173
|
+
|
174
|
+
parsed_data.each do |k1,v1| ## Pull in the data
|
175
|
+
event_cloned[k1] = v1
|
176
|
+
end
|
177
|
+
filter_matched(event_cloned)
|
178
|
+
yield event_cloned
|
179
|
+
end # end if
|
180
|
+
end
|
181
|
+
|
182
|
+
end # end if
|
183
|
+
|
184
|
+
# filter_matched should go in the last line of our successful code
|
185
|
+
event.cancel #As we have cloned the event we need to cancel the original one
|
186
|
+
end # def filter
|
187
|
+
|
188
|
+
def processHit(json_data)
|
189
|
+
parsed_data = json_data['hit']
|
190
|
+
parsed_data['leadid'] = parsed_data['lead']['id'].to_i
|
191
|
+
parsed_data.delete('lead')
|
192
|
+
|
193
|
+
|
194
|
+
parsed_data['parent'] = parsed_data['leadid']
|
195
|
+
parsed_data['type'] = "page_hit"
|
196
|
+
|
197
|
+
if parsed_data['dateHit']
|
198
|
+
parsed_data['dateHit'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateHit'])
|
199
|
+
end
|
200
|
+
|
201
|
+
if parsed_data['dateLeft']
|
202
|
+
parsed_data['dateLeft'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateLeft'])
|
203
|
+
end
|
204
|
+
return parsed_data
|
205
|
+
end
|
206
|
+
|
207
|
+
def processForm(json_data)
|
208
|
+
parsed_data = json_data['submission']
|
209
|
+
parsed_data['leadid'] = parsed_data['lead']['id'].to_i
|
210
|
+
parsed_data['submissionid'] = parsed_data['id']
|
211
|
+
|
212
|
+
|
213
|
+
parsed_data.delete('id')
|
214
|
+
parsed_data.delete('lead')
|
215
|
+
parsed_data.delete('ipAddress')
|
216
|
+
|
217
|
+
if parsed_data['dateSubmitted']
|
218
|
+
parsed_data['dateSubmitted'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateSubmitted'])
|
219
|
+
end
|
220
|
+
|
221
|
+
parsed_data['type'] = "form_submission"
|
222
|
+
parsed_data['parent'] = parsed_data['leadid']
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
# num =0
|
227
|
+
# parsed_data["ipAddresses"] = []
|
228
|
+
# parsed_data['ipAddresses'].each do |k2,v2|
|
229
|
+
# formData['ipAddresses'][num] = k2
|
230
|
+
# num +=1
|
231
|
+
# end
|
232
|
+
return parsed_data
|
233
|
+
end
|
234
|
+
|
235
|
+
def processNewUpdateLead(json_data,key)
|
236
|
+
parsed_data = newLeadFilter(json_data)
|
237
|
+
parsed_data['leadid'] = parsed_data['id'].to_i
|
238
|
+
parsed_data.delete('id')
|
239
|
+
|
240
|
+
if parsed_data['dateIdentified'] != nil
|
241
|
+
parsed_data['dateIdentified'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateIdentified'])
|
242
|
+
end
|
243
|
+
|
244
|
+
if parsed_data['dateAdded'] != nil
|
245
|
+
parsed_data['dateAdded'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateAdded'])
|
246
|
+
end
|
247
|
+
|
248
|
+
if parsed_data['dateModified'] != nil
|
249
|
+
parsed_data['dateModified'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateModified'])
|
250
|
+
end
|
251
|
+
|
252
|
+
parsed_data['type'] = "lead"
|
253
|
+
return parsed_data
|
254
|
+
end
|
255
|
+
|
256
|
+
def processEmail(json_data)
|
257
|
+
parsed_data = json_data['stat']
|
258
|
+
parsed_data['leadid'] = parsed_data['lead']['id'].to_i
|
259
|
+
parsed_data['emailopenid'] = parsed_data['id']
|
260
|
+
|
261
|
+
parsed_data.delete("lead")
|
262
|
+
parsed_data.delete("id")
|
263
|
+
|
264
|
+
parsed_data['type'] = "email"
|
265
|
+
parsed_data['parent'] = parsed_data['leadid']
|
266
|
+
|
267
|
+
|
268
|
+
if parsed_data['dateSent'] != nil
|
269
|
+
parsed_data['dateSent'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateSent'])
|
270
|
+
end
|
271
|
+
|
272
|
+
if parsed_data['dateRead'] != nil
|
273
|
+
parsed_data['dateRead'] = LogStash::Timestamp.parse_iso8601(parsed_data['dateRead'])
|
274
|
+
end
|
275
|
+
if parsed_data['lastOpened'] != nil
|
276
|
+
parsed_data['lastOpened'] = LogStash::Timestamp.parse_iso8601(parsed_data['lastOpened'])
|
277
|
+
end
|
278
|
+
|
279
|
+
return parsed_data
|
280
|
+
end
|
281
|
+
|
282
|
+
def newLeadFilter(json_data)
|
283
|
+
|
284
|
+
formData = {}
|
285
|
+
json_data["lead"].each do |k1,v1|
|
286
|
+
if k1 === "ipAddresses"
|
287
|
+
num = 0
|
288
|
+
formData["ipAddresses"] = []
|
289
|
+
v1.each do |k2,v2|
|
290
|
+
formData[k1][num] = k2
|
291
|
+
num +=1
|
292
|
+
end
|
293
|
+
elsif k1 === "tags"
|
294
|
+
num =0
|
295
|
+
formData["mautic_tags"] = []
|
296
|
+
v1.each do |v2|
|
297
|
+
formData["mautic_tags"][num] =v2
|
298
|
+
num +=1
|
299
|
+
end
|
300
|
+
elsif v1.is_a?(Hash)
|
301
|
+
v1.each do |k2,v2|
|
302
|
+
if v2.is_a?(Hash)
|
303
|
+
v2.each do |k3,v3|
|
304
|
+
if v3.is_a?(Hash)
|
305
|
+
v3.each do |k4,v4|
|
306
|
+
if v4 != nil and k4 === 'value'
|
307
|
+
formData[k3] = v4
|
308
|
+
end
|
309
|
+
end
|
310
|
+
elsif v3 != nil
|
311
|
+
formData[k3] = v3
|
312
|
+
end
|
313
|
+
end
|
314
|
+
elsif v2 != nil and !(k2 === 'fields') and !(k1 === 'owner')
|
315
|
+
formData[k2] = v2
|
316
|
+
end
|
317
|
+
end
|
318
|
+
elsif v1 != nil
|
319
|
+
formData[k1] = v1
|
320
|
+
end
|
321
|
+
end
|
322
|
+
return formData
|
323
|
+
|
324
|
+
end
|
325
|
+
end # class LogStash::Filters::Mautic
|