sensu-plugins-mailer 1.0.0 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +9 -4
- data/README.md +26 -0
- data/bin/handler-mailer-mailgun.rb +16 -5
- data/bin/handler-mailer-ses.rb +17 -6
- data/bin/handler-mailer.rb +57 -40
- data/lib/sensu-plugins-mailer/version.rb +1 -1
- metadata +18 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914ffd464cbc0cca8d351da9a48c9d09fb81e061
|
4
|
+
data.tar.gz: 93f37933624d9923666492a9084c9a3f270d9868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e03b487e6b264cab942d39b78b989908430ab3ff724b1cee7a6925cb43fe55ec8eb93896e14278c8e7e3a3dea21de26ec1c0bafaee1bec4e1c56a2115d464df
|
7
|
+
data.tar.gz: 32021357210d7be11fee1348f7fba666119379535595dd4b9eca90d3b7267428e9b6c1c06adba1ae9e59d1677f3d18e6d200374a5418b7642a0116ca044cfc19
|
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
|
+
## [1.1.0] - 2017-06-01
|
8
|
+
### Fixed
|
9
|
+
- handler-mailer.rb - revert the commit which makes email go to wrong addresses
|
10
|
+
- handler-mailer.rb - change `json_config` to `json_config_name` for clarity
|
11
|
+
and add documentation
|
7
12
|
|
8
13
|
## [1.0.0] - 2016-06-23
|
9
14
|
### Fixed
|
10
|
-
-
|
11
|
-
- handler-mailer-mailgun.rb/handler-mailer-ses.rb:
|
15
|
+
- fix timeout deprecation for ruby 2.3.0
|
16
|
+
- handler-mailer-mailgun.rb/handler-mailer-ses.rb: fix undefined local variable or method params error
|
12
17
|
|
13
18
|
### Removed
|
14
19
|
- Support for Ruby 1.9.3; Added support for Ruby 2.3.0
|
@@ -79,7 +84,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
79
84
|
### Added
|
80
85
|
- initial release
|
81
86
|
|
82
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/1.
|
87
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/1.1.0...HEAD
|
88
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/1.0.0...1.1.0
|
83
89
|
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.3.1...1.0.0
|
84
90
|
[0.3.1]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.3.0...0.3.1
|
85
91
|
[0.3.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.2.0...0.3.0
|
@@ -91,4 +97,3 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
91
97
|
[0.1.1]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.1.0...0.1.1
|
92
98
|
[0.1.0]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.0.2...0.1.0
|
93
99
|
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-mailer/compare/0.0.1...0.0.2
|
94
|
-
|
data/README.md
CHANGED
@@ -83,9 +83,35 @@ client config called "template", the mailer handler config, default.
|
|
83
83
|
}
|
84
84
|
}
|
85
85
|
```
|
86
|
+
By default, the handler will use `plain` as the SMTP authentication type, but you may also specify `"smtp_authentication": "ntlm"` for compatible servers, e.g. Microsoft Exchange.
|
86
87
|
|
87
88
|
## Installation
|
88
89
|
|
89
90
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
90
91
|
|
92
|
+
Create a handler file in `/etc/sensu/conf.d` with the following content, replacing with your own configuration:
|
93
|
+
|
94
|
+
```json
|
95
|
+
{
|
96
|
+
"mailer" : {
|
97
|
+
"admin_gui" : "http://localhost:3000",
|
98
|
+
"mail_from": "from@email.com",
|
99
|
+
"mail_to": "to@email.com",
|
100
|
+
"delivery_method": "smtp",
|
101
|
+
"smtp_address": "localhost",
|
102
|
+
"smtp_port": "25",
|
103
|
+
"smtp_domain": "localhost.local_domain",
|
104
|
+
"smtp_enable_starttls_auto": "true",
|
105
|
+
"smtp_username" : "username",
|
106
|
+
"smtp_password" : "XXXXXXXX"
|
107
|
+
},
|
108
|
+
"handlers": {
|
109
|
+
"mailer": {
|
110
|
+
"type": "pipe",
|
111
|
+
"command": "/opt/sensu/embedded/bin/handler-mailer.rb"
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
```
|
116
|
+
|
91
117
|
## Notes
|
@@ -33,6 +33,17 @@ require 'mailgun'
|
|
33
33
|
require 'timeout'
|
34
34
|
|
35
35
|
class Mailer < Sensu::Handler
|
36
|
+
option :json_config,
|
37
|
+
description: 'Config Name',
|
38
|
+
short: '-j JsonConfig',
|
39
|
+
long: '--json_config JsonConfig',
|
40
|
+
required: false,
|
41
|
+
default: 'mailer-mailgun'
|
42
|
+
|
43
|
+
def json_config
|
44
|
+
@json_config ||= config[:json_config]
|
45
|
+
end
|
46
|
+
|
36
47
|
def short_name
|
37
48
|
@event['client']['name'] + '/' + @event['check']['name']
|
38
49
|
end
|
@@ -43,11 +54,11 @@ class Mailer < Sensu::Handler
|
|
43
54
|
|
44
55
|
def handle
|
45
56
|
params = {
|
46
|
-
mail_to: settings[
|
47
|
-
mail_from: settings[
|
48
|
-
mg_apikey: settings[
|
49
|
-
mg_domain: settings[
|
50
|
-
subject_prefix: settings[
|
57
|
+
mail_to: settings[json_config]['mail_to'],
|
58
|
+
mail_from: settings[json_config]['mail_from'],
|
59
|
+
mg_apikey: settings[json_config]['mg_apikey'],
|
60
|
+
mg_domain: settings[json_config]['mg_domain'],
|
61
|
+
subject_prefix: settings[json_config]['subject_prefix']
|
51
62
|
}
|
52
63
|
|
53
64
|
body = <<-BODY.gsub(/^ {14}/, '')
|
data/bin/handler-mailer-ses.rb
CHANGED
@@ -16,6 +16,17 @@ require 'aws/ses'
|
|
16
16
|
require 'timeout'
|
17
17
|
|
18
18
|
class Mailer < Sensu::Handler
|
19
|
+
option :json_config,
|
20
|
+
description: 'Config Name',
|
21
|
+
short: '-j JsonConfig',
|
22
|
+
long: '--json_config JsonConfig',
|
23
|
+
required: false,
|
24
|
+
default: 'mailer-ses'
|
25
|
+
|
26
|
+
def json_config
|
27
|
+
@json_config ||= config[:json_config]
|
28
|
+
end
|
29
|
+
|
19
30
|
def short_name
|
20
31
|
@event['client']['name'] + '/' + @event['check']['name']
|
21
32
|
end
|
@@ -26,12 +37,12 @@ class Mailer < Sensu::Handler
|
|
26
37
|
|
27
38
|
def handle
|
28
39
|
params = {
|
29
|
-
mail_to: settings[
|
30
|
-
mail_from: settings[
|
31
|
-
aws_access_key: settings[
|
32
|
-
aws_secret_key: settings[
|
33
|
-
aws_ses_endpoint: settings[
|
34
|
-
subject_prefix: settings[
|
40
|
+
mail_to: settings[json_config]['mail_to'],
|
41
|
+
mail_from: settings[json_config]['mail_from'],
|
42
|
+
aws_access_key: settings[json_config]['aws_access_key'],
|
43
|
+
aws_secret_key: settings[json_config]['aws_secret_key'],
|
44
|
+
aws_ses_endpoint: settings[json_config]['aws_ses_endpoint'],
|
45
|
+
subject_prefix: settings[json_config]['subject_prefix']
|
35
46
|
}
|
36
47
|
|
37
48
|
body = <<-BODY.gsub(/^ {14}/, '')
|
data/bin/handler-mailer.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# for details.
|
11
11
|
|
12
12
|
# Note: The default mailer config is fetched from the predefined json config file which is "mailer.json" or any other
|
13
|
-
# file
|
13
|
+
# file defined using the "json_config" command line option. The mailing list could also be configured on a per client basis
|
14
14
|
# by defining the "mail_to" attribute in the client config file. This will override the default mailing list where the
|
15
15
|
# alerts are being routed to for that particular client.
|
16
16
|
|
@@ -18,6 +18,8 @@ require 'sensu-handler'
|
|
18
18
|
require 'mail'
|
19
19
|
require 'timeout'
|
20
20
|
require 'erubis'
|
21
|
+
require 'set'
|
22
|
+
require 'ntlm/smtp'
|
21
23
|
|
22
24
|
# patch to fix Exim delivery_method: https://github.com/mikel/mail/pull/546
|
23
25
|
# #YELLOW
|
@@ -33,8 +35,8 @@ module ::Mail # rubocop:disable Style/ClassAndModuleChildren
|
|
33
35
|
end
|
34
36
|
|
35
37
|
class Mailer < Sensu::Handler
|
36
|
-
option :
|
37
|
-
description: '
|
38
|
+
option :json_config_name,
|
39
|
+
description: 'Name of the JSON Configuration block in Sensu',
|
38
40
|
short: '-j JsonConfig',
|
39
41
|
long: '--json_config JsonConfig',
|
40
42
|
required: false,
|
@@ -58,6 +60,32 @@ class Mailer < Sensu::Handler
|
|
58
60
|
long: '--subject_prefix prefix',
|
59
61
|
required: false
|
60
62
|
|
63
|
+
# JSON configuration settings typically defined in the handler
|
64
|
+
# file for mailer. JSON Config Name defaultly looks for a block
|
65
|
+
# named 'mailer', as seen in the Installation step of the README
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
#
|
69
|
+
# ```json
|
70
|
+
# {
|
71
|
+
# "admin_gui": "http://localhost:3000",
|
72
|
+
# "mail_from": "from@email.com",
|
73
|
+
# "mail_to": "to@email.com",
|
74
|
+
# "delivery_method": "smtp",
|
75
|
+
# "smtp_address": "localhost",
|
76
|
+
# "smtp_port": "25",
|
77
|
+
# "smtp_domain": "localhost.local_domain",
|
78
|
+
# "smtp_enable_starttls_auto": "true",
|
79
|
+
# "smtp_username": "username",
|
80
|
+
# "smtp_password": "XXXXXXXX"
|
81
|
+
# }
|
82
|
+
# ```
|
83
|
+
#
|
84
|
+
# @return [Hash]
|
85
|
+
def json_config_settings
|
86
|
+
settings[config[:json_config_name]]
|
87
|
+
end
|
88
|
+
|
61
89
|
def short_name
|
62
90
|
@event['client']['name'] + '/' + @event['check']['name']
|
63
91
|
end
|
@@ -69,8 +97,8 @@ class Mailer < Sensu::Handler
|
|
69
97
|
def prefix_subject
|
70
98
|
if config[:subject_prefix]
|
71
99
|
config[:subject_prefix] + ' '
|
72
|
-
elsif
|
73
|
-
|
100
|
+
elsif json_config_settings['subject_prefix']
|
101
|
+
json_config_settings['subject_prefix'] + ' '
|
74
102
|
else
|
75
103
|
''
|
76
104
|
end
|
@@ -94,13 +122,13 @@ class Mailer < Sensu::Handler
|
|
94
122
|
config[:content_type]
|
95
123
|
elsif @event['check']['content_type']
|
96
124
|
@event['check']['content_type']
|
97
|
-
elsif
|
98
|
-
|
125
|
+
elsif json_config_settings['content_type']
|
126
|
+
json_config_settings['content_type']
|
99
127
|
else
|
100
128
|
'plain'
|
101
129
|
end
|
102
130
|
|
103
|
-
if use.casecmp('html')
|
131
|
+
if use.casecmp('html').zero?
|
104
132
|
'text/html; charset=UTF-8'
|
105
133
|
else
|
106
134
|
'text/plain; charset=ISO-8859-1'
|
@@ -108,37 +136,27 @@ class Mailer < Sensu::Handler
|
|
108
136
|
end
|
109
137
|
|
110
138
|
def build_mail_to_list
|
111
|
-
|
112
|
-
mail_to
|
113
|
-
if
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
mail_to << ", #{settings[json_config]['subscriptions'][sub]['mail_to']}"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
if @event['client']['subscriptions']
|
122
|
-
@event['client']['subscriptions'].each do |sub|
|
123
|
-
if settings[json_config]['subscriptions'].key?(sub)
|
124
|
-
mail_to << ", #{settings[json_config]['subscriptions'][sub]['mail_to']}"
|
125
|
-
end
|
139
|
+
mail_to = Set.new
|
140
|
+
mail_to.add(@event['client']['mail_to'] || json_config_settings['mail_to'])
|
141
|
+
if json_config_settings.key?('subscriptions') && @event['check']['subscribers']
|
142
|
+
@event['check']['subscribers'].each do |sub|
|
143
|
+
if json_config_settings['subscriptions'].key?(sub)
|
144
|
+
mail_to.add(json_config_settings['subscriptions'][sub]['mail_to'].to_s)
|
126
145
|
end
|
127
146
|
end
|
128
147
|
end
|
129
|
-
mail_to
|
148
|
+
mail_to.to_a.join(', ')
|
130
149
|
end
|
131
150
|
|
132
151
|
def message_template
|
133
152
|
return config[:template] if config[:template]
|
134
153
|
return @event['check']['template'] if @event['check']['template']
|
135
|
-
return
|
154
|
+
return json_config_settings['template'] if json_config_settings['template']
|
136
155
|
nil
|
137
156
|
end
|
138
157
|
|
139
158
|
def build_body
|
140
|
-
|
141
|
-
admin_gui = settings[json_config]['admin_gui'] || 'http://localhost:8080/'
|
159
|
+
admin_gui = json_config_settings['admin_gui'] || 'http://localhost:8080/'
|
142
160
|
# try to redact passwords from output and command
|
143
161
|
output = (@event['check']['output']).to_s.gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 <password omitted>')
|
144
162
|
command = (@event['check']['command']).to_s.gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 <password omitted>')
|
@@ -165,25 +183,24 @@ class Mailer < Sensu::Handler
|
|
165
183
|
end
|
166
184
|
|
167
185
|
def handle
|
168
|
-
json_config = config[:json_config]
|
169
186
|
body = build_body
|
170
187
|
content_type = parse_content_type
|
171
188
|
mail_to = build_mail_to_list
|
172
|
-
mail_from =
|
173
|
-
reply_to =
|
189
|
+
mail_from = json_config_settings['mail_from']
|
190
|
+
reply_to = json_config_settings['reply_to'] || mail_from
|
174
191
|
|
175
|
-
delivery_method =
|
176
|
-
smtp_address =
|
177
|
-
smtp_port =
|
178
|
-
smtp_domain =
|
192
|
+
delivery_method = json_config_settings['delivery_method'] || 'smtp'
|
193
|
+
smtp_address = json_config_settings['smtp_address'] || 'localhost'
|
194
|
+
smtp_port = json_config_settings['smtp_port'] || '25'
|
195
|
+
smtp_domain = json_config_settings['smtp_domain'] || 'localhost.localdomain'
|
179
196
|
|
180
|
-
smtp_username =
|
181
|
-
smtp_password =
|
182
|
-
smtp_authentication =
|
183
|
-
smtp_use_tls =
|
184
|
-
smtp_enable_starttls_auto =
|
197
|
+
smtp_username = json_config_settings['smtp_username'] || nil
|
198
|
+
smtp_password = json_config_settings['smtp_password'] || nil
|
199
|
+
smtp_authentication = json_config_settings['smtp_authentication'] || :plain
|
200
|
+
smtp_use_tls = json_config_settings['smtp_use_tls'] || nil
|
201
|
+
smtp_enable_starttls_auto = json_config_settings['smtp_enable_starttls_auto'] == 'false' ? false : true
|
185
202
|
|
186
|
-
timeout_interval =
|
203
|
+
timeout_interval = json_config_settings['timeout'] || 10
|
187
204
|
|
188
205
|
headers = {
|
189
206
|
'X-Sensu-Host' => (@event['client']['name']).to_s,
|
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: 1.
|
4
|
+
version: 1.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:
|
11
|
+
date: 2017-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-ses
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.7.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ruby-ntlm
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.3
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.3
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,7 +220,7 @@ dependencies:
|
|
206
220
|
- - "~>"
|
207
221
|
- !ruby/object:Gem::Version
|
208
222
|
version: '0.8'
|
209
|
-
description:
|
223
|
+
description: Provides mail output for Sensu
|
210
224
|
email: "<sensu-users@googlegroups.com>"
|
211
225
|
executables:
|
212
226
|
- handler-mailer-mailgun.rb
|
@@ -249,9 +263,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
263
|
version: '0'
|
250
264
|
requirements: []
|
251
265
|
rubyforge_project:
|
252
|
-
rubygems_version: 2.5
|
266
|
+
rubygems_version: 2.4.5
|
253
267
|
signing_key:
|
254
268
|
specification_version: 4
|
255
269
|
summary: Sensu plugins for mailer
|
256
270
|
test_files: []
|
257
|
-
has_rdoc:
|