chef-handler-sns 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/chef/handler/sns.rb +19 -4
- data/lib/chef/handler/sns/config.rb +8 -0
- data/lib/chef/handler/sns/version.rb +1 -1
- data/test/test_chef_handler_sns.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3b47ba35513e1fa3c1d7df3ac62d95feaa396d
|
4
|
+
data.tar.gz: c3936aaa918435c64cd476f51f05c8c78e1ba4d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a36d6e4ff9da8f1a5d502e4d02510ac78793d7c7863c3acd9587bd7a991c7ecb123e3522f2dcae236f7df1a46fadf140205bb632664d26ad70ed5d3bf5971b7d
|
7
|
+
data.tar.gz: f1a242ae00a139aea03b43432143e0dcbf5c052d086d040f1c8e8d9e48bddb49b818c244848ff5e796085e4e666f6ded83f2561cd1ca2f005ba9a60ad33939d9
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ A simple Chef report handler that reports status of a Chef run through [Amazon S
|
|
4
4
|
|
5
5
|
[Amazon SNS](http://aws.amazon.com/sns/) can send notifications by SMS, email, [Amazon SQS](http://aws.amazon.com/sqs/) queues or to any HTTP endpoint.
|
6
6
|
|
7
|
+
We recommend using the [chef_handler_sns cookbook](http://community.opscode.com/cookbooks/chef_handler_sns) for easy installation.
|
8
|
+
|
7
9
|
This Chef Handler is heavily based on [Joshua Timberman](https://github.com/jtimberman) examples.
|
8
10
|
|
9
11
|
* http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers
|
@@ -158,6 +160,16 @@ chef_handler "Chef::Handler::Sns" do
|
|
158
160
|
end
|
159
161
|
```
|
160
162
|
|
163
|
+
##### Opsworks: Filter Notifications by Activity
|
164
|
+
An optional array of opsworks activities can be supplied. If the array is set, notifications will
|
165
|
+
only be triggered for the activities in the array, everything else will be discarded.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
argument_array = [
|
169
|
+
:filter_opsworks_activities => ['deploy','configure']
|
170
|
+
]
|
171
|
+
```
|
172
|
+
|
161
173
|
## Handler Configuration Options
|
162
174
|
|
163
175
|
The following options are available to configure the handler:
|
@@ -281,7 +293,8 @@ Minitest tests can be run as usual:
|
|
281
293
|
|
282
294
|
| | |
|
283
295
|
|:---------------------|:-----------------------------------------|
|
284
|
-
| **Author:** | Xabier de Zuazo (<xabier@onddo.com>)
|
296
|
+
| **Author:** | [Xabier de Zuazo](https://github.com/zuazo) (<xabier@onddo.com>)
|
297
|
+
| **Contributor:** | [Florian Holzhauer](https://github.com/fh)
|
285
298
|
| **Copyright:** | Copyright (c) 2014 Onddo Labs, SL. (www.onddo.com)
|
286
299
|
| **License:** | Apache License, Version 2.0
|
287
300
|
|
data/lib/chef/handler/sns.rb
CHANGED
@@ -33,10 +33,12 @@ class Chef
|
|
33
33
|
|
34
34
|
def report
|
35
35
|
config_check(node)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
if allow_publish(node)
|
37
|
+
sns.topics[topic_arn].publish(
|
38
|
+
sns_body,
|
39
|
+
{ :subject => sns_subject }
|
40
|
+
)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def get_region
|
@@ -45,6 +47,19 @@ class Chef
|
|
45
47
|
|
46
48
|
protected
|
47
49
|
|
50
|
+
def allow_publish(node)
|
51
|
+
if filter_opsworks_activity.nil?
|
52
|
+
return true
|
53
|
+
end
|
54
|
+
|
55
|
+
if node.attribute?('opsworks') && node['opsworks'].attribute?('activity')
|
56
|
+
return filter_opsworks_activity.include?(node['opsworks']['activity'])
|
57
|
+
end
|
58
|
+
|
59
|
+
Chef::Log.debug('You supplied opsworks activity filters, but node attr was not found. Returning false')
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
|
48
63
|
def sns
|
49
64
|
@sns ||= begin
|
50
65
|
params = {
|
@@ -175,4 +175,37 @@ describe Chef::Handler::Sns do
|
|
175
175
|
assert_equal @fake_sns_handler.get_sns_body, body_msg
|
176
176
|
end
|
177
177
|
|
178
|
+
it 'should publish messages if node["opsworks"]["activity"] does not exist' do
|
179
|
+
@sns_handler = Chef::Handler::Sns.new(@config)
|
180
|
+
AWS::SNS::Topic.any_instance.expects(:publish).once
|
181
|
+
|
182
|
+
@sns_handler.run_report_safely(@run_status)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should publish messages if node["opsworks"]["activity"] matches allowed acvities' do
|
186
|
+
@node.set['opsworks']['activity'] = 'deploy'
|
187
|
+
@config[:filter_opsworks_activity] = ['deploy', 'setup']
|
188
|
+
|
189
|
+
@sns_handler = Chef::Handler::Sns.new(@config)
|
190
|
+
AWS::SNS::Topic.any_instance.expects(:publish).once
|
191
|
+
@sns_handler.run_report_safely(@run_status)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should not publish messages if node["opsworks"]["activity"] differs from allowed acvities' do
|
195
|
+
@node.set['opsworks']['activity'] = 'configure'
|
196
|
+
@config[:filter_opsworks_activity] = ['deploy', 'setup']
|
197
|
+
|
198
|
+
@sns_handler = Chef::Handler::Sns.new(@config)
|
199
|
+
AWS::SNS::Topic.any_instance.expects(:publish).never
|
200
|
+
@sns_handler.run_report_safely(@run_status)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should not publish messages if node["opsworks"]["activity"] is set, but the node attribute is missing' do
|
204
|
+
@config[:filter_opsworks_activity] = ['deploy', 'setup']
|
205
|
+
|
206
|
+
@sns_handler = Chef::Handler::Sns.new(@config)
|
207
|
+
AWS::SNS::Topic.any_instance.expects(:publish).never
|
208
|
+
@sns_handler.run_report_safely(@run_status)
|
209
|
+
end
|
210
|
+
|
178
211
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-handler-sns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Onddo Labs, SL.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|