sensu-plugins-mailer 2.0.1 → 2.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
- SHA256:
3
- metadata.gz: 8ad181e78c5e2610cd7e1c71df58c691abfd61a79d6a5a0d204be3c9f2678ef3
4
- data.tar.gz: d553fba10bcb51805773fbc93a0403b4b020cf39850b35265886d13e2bf44c4f
2
+ SHA1:
3
+ metadata.gz: d530c35c2b3418da88c519c84bc2e1004b950408
4
+ data.tar.gz: 81e19d4ca9159681bd0795ee179a5c0a083bcb62
5
5
  SHA512:
6
- metadata.gz: 57cf094ec41772b4299865f4ecc5bcf15b9d5ba9a57820511c559516b92b89a975fe03a8b635651a0b1e738f17d87d1e38e7e821d8e0e2ff30baf4bdad3d0fee
7
- data.tar.gz: 14a247af62a6d06a6dcfd3e2d9c217246b1315cbe99fdd373903f30e9c1c2105d0760f42b2d7f3c8e5476592f548e7239598376f07a22eb08557d84ce5f1e14e
6
+ metadata.gz: 5367e78f2db13246bf4f0b50d2cac2dd77d538f91d5f891b8fa351963f06684c049692e62cb344bc971ccc7d073a5cf99346c8aaf9a7dd84d683db41fb06ca13
7
+ data.tar.gz: 0f53a2cc839508e4601444f025655de9e22b28ea168fcbff13ea86f0788075b4e7226d02085249ebb09d1d8cce81223fe42227826b489b3d9a0edf240a673c47
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.1.0] - 2018-11-01
9
+ ### Added
10
+ - handler-mailer.rb: add subject_template feature. With this option to can change the default subject with a template.
11
+
8
12
  ## [2.0.1] - 2018-01-31
9
13
  ### Fixed
10
14
  - handler-mailer.rb: emit an `unknown` with a helpful message when receiving an event `@event['contact']` with multiple objects in an array. This helps avoid confusion over using `contact` when you meant `contacts`. (@majormoses)
@@ -106,6 +110,7 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
106
110
  - initial release
107
111
 
108
112
  [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/2.0.1...HEAD
113
+ [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/2.0.1...2.1.0
109
114
  [2.0.1]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/2.0.0...2.0.1
110
115
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/1.2.0...2.0.0
111
116
  [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/1.1.0...1.2.0
data/README.md CHANGED
@@ -27,6 +27,10 @@ Optionally, you can specify your own ERB template file to use for the message
27
27
  body. The order of precedence for templates is: command-line argument (-t),
28
28
  client config called "template", the mailer handler config, default.
29
29
 
30
+ Optionally, you can specify your own ERB template file to use for the message
31
+ subject. The order of precedence for templates is: command-line argument (-T),
32
+ client config called "subject_template", the mailer handler config, default.
33
+
30
34
  ```json
31
35
  {
32
36
  "mailer": {
@@ -36,6 +40,7 @@ client config called "template", the mailer handler config, default.
36
40
  "smtp_port": "25",
37
41
  "smtp_domain": "example.org",
38
42
  "template": "/optional/path/to/template.erb",
43
+ "subject_template": "/optional/path/to/subject_template.erb",
39
44
  "subscriptions": {
40
45
  "subscription_name": {
41
46
  "mail_to": "teamemail@example.com"
@@ -48,6 +48,12 @@ class Mailer < Sensu::Handler
48
48
  long: '--template TemplateFile',
49
49
  required: false
50
50
 
51
+ option :subject_template,
52
+ description: 'Subject template to use',
53
+ short: '-T TemplateFile',
54
+ long: '--subject_template TemplateFile',
55
+ required: false
56
+
51
57
  option :content_type,
52
58
  description: 'Content-type of message',
53
59
  short: '-c ContentType',
@@ -176,6 +182,26 @@ class Mailer < Sensu::Handler
176
182
  mail_to.to_a.join(', ')
177
183
  end
178
184
 
185
+ def subject_template
186
+ return config[:subject_template] if config[:subject_template]
187
+ return @event['check']['subject_template'] if @event['check']['subject_template']
188
+ return json_config_settings['subject_template'] if json_config_settings['subject_template']
189
+ nil
190
+ end
191
+
192
+ def build_subject
193
+ template = if subject_template && File.readable?(subject_template)
194
+ File.read(subject_template)
195
+ else
196
+ <<-SUBJECT.gsub(/^\s+/, '')
197
+ <%= action_to_string %> - <%= short_name %>: <% if (@event['check']['notification'] != nil) then %><%= @event['check']['notification'] %><% else %><%= status_to_string %><% end %>
198
+ SUBJECT
199
+ end
200
+
201
+ eruby = Erubis::Eruby.new(template)
202
+ eruby.result(binding)
203
+ end
204
+
179
205
  def message_template
180
206
  return config[:template] if config[:template]
181
207
  return @event['check']['template'] if @event['check']['template']
@@ -212,6 +238,8 @@ class Mailer < Sensu::Handler
212
238
 
213
239
  def handle
214
240
  body = build_body
241
+ subject = "#{prefix_subject}#{build_subject}"
242
+
215
243
  content_type = parse_content_type
216
244
  mail_to = build_mail_to_list
217
245
  mail_from = json_config_settings['mail_from']
@@ -239,12 +267,6 @@ class Mailer < Sensu::Handler
239
267
  'X-Sensu-Occurrences' => (@event['occurrences']).to_s
240
268
  }
241
269
 
242
- subject = if @event['check']['notification'].nil?
243
- "#{prefix_subject}#{action_to_string} - #{short_name}: #{status_to_string}"
244
- else
245
- "#{prefix_subject}#{action_to_string} - #{short_name}: #{@event['check']['notification']}"
246
- end
247
-
248
270
  Mail.defaults do
249
271
  delivery_options = {
250
272
  address: smtp_address,
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsMailer
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
5
- PATCH = 1
4
+ MINOR = 1
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-ses
@@ -223,8 +223,8 @@ dependencies:
223
223
  description: Provides mail output for Sensu
224
224
  email: "<sensu-users@googlegroups.com>"
225
225
  executables:
226
- - handler-mailer-mailgun.rb
227
226
  - handler-mailer-ses.rb
227
+ - handler-mailer-mailgun.rb
228
228
  - handler-mailer.rb
229
229
  extensions: []
230
230
  extra_rdoc_files: []
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  version: '0'
264
264
  requirements: []
265
265
  rubyforge_project:
266
- rubygems_version: 2.7.4
266
+ rubygems_version: 2.6.11
267
267
  signing_key:
268
268
  specification_version: 4
269
269
  summary: Sensu plugins for mailer