sensu-plugins-mailer 0.0.2 → 0.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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +17 -3
- data/README.md +9 -3
- data/bin/handler-mailer-mailgun.rb +1 -1
- data/bin/handler-mailer.rb +85 -20
- data/lib/sensu-plugins-mailer/version.rb +2 -2
- data.tar.gz.sig +2 -2
- metadata +22 -8
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f0a156a68477698c96e7697f9eaf5743d65dbb
|
4
|
+
data.tar.gz: bab7b53712fe7e5421d9546f26f73eea0df821c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fa0bf017df15111a9951ab030e3d3cb8a9dd01a5266c163517b1d6fd4df5fdfbd9adc39b7de722627fca579604cc7bc957de16745ce1b2deecf22adc6b56bf
|
7
|
+
data.tar.gz: 3d5991a161fbc56721a781d30accc430814e929a05f14c6ef969dcda8ec7dcf927115863f66145750d00570eb68b522c75268d2f6c5b5254c9c0395fd896397b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -3,15 +3,29 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
## Unreleased
|
6
|
+
## Unreleased
|
7
7
|
|
8
|
-
##
|
8
|
+
## 0.1.0 - 2015-11-17
|
9
|
+
### Added
|
10
|
+
- Ability to use custom ERB template for mail message
|
11
|
+
- Ability to specify a custom timeout interval for sending mail
|
12
|
+
- Content type option
|
13
|
+
- Add essential information to headers
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Use correct mailgun gem
|
17
|
+
- Correct password replacement
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Upgraded to rubocop 0.32.1
|
21
|
+
|
22
|
+
## [0.0.2] - [2015-07-14]
|
9
23
|
### Changed
|
10
24
|
- updated sensu-plugin gem to 1.2.0
|
11
25
|
- updated documentation links in the README and CONTRIBUTING
|
12
26
|
- puts deps in alpha order in the gemspec and rakefile
|
13
27
|
|
14
|
-
## 0.0.1 - 2015-06-04
|
28
|
+
## [0.0.1] - [2015-06-04]
|
15
29
|
|
16
30
|
### Added
|
17
31
|
- initial release
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## Sensu-Plugins-mailer
|
2
2
|
|
3
|
-
[
|
3
|
+
[](https://travis-ci.org/sensu-plugins/sensu-plugins-mailer)
|
4
4
|
[](http://badge.fury.io/rb/sensu-plugins-mailer)
|
5
5
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mailer)
|
6
6
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-mailer)
|
@@ -24,6 +24,10 @@ The following three configuration variables must be set if you want mailer to us
|
|
24
24
|
|
25
25
|
There is an optional subscriptions hash which can be added to your mailer.json file. This subscriptions hash allows you to define individual mail_to addresses for a given subscription. When the mailer handler runs it will check the clients subscriptions and build a mail_to string with the default mailer.mail_to address as well as any subscriptions the client subscribes to where a mail_to address is found. There can be N number of hashes inside of subscriptions but the key for a given hash inside of subscriptions must match a subscription name.
|
26
26
|
|
27
|
+
Optionally, you can specify your own ERB template file to use for the message
|
28
|
+
body. The order of precedence for templates is: command-line argument (-t),
|
29
|
+
client config called "template", the mailer handler config, default.
|
30
|
+
|
27
31
|
```json
|
28
32
|
{
|
29
33
|
"mailer": {
|
@@ -32,9 +36,11 @@ There is an optional subscriptions hash which can be added to your mailer.json f
|
|
32
36
|
"smtp_address": "smtp.example.org",
|
33
37
|
"smtp_port": "25",
|
34
38
|
"smtp_domain": "example.org",
|
39
|
+
"template": "/optional/path/to/template.erb",
|
35
40
|
"subscriptions": {
|
36
|
-
|
37
|
-
|
41
|
+
"subscription_name": {
|
42
|
+
"mail_to": "teamemail@example.com"
|
43
|
+
}
|
38
44
|
}
|
39
45
|
}
|
40
46
|
}
|
data/bin/handler-mailer.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
require 'sensu-handler'
|
18
18
|
require 'mail'
|
19
19
|
require 'timeout'
|
20
|
+
require 'erubis'
|
20
21
|
|
21
22
|
# patch to fix Exim delivery_method: https://github.com/mikel/mail/pull/546
|
22
23
|
# #YELLOW
|
@@ -36,6 +37,19 @@ class Mailer < Sensu::Handler
|
|
36
37
|
description: 'Config Name',
|
37
38
|
short: '-j JsonConfig',
|
38
39
|
long: '--json_config JsonConfig',
|
40
|
+
required: false,
|
41
|
+
default: 'mailer'
|
42
|
+
|
43
|
+
option :template,
|
44
|
+
description: 'Message template to use',
|
45
|
+
short: '-t TemplateFile',
|
46
|
+
long: '--template TemplateFile',
|
47
|
+
required: false
|
48
|
+
|
49
|
+
option :content_type,
|
50
|
+
description: 'Content-type of message',
|
51
|
+
short: '-c ContentType',
|
52
|
+
long: '--content_type ContentType',
|
39
53
|
required: false
|
40
54
|
|
41
55
|
def short_name
|
@@ -59,8 +73,26 @@ class Mailer < Sensu::Handler
|
|
59
73
|
end
|
60
74
|
end
|
61
75
|
|
76
|
+
def parse_content_type
|
77
|
+
if config[:content_type]
|
78
|
+
use = config[:content_type]
|
79
|
+
elsif @event['check']['content_type']
|
80
|
+
use = @event['check']['content_type']
|
81
|
+
elsif settings[config[:json_config]]['content_type']
|
82
|
+
use = settings[config[:json_config]]['content_type']
|
83
|
+
else
|
84
|
+
use = 'plain'
|
85
|
+
end
|
86
|
+
|
87
|
+
if use.downcase == 'html'
|
88
|
+
'text/html; charset=UTF-8'
|
89
|
+
else
|
90
|
+
'text/plain; charset=ISO-8859-1'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
62
94
|
def build_mail_to_list
|
63
|
-
json_config = config[:json_config]
|
95
|
+
json_config = config[:json_config]
|
64
96
|
mail_to = @event['client']['mail_to'] || settings[json_config]['mail_to']
|
65
97
|
if settings[json_config].key?('subscriptions') && @event['check']['subscribers']
|
66
98
|
@event['check']['subscribers'].each do |sub|
|
@@ -72,9 +104,45 @@ class Mailer < Sensu::Handler
|
|
72
104
|
mail_to
|
73
105
|
end
|
74
106
|
|
75
|
-
def
|
76
|
-
|
107
|
+
def message_template
|
108
|
+
return config[:template] if config[:template]
|
109
|
+
return @event['check']['template'] if @event['check']['template']
|
110
|
+
return settings[config[:json_config]]['template'] if settings[config[:json_config]]['template']
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
|
114
|
+
def build_body
|
115
|
+
json_config = config[:json_config]
|
77
116
|
admin_gui = settings[json_config]['admin_gui'] || 'http://localhost:8080/'
|
117
|
+
# try to redact passwords from output and command
|
118
|
+
output = "#{@event['check']['output']}".gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 <password omitted>')
|
119
|
+
command = "#{@event['check']['command']}".gsub(/(\s-p|\s-P|\s--password)(\s*\S+)/, '\1 <password omitted>')
|
120
|
+
playbook = "Playbook: #{@event['check']['playbook']}" if @event['check']['playbook']
|
121
|
+
|
122
|
+
if message_template && File.readable?(message_template)
|
123
|
+
template = File.read(message_template)
|
124
|
+
else
|
125
|
+
template = <<-BODY.gsub(/^\s+/, '')
|
126
|
+
<%= @output %>
|
127
|
+
Admin GUI: <%= admin_gui %>
|
128
|
+
Host: <%= @event['client']['name'] %>
|
129
|
+
Timestamp: <%= Time.at(@event['check']['issued']) %>
|
130
|
+
Address: <%= @event['client']['address'] %>
|
131
|
+
Check Name: <%= @event['check']['name'] %>
|
132
|
+
Command: <%= command %>
|
133
|
+
Status: <%= status_to_string %>
|
134
|
+
Occurrences: <%= @event['occurrences'] %>
|
135
|
+
<%= playbook %>
|
136
|
+
BODY
|
137
|
+
end
|
138
|
+
eruby = Erubis::Eruby.new(template)
|
139
|
+
eruby.result(binding)
|
140
|
+
end
|
141
|
+
|
142
|
+
def handle
|
143
|
+
json_config = config[:json_config]
|
144
|
+
body = build_body
|
145
|
+
content_type = parse_content_type
|
78
146
|
mail_to = build_mail_to_list
|
79
147
|
mail_from = settings[json_config]['mail_from']
|
80
148
|
reply_to = settings[json_config]['reply_to'] || mail_from
|
@@ -88,23 +156,18 @@ class Mailer < Sensu::Handler
|
|
88
156
|
smtp_password = settings[json_config]['smtp_password'] || nil
|
89
157
|
smtp_authentication = settings[json_config]['smtp_authentication'] || :plain
|
90
158
|
smtp_enable_starttls_auto = settings[json_config]['smtp_enable_starttls_auto'] == 'false' ? false : true
|
91
|
-
# try to redact passwords from output and command
|
92
|
-
output = "#{@event['check']['output']}".gsub(/(-p|-P|--password)\s*\S+/, '\1 <password redacted>')
|
93
|
-
command = "#{@event['check']['command']}".gsub(/(-p|-P|--password)\s*\S+/, '\1 <password redacted>')
|
94
159
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
#{playbook}
|
107
|
-
BODY
|
160
|
+
timeout_interval = settings[json_config]['timeout'] || 10
|
161
|
+
|
162
|
+
headers = {
|
163
|
+
'X-Sensu-Host' => "#{@event['client']['name']}",
|
164
|
+
'X-Sensu-Timestamp' => "#{Time.at(@event['check']['issued'])}",
|
165
|
+
'X-Sensu-Address' => "#{@event['client']['address']}",
|
166
|
+
'X-Sensu-Check-Name' => "#{@event['check']['name']}",
|
167
|
+
'X-Sensu-Status' => "#{status_to_string}",
|
168
|
+
'X-Sensu-Occurrences' => "#{@event['occurrences']}"
|
169
|
+
}
|
170
|
+
|
108
171
|
if @event['check']['notification'].nil?
|
109
172
|
subject = "#{action_to_string} - #{short_name}: #{status_to_string}"
|
110
173
|
else
|
@@ -133,13 +196,15 @@ class Mailer < Sensu::Handler
|
|
133
196
|
end
|
134
197
|
|
135
198
|
begin
|
136
|
-
timeout
|
199
|
+
timeout timeout_interval do
|
137
200
|
Mail.deliver do
|
138
201
|
to mail_to
|
139
202
|
from mail_from
|
140
203
|
reply_to reply_to
|
141
204
|
subject subject
|
142
205
|
body body
|
206
|
+
headers headers
|
207
|
+
content_type content_type
|
143
208
|
end
|
144
209
|
|
145
210
|
puts 'mail -- sent alert for ' + short_name + ' to ' + mail_to.to_s
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
���H�a5�h���{]���%�����K�J;�[�8wI�ǡd{��d����~�� ��ܦx|��<��4�T��TA�R����ζ��>�����E�i;���� �ܲ���_�0P�Z^��X�r�
|
2
|
+
22�s�G���F����G�F�i<C�k��bm}��Jr�CԿ����"M<�(�_)Y�^�_əa��}@|P����̳\�VV�����B�ͦ1oC(5���ub�15[/i$u�-T�~GoP����
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-
|
33
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: aws
|
@@ -61,19 +61,19 @@ dependencies:
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 2.6.3
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name: mailgun
|
64
|
+
name: mailgun-ruby
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - '='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 1.0.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - '='
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 1.0.3
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
name: sensu-plugin
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +88,20 @@ dependencies:
|
|
88
88
|
- - '='
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 1.2.0
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: erubis
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.7.0
|
98
|
+
type: :runtime
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.7.0
|
91
105
|
- !ruby/object:Gem::Dependency
|
92
106
|
name: bundler
|
93
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,14 +192,14 @@ dependencies:
|
|
178
192
|
requirements:
|
179
193
|
- - '='
|
180
194
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
195
|
+
version: 0.32.1
|
182
196
|
type: :development
|
183
197
|
prerelease: false
|
184
198
|
version_requirements: !ruby/object:Gem::Requirement
|
185
199
|
requirements:
|
186
200
|
- - '='
|
187
201
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
202
|
+
version: 0.32.1
|
189
203
|
- !ruby/object:Gem::Dependency
|
190
204
|
name: rspec
|
191
205
|
requirement: !ruby/object:Gem::Requirement
|
@@ -257,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
271
|
version: '0'
|
258
272
|
requirements: []
|
259
273
|
rubyforge_project:
|
260
|
-
rubygems_version: 2.4.
|
274
|
+
rubygems_version: 2.4.8
|
261
275
|
signing_key:
|
262
276
|
specification_version: 4
|
263
277
|
summary: Sensu plugins for mailer
|
metadata.gz.sig
CHANGED
Binary file
|