chef-handler-sns 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bfcb555c086dcc166d90531da24483459f72e83
4
- data.tar.gz: 4ff9d560ba54be282c9efeb9595a6ad12b471fbe
3
+ metadata.gz: bc3b47ba35513e1fa3c1d7df3ac62d95feaa396d
4
+ data.tar.gz: c3936aaa918435c64cd476f51f05c8c78e1ba4d2
5
5
  SHA512:
6
- metadata.gz: 4fe21997780eebbda502e774c179c2e11fef890c4f5506bbeb39b4c81b2cf68357493909d32983779ce7715d5c5c637c3b417fabc3f6ebe7a579967eb0210cfa
7
- data.tar.gz: 378efacd20133aad1373579a8307f9b963a39f443560d58534a113811a87a8d35b49bfd2a3a5414da15e76eead051e1e2160ba8d3ea6f435bc23b3260f730dd4
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
 
@@ -33,10 +33,12 @@ class Chef
33
33
 
34
34
  def report
35
35
  config_check(node)
36
- sns.topics[topic_arn].publish(
37
- sns_body,
38
- { :subject => sns_subject }
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 = {
@@ -122,6 +122,14 @@ class Chef
122
122
  )
123
123
  end
124
124
 
125
+ def filter_opsworks_activity(arg=nil)
126
+ arg = Array(arg) if arg.is_a? String
127
+ set_or_return(
128
+ :filter_opsworks_activity,
129
+ arg,
130
+ :kind_of => Array
131
+ )
132
+ end
125
133
  end
126
134
  end
127
135
  end
@@ -2,7 +2,7 @@
2
2
  class Chef
3
3
  class Handler
4
4
  class Sns < ::Chef::Handler
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
8
8
  end
@@ -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.0.0
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-02-19 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk