logstash-output-email 4.0.6 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/LICENSE +1 -1
- data/docs/index.asciidoc +21 -0
- data/lib/logstash/outputs/email.rb +28 -6
- data/logstash-output-email.gemspec +5 -2
- data/spec/fixtures/template.mustache +1 -0
- data/spec/outputs/email_spec.rb +15 -0
- data/spec/spec_helper.rb +14 -0
- metadata +37 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fba3309aa6431187a31571b6db5ffeb5efd80c988b0a6ddf04c81b0646b6d46f
|
4
|
+
data.tar.gz: e0be2186cdb511b14a10a8d0489583a09d3262d5cc36b13c01eb7466b508d6f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce3eeebfcc341aa54ae7f4b6345884e98f220c95f92c45d0f15c88ac281711aaf5bb8812265ac9f91a3d2560e3cdaf595fbfee0665581710844f4843f22cbfa0
|
7
|
+
data.tar.gz: 6fc5516f97137e2d5030ae08021fcb3d3e18186167ce767764710ef40e91dcf093eac0c3346e8e6211aceb4ef1494395418f1bcc252f1a2bfc88826ef567227e
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/docs/index.asciidoc
CHANGED
@@ -33,6 +33,7 @@ output {
|
|
33
33
|
from => 'monitor@example.com'
|
34
34
|
subject => 'Alert - %{title}'
|
35
35
|
body => "Tags: %{tags}\\n\\Content:\\n%{message}"
|
36
|
+
template_file => "/tmp/email_template.mustache"
|
36
37
|
domain => 'mail.example.com'
|
37
38
|
port => 25
|
38
39
|
}
|
@@ -53,6 +54,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
53
54
|
| <<plugins-{type}s-{plugin}-authentication>> |<<string,string>>|No
|
54
55
|
| <<plugins-{type}s-{plugin}-body>> |<<string,string>>|No
|
55
56
|
| <<plugins-{type}s-{plugin}-cc>> |<<string,string>>|No
|
57
|
+
| <<plugins-{type}s-{plugin}-bcc>> |<<string,string>>|No
|
56
58
|
| <<plugins-{type}s-{plugin}-contenttype>> |<<string,string>>|No
|
57
59
|
| <<plugins-{type}s-{plugin}-debug>> |<<boolean,boolean>>|No
|
58
60
|
| <<plugins-{type}s-{plugin}-domain>> |<<string,string>>|No
|
@@ -66,6 +68,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
|
|
66
68
|
| <<plugins-{type}s-{plugin}-use_tls>> |<<boolean,boolean>>|No
|
67
69
|
| <<plugins-{type}s-{plugin}-username>> |<<string,string>>|No
|
68
70
|
| <<plugins-{type}s-{plugin}-via>> |<<string,string>>|No
|
71
|
+
| <<plugins-{type}s-{plugin}-template_file>> |<<path,path>>|No
|
69
72
|
|=======================================================================
|
70
73
|
|
71
74
|
Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
|
@@ -116,6 +119,16 @@ The fully-qualified email address(es) to include as cc: address(es).
|
|
116
119
|
This field also accepts a comma-separated string of addresses, for example:
|
117
120
|
`"me@example.com, you@example.com"`
|
118
121
|
|
122
|
+
[id="plugins-{type}s-{plugin}-bcc"]
|
123
|
+
===== `bcc`
|
124
|
+
|
125
|
+
* Value type is <<string,string>>
|
126
|
+
* There is no default value for this setting.
|
127
|
+
|
128
|
+
The fully-qualified email address(es) to include as bcc: address(es).
|
129
|
+
|
130
|
+
This field accepts several addresses like cc.
|
131
|
+
|
119
132
|
[id="plugins-{type}s-{plugin}-contenttype"]
|
120
133
|
===== `contenttype`
|
121
134
|
|
@@ -229,6 +242,14 @@ Username to authenticate with the server
|
|
229
242
|
|
230
243
|
How Logstash should send the email, either via SMTP or by invoking sendmail.
|
231
244
|
|
245
|
+
[id="plugins-{type}s-{plugin}-template_file"]
|
246
|
+
===== `template_file`
|
247
|
+
|
248
|
+
* Value type is <<path,path>>
|
249
|
+
* There is no default value for this setting.
|
250
|
+
|
251
|
+
Path of a [Mustache templating](https://mustache.github.io/) file used for email templating. See example in test fixture.
|
252
|
+
Can be used with `body` to send multi-part emails. Takes precedence over `htmlBody`.
|
232
253
|
|
233
254
|
|
234
255
|
[id="plugins-{type}s-{plugin}-common-options"]
|
@@ -46,6 +46,9 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
46
46
|
# This field also accepts a comma-separated string of addresses, for example:
|
47
47
|
# `"me@example.com, you@example.com"`
|
48
48
|
config :cc, :validate => :string
|
49
|
+
|
50
|
+
# Same as cc but in blind carbon
|
51
|
+
config :bcc, :validate => :string
|
49
52
|
|
50
53
|
# How Logstash should send the email, either via SMTP or by invoking sendmail.
|
51
54
|
config :via, :validate => :string, :default => "smtp"
|
@@ -80,6 +83,9 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
80
83
|
# Body for the email - plain text only.
|
81
84
|
config :body, :validate => :string, :default => ""
|
82
85
|
|
86
|
+
# Email template file to be used - as mustache template.
|
87
|
+
config :template_file, :validate => :path
|
88
|
+
|
83
89
|
# HTML Body for the email, which may contain HTML markup.
|
84
90
|
config :htmlbody, :validate => :string, :default => ""
|
85
91
|
|
@@ -93,6 +99,7 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
93
99
|
public
|
94
100
|
def register
|
95
101
|
require "mail"
|
102
|
+
require "mustache"
|
96
103
|
|
97
104
|
options = {
|
98
105
|
:address => @address,
|
@@ -118,6 +125,7 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
118
125
|
delivery_method :@via, options
|
119
126
|
end
|
120
127
|
end # @via tests
|
128
|
+
@htmlTemplate = File.open(@template_file, "r").read unless @template_file.nil?
|
121
129
|
@logger.debug("Email Output Registered!", :config => options, :via => @via)
|
122
130
|
end # def register
|
123
131
|
|
@@ -125,10 +133,11 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
125
133
|
def receive(event)
|
126
134
|
|
127
135
|
|
128
|
-
@logger.debug? and @logger.debug("Creating mail with these settings : ", :via => @via, :options => @options, :from => @from, :to => @to, :cc => @cc, :subject => @subject, :body => @body, :content_type => @contenttype, :htmlbody => @htmlbody, :attachments => @attachments
|
136
|
+
@logger.debug? and @logger.debug("Creating mail with these settings : ", :via => @via, :options => @options, :from => @from, :to => @to, :cc => @cc, :bcc => @bcc, :subject => @subject, :body => @body, :content_type => @contenttype, :htmlbody => @htmlbody, :attachments => @attachments)
|
129
137
|
formatedSubject = event.sprintf(@subject)
|
130
138
|
formattedBody = event.sprintf(@body)
|
131
139
|
formattedHtmlBody = event.sprintf(@htmlbody)
|
140
|
+
|
132
141
|
mail = Mail.new
|
133
142
|
mail.from = event.sprintf(@from)
|
134
143
|
mail.to = event.sprintf(@to)
|
@@ -136,25 +145,38 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
|
|
136
145
|
mail.reply_to = event.sprintf(@replyto)
|
137
146
|
end
|
138
147
|
mail.cc = event.sprintf(@cc)
|
148
|
+
mail.bcc = event.sprintf(@bcc)
|
139
149
|
mail.subject = formatedSubject
|
140
|
-
|
150
|
+
|
151
|
+
if @htmlbody.empty? and @template_file.nil?
|
141
152
|
formattedBody.gsub!(/\\n/, "\n") # Take new line in the email
|
142
153
|
mail.body = formattedBody
|
143
154
|
else
|
155
|
+
# This handles multipart emails
|
156
|
+
# cf: https://github.com/mikel/mail/#writing-and-sending-a-multipartalternative-html-and-text-email
|
144
157
|
mail.text_part = Mail::Part.new do
|
145
158
|
content_type "text/plain; charset=UTF-8"
|
146
159
|
formattedBody.gsub!(/\\n/, "\n") # Take new line in the email
|
147
160
|
body formattedBody
|
148
161
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
162
|
+
|
163
|
+
if @template_file.nil?
|
164
|
+
mail.html_part = Mail::Part.new do
|
165
|
+
content_type "text/html; charset=UTF-8"
|
166
|
+
body formattedHtmlBody
|
167
|
+
end
|
168
|
+
else
|
169
|
+
templatedHtmlBody = Mustache.render(@htmlTemplate, event.to_hash)
|
170
|
+
mail.html_part = Mail::Part.new do
|
171
|
+
content_type "text/html; charset=UTF-8"
|
172
|
+
body templatedHtmlBody
|
173
|
+
end
|
152
174
|
end
|
153
175
|
end
|
154
176
|
@attachments.each do |fileLocation|
|
155
177
|
mail.add_file(fileLocation)
|
156
178
|
end # end @attachments.each
|
157
|
-
@logger.debug? and @logger.debug("Sending mail with these values : ", :from => mail.from, :to => mail.to, :cc => mail.cc, :subject => mail.subject)
|
179
|
+
@logger.debug? and @logger.debug("Sending mail with these values : ", :from => mail.from, :to => mail.to, :cc => mail.cc, :bcc => mail.bcc, :subject => mail.subject)
|
158
180
|
begin
|
159
181
|
mail.deliver!
|
160
182
|
rescue StandardError => e
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-output-email'
|
4
|
-
s.version = '4.0
|
4
|
+
s.version = '4.1.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
|
-
s.summary = "
|
6
|
+
s.summary = "Sends email to a specified address when output is received"
|
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"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
@@ -26,9 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
# mime-types >= 3 require ruby 2.0 support
|
27
27
|
s.add_runtime_dependency 'mime-types', '< 3'
|
28
28
|
|
29
|
+
s.add_runtime_dependency 'mustache', '>= 0.99.8'
|
30
|
+
|
29
31
|
s.add_development_dependency 'logstash-devutils'
|
30
32
|
s.add_development_dependency 'rumbster'
|
31
33
|
s.add_development_dependency 'logstash-input-generator'
|
34
|
+
s.add_development_dependency 'gserver'
|
32
35
|
|
33
36
|
end
|
34
37
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>{{message}}</h1>
|
data/spec/outputs/email_spec.rb
CHANGED
@@ -89,5 +89,20 @@ describe "outputs/email" do
|
|
89
89
|
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
context "mustache template for email body" do
|
94
|
+
it "uses the template file" do
|
95
|
+
subject = plugin.new("to" => "me@host",
|
96
|
+
"subject" => "Hello World",
|
97
|
+
"template_file" => File.dirname(__FILE__) + "/../fixtures/template.mustache",
|
98
|
+
"port" => port)
|
99
|
+
subject.register
|
100
|
+
subject.receive(LogStash::Event.new("message" => "hello"))
|
101
|
+
|
102
|
+
expect(message_observer.messages.size).to eq(1)
|
103
|
+
expect(message_observer.messages[0].subject).to eq("Hello World")
|
104
|
+
expect(message_observer.messages[0].body.decoded).to eq(craft_multi_part_email('', '<h1>hello</h1>', message_observer.messages[0].content_type))
|
105
|
+
end
|
106
|
+
end
|
92
107
|
end
|
93
108
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,3 +12,17 @@ class LogStash::Filters::NOOP < LogStash::Filters::Base
|
|
12
12
|
filter_matched(event)
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
def craft_multi_part_email(body, htmlbody, content_type)
|
17
|
+
charset = "charset=UTF-8"
|
18
|
+
content_encoding = "Content-Transfer-Encoding: 7bit"
|
19
|
+
|
20
|
+
# Have to get the generated part of the header, eg:
|
21
|
+
# --==_mimepart_5a462a1fda04b_efe7d032127
|
22
|
+
mimetype = content_type.split('; ')[1][10..-2]
|
23
|
+
|
24
|
+
plain_header = "\n--#{mimetype}\nContent-Type: text/plain;\n #{charset}\n#{content_encoding}\n\n"
|
25
|
+
html_header = "\n--#{mimetype}\nContent-Type: text/html;\n #{charset}\n#{content_encoding}\n\n"
|
26
|
+
|
27
|
+
"#{plain_header}#{body}#{html_header}#{htmlbody}\n\n--#{mimetype}--\n"
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.99.8
|
67
|
+
name: mustache
|
68
|
+
prerelease: false
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.99.8
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
requirement: !ruby/object:Gem::Requirement
|
63
77
|
requirements:
|
@@ -100,7 +114,23 @@ dependencies:
|
|
100
114
|
- - ">="
|
101
115
|
- !ruby/object:Gem::Version
|
102
116
|
version: '0'
|
103
|
-
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
name: gserver
|
124
|
+
prerelease: false
|
125
|
+
type: :development
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
132
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
133
|
+
gem is not a stand-alone program
|
104
134
|
email: info@elastic.co
|
105
135
|
executables: []
|
106
136
|
extensions: []
|
@@ -115,6 +145,7 @@ files:
|
|
115
145
|
- docs/index.asciidoc
|
116
146
|
- lib/logstash/outputs/email.rb
|
117
147
|
- logstash-output-email.gemspec
|
148
|
+
- spec/fixtures/template.mustache
|
118
149
|
- spec/outputs/email_spec.rb
|
119
150
|
- spec/spec_helper.rb
|
120
151
|
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
@@ -139,10 +170,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
170
|
version: '0'
|
140
171
|
requirements: []
|
141
172
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.6.13
|
143
174
|
signing_key:
|
144
175
|
specification_version: 4
|
145
|
-
summary:
|
176
|
+
summary: Sends email to a specified address when output is received
|
146
177
|
test_files:
|
178
|
+
- spec/fixtures/template.mustache
|
147
179
|
- spec/outputs/email_spec.rb
|
148
180
|
- spec/spec_helper.rb
|