chef-rabbit 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTdjY2I2MWNjNDQ5NDg4ZWU1NDQ3OTQwYjFjZGQ3NmEwMGE4NDk3ZQ==
4
+ YjY4OWVkNTZiNDhjYzU3ZTIxZGJjNWJmNzc3NTUzMGE0YjhmYzEwMA==
5
5
  data.tar.gz: !binary |-
6
- N2M4NDhlMzQ4N2FlMGFiMzk5MTI0MzU0MDEyYWJlODc1NTczZjdlYw==
6
+ MDk1NDI0YWMwMTI0YTZkYjMzY2NmY2NiNGRmOGU3NDMzZmQ1NDc1Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWQ5ZGM0YzM5NTU2YmFjMWFmZWMwYjhhM2ZhZDRlODM5NzdiMzczZDQyNjU2
10
- YzA3MjdhYzBkNDViZmFlOGQxNjY3NzQxMWM0NTk2ZTNmN2Y0NmVjZTJmM2Mw
11
- ZWJiMzA0MzgzYWVmNDQ1ZGMzNWFjMjRhNGIyNGE2MzdkMzZjYTg=
9
+ YjZkNDkzNmE3NTRjNTcwNjBhNTJjMjI3NGQ0OTBmOTY3NzE3NmUwMmMxYjBj
10
+ MDIyOGNiODk1OTI0NDA4NjNjN2JmZjY0OTc0ZGJmOTkyYmIxNTQxZTg1YTk1
11
+ YTNhYTMyMGExOTBiNDNiNDIwYzRhZWFjNGJhM2I5ZDBkYzk2ZWQ=
12
12
  data.tar.gz: !binary |-
13
- Y2JjNTQyNTM2YzRmMmZkNDQ2YTZjYTk4Mjc5MTU0OTAyMTRmMTQ5M2Q1MzYx
14
- Yzk0NDJkOTUzODRmN2E0YjE0NjA1ZDE4YTUzNTM2NTUyOTNlZDc5MmQ1MjIy
15
- YmNkMzRiYzUzYmNlZjM0ODVmZjYyMGE4YWMxYTNiOTRkMDBiMWY=
13
+ NTJkMzM1NWY0ZmY0ZWQ5OTkyZjZmZGQyYjMxZmMyYmFhMjk4NjJkMTc0NGYw
14
+ YTAwNGYwMWFhNmRmMWZjMmUxZmI4ZmMwOWQxNDAwMGNhZmM0NDI2MDJiZDFm
15
+ YjBkZmRiMGQ5OGJjM2Y0MTlmZmJkYWRhNTBjOTc4YzA5ZDMzMGQ=
data/README.md CHANGED
@@ -0,0 +1,88 @@
1
+ ##DESCRIPTION:
2
+
3
+ Provides a Chef handler which can report run status, including any changes that were made, to a rabbit server. In the case of failed runs a backtrace will be included in the details reported. Based on the Graylog Gelf handler by Jon Wood (<jon@blankpad.net>) https://github.com/jellybob/chef-gelf
4
+
5
+ ##REQUIREMENTS:
6
+ A Rabbit server running somewhere.
7
+
8
+ ##USAGE
9
+ This example makes of the chef_handler cookbook, place some thing like this in cookbooks/chef_handler/recipes/rabbit.rb and add it to your run list.
10
+
11
+ ```
12
+ include_recipe "chef_handler::default"
13
+
14
+ gem_package "chef-rabbit" do
15
+ action :nothing
16
+ end.run_action(:install)
17
+
18
+ # Make sure the newly installed Gem is loaded.
19
+ Gem.clear_paths
20
+ require 'chef/rabbit'
21
+
22
+ chef_handler "Chef::RABBIT::Handler" do
23
+ source "chef/rabbit"
24
+ arguments({
25
+ :connection => {
26
+ :host => "your_rabbit_server",
27
+ :user => "rabbit_user",
28
+ :pass => "rabbit_pass",
29
+ :vhost => "/stuff"
30
+ }
31
+ :queue => {
32
+ :name => "some_queue",
33
+ :params => {
34
+ :durable => true,
35
+ ...
36
+ }
37
+ },
38
+ :exchange => {
39
+ :name => "some_exchange",
40
+ :params => {
41
+ :durable => true,
42
+ ...
43
+ }
44
+ },
45
+ :timestamp_tag => "@timestamp"
46
+ })
47
+
48
+ supports :exception => true, :report => true
49
+ end.run_action(:enable)
50
+ ```
51
+
52
+ Arguments take the form of an options hash, with the following options:
53
+
54
+ * :connection - http://rubybunny.info/articles/connecting.html
55
+ * :queue - rabbit queue info to use. name is set to "chef-client" + durable = true by default
56
+ * :exchange - rabbit exchange to use .default_exchange + durable = true by default
57
+ * :timestamp_tag - tag for timestamp "timestamp" by default
58
+ * :blacklist ({}) - A hash of cookbooks, resources and actions to ignore in the change list.
59
+
60
+ ##BLACKLISTING:
61
+
62
+ Some resources report themselves as having updated on every run even if nothing changed, or are just things you don't care about. To reduce the amount of noise in your logs these can be ignored by providing a blacklist. In this example we don't want to be told about the GELF handler being activated:
63
+
64
+ ```
65
+ chef_handler "Chef::RABBIT::Handler" do
66
+ source "chef/rabbit"
67
+ arguments({
68
+ :blacklist => {
69
+ "chef_handler" => {
70
+ "chef_handler" => [ "nothing", "enable" ]
71
+ }
72
+ }
73
+ })
74
+
75
+ supports :exception => true, :report => true
76
+ end.run_action(:enable)
77
+ ```
78
+
79
+ ##LICENSE and AUTHOR:
80
+
81
+ Copyright 2014 by MTN Sattelite Communications
82
+
83
+ Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
84
+
85
+ http://www.apache.org/licenses/LICENSE-2.0
86
+
87
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88
+ See the License for the specific language governing permissions and limitations under the License.
@@ -23,11 +23,26 @@ This example makes of the chef_handler cookbook, place some thing like this in c
23
23
  chef_handler "Chef::RABBIT::Handler" do
24
24
  source "chef/rabbit"
25
25
  arguments({
26
- :host => your_rabbit_server,
27
- :user => rabbit_user,
28
- :pass => rabbit_pass,
29
- :queue => your_queue,
30
- :exchange => your_exchange,
26
+ :connection => {
27
+ :host => "your_rabbit_server",
28
+ :user => "rabbit_user",
29
+ :pass => "rabbit_pass",
30
+ :vhost => "/stuff"
31
+ }
32
+ :queue => {
33
+ :name => "some_queue",
34
+ :params => {
35
+ :durable => true,
36
+ ...
37
+ }
38
+ },
39
+ :exchange => {
40
+ :name => "some_exchange",
41
+ :params => {
42
+ :durable => true,
43
+ ...
44
+ }
45
+ },
31
46
  :timestamp_tag => "@timestamp"
32
47
  })
33
48
 
@@ -36,9 +51,9 @@ This example makes of the chef_handler cookbook, place some thing like this in c
36
51
 
37
52
  Arguments take the form of an options hash, with the following options:
38
53
 
39
- * bunny client attributes - http://rubybunny.info/articles/connecting.html
40
- * :queue - name of the rabbit queue to use. "chef-client" by default
41
- * :exchange - name of exchange to use .default_exchange otherwise
54
+ * :connection - http://rubybunny.info/articles/connecting.html
55
+ * :queue - rabbit queue info to use. name is set to "chef-client" + durable = true by default
56
+ * :exchange - rabbit exchange to use .default_exchange + durable = true by default
42
57
  * :timestamp_tag - tag for timestamp "timestamp" by default
43
58
  * :blacklist ({}) - A hash of cookbooks, resources and actions to ignore in the change list.
44
59
 
@@ -63,20 +78,9 @@ Some resources report themselves as having updated on every run even if nothing
63
78
 
64
79
  Copyright 2014 by MTN Sattelite Communications
65
80
 
66
- Permission is hereby granted, free of charge, to any person obtaining a copy
67
- of this software and associated documentation files (the "Software"), to
68
- deal in the Software without restriction, including without limitation the
69
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70
- sell copies of the Software, and to permit persons to whom the Software is
71
- furnished to do so, subject to the following conditions:
72
-
73
- The above copyright notice and this permission notice shall be included in
74
- all copies or substantial portions of the Software.
75
-
76
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
77
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
78
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
79
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
80
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
81
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
82
- IN THE SOFTWARE.
81
+ Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
82
+
83
+ http://www.apache.org/licenses/LICENSE-2.0
84
+
85
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86
+ See the License for the specific language governing permissions and limitations under the License.
@@ -1,24 +1,11 @@
1
1
  #--
2
-
3
2
  # Copyright 2014 by MTN Sattelite Communications
4
3
  #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to
7
- # deal in the Software without restriction, including without limitation the
8
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9
- # sell copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
- # IN THE SOFTWARE.
4
+ # Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
7
+ # “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
22
9
  #++
23
10
 
24
11
  require "chef/rabbit/version"
@@ -33,23 +20,30 @@ class Chef
33
20
 
34
21
  def options=(value = {})
35
22
  @options = {
36
- :host => "127.0.0.1",
37
- :port => 5672,
38
- :ssl => false,
39
- :vhost => "/",
40
- :user => "guest",
41
- :pass => "guest",
42
- :queue => "chef-rabbit",
43
- :heartbeat => :server, # will use RabbitMQ setting
44
- :frame_max => 131072
23
+ :connection => {
24
+ :host => "127.0.0.1",
25
+ :port => 5672,
26
+ :ssl => false,
27
+ :vhost => "/",
28
+ :user => "guest",
29
+ :pass => "guest",
30
+ :heartbeat => :server, # will use RabbitMQ setting
31
+ :frame_max => 131072
32
+ },
33
+ :queue => {
34
+ :name => "chef-rabbit",
35
+ :params => {
36
+ :durable => true
37
+ }
38
+ }
45
39
  }.merge(value)
46
40
  end
47
41
 
48
42
  def initialize(options = {})
49
- self.options = options
43
+ self.options = symbolize_keys(options)
50
44
 
51
- Chef::Log.debug "Initialised RABBIT handler for amqp://#{self.options[:server]}:#{self.options[:server]}@#{self.options[:server]}:#{self.options[:port]}/#{self.options[:vhost]}"
52
- @connection = Bunny.new(self.options)
45
+ Chef::Log.debug "Initialised RABBIT handler for amqp://#{self.options[:connection][:user]}:#{self.options[:connection][:pass]}@#{self.options[:connection][:host]}:#{self.options[:connection][:port]}/#{self.options[:connection][:vhost]}"
46
+ @connection = Bunny.new(self.options[:connection])
53
47
  @connection.start
54
48
  end
55
49
 
@@ -57,7 +51,9 @@ class Chef
57
51
  Chef::Log.debug "Reporting #{run_status.inspect}"
58
52
 
59
53
  channel = @connection.create_channel
60
- exchange = (@options[:exchange] == nil) ? channel.default_echange : channel.direct(@options[:exchange])
54
+ exchange = (@options[:exchange] == nil) ? channel.default_echange : channel.direct(@options[:exchange][:name], @options[:exchange][:params])
55
+ channel.queue(@options[:queue][:name], @options[:queue][:params]).bind(exch)
56
+
61
57
  timestamp = (@options[:timestamp_tag] == nil) ? "timestamp" : @options[:timestamp_tag]
62
58
 
63
59
  if run_status.failed?
@@ -68,7 +64,7 @@ class Chef
68
64
  :short_message => "Chef run failed on #{node.name}. Updated #{changes[:count]} resources.",
69
65
  :full_message => run_status.formatted_exception + "\n" + Array(backtrace).join("\n") + changes[:message]
70
66
  }.to_json,
71
- :routing_key => @options[:queue])
67
+ :routing_key => @options[:queue][:name])
72
68
  else
73
69
  Chef::Log.debug "Notifying Rabbit server of success."
74
70
  exchange.publish(
@@ -77,7 +73,7 @@ class Chef
77
73
  :short_message => "Chef run completed on #{node.name} in #{elapsed_time}. Updated #{changes[:count]} resources.",
78
74
  :full_message => changes[:message]
79
75
  }.to_json,
80
- :routing_key => @options[:queue])
76
+ :routing_key => @options[:queue][:name])
81
77
  end
82
78
  end
83
79
 
@@ -99,6 +95,21 @@ class Chef
99
95
  @changes = { :lines => lines, :count => count, :message => message }
100
96
  end
101
97
 
98
+ def symbolize_keys(hash)
99
+ hash.inject({}) {|result, (key, value)|
100
+ new_key = case key
101
+ when String then key.to_sym
102
+ else key
103
+ end
104
+ new_value = case value
105
+ when Hash then symbolize_keys(value)
106
+ else value
107
+ end
108
+ result[new_key] = new_value
109
+ result
110
+ }
111
+ end
112
+
102
113
  def sanitised_changes
103
114
  run_status.updated_resources.reject do |updated|
104
115
  cookbook = @options[:blacklist][updated.cookbook_name]
@@ -23,6 +23,6 @@
23
23
 
24
24
  class Chef
25
25
  module RABBIT
26
- VERSION = "1.0.0"
26
+ VERSION = "1.0.1"
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-rabbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MTN Satellite Communications
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -48,36 +48,34 @@ description: ! "= DESCRIPTION:\n\nProvides a Chef handler which can report run s
48
48
  \ gem_package \"chef-rabbit\" do\n action :nothing\n end.run_action(:install)\n
49
49
  \ \n # Make sure the newly installed Gem is loaded.\n Gem.clear_paths\n require
50
50
  'chef/rabbit'\n \n chef_handler \"Chef::RABBIT::Handler\" do\n source \"chef/rabbit\"\n
51
- \ arguments({\n :host => your_rabbit_server,\n :user => rabbit_user,\n
52
- \ :pass => rabbit_pass,\n :queue => your_queue,\n :exchange => your_exchange,\n
53
- \ :timestamp_tag => \"@timestamp\"\n })\n\n supports :exception => true,
54
- :report => true\n end.run_action(:enable)\n\nArguments take the form of an options
55
- hash, with the following options:\n\n* bunny client attributes - http://rubybunny.info/articles/connecting.html\n*
56
- :queue - name of the rabbit queue to use. \"chef-client\" by default\n*
57
- :exchange - name of exchange to use .default_exchange otherwise\n*
58
- :timestamp_tag - tag for timestamp \"timestamp\" by default\n* :blacklist
59
- ({}) - A hash of cookbooks, resources and actions to ignore in the change
60
- list.\n\n= BLACKLISTING:\n\nSome resources report themselves as having updated on
61
- every run even if nothing changed, or are just things you don't care about. To reduce
62
- the amount of noise in your logs these can be ignored by providing a blacklist.
63
- In this example we don't want to be told about the GELF handler being activated:\n\n
64
- \ chef_handler \"Chef::RABBIT::Handler\" do\n source \"chef/rabbit\"\n arguments({\n
65
- \ :blacklist => {\n \"chef_handler\" => {\n \"chef_handler\"
51
+ \ arguments({\n :connection => {\n :host => \"your_rabbit_server\",\n
52
+ \ :user => \"rabbit_user\",\n :pass => \"rabbit_pass\",\n :vhost
53
+ => \"/stuff\"\n }\n :queue => {\n :name => \"some_queue\",\n :params
54
+ => {\n :durable => true,\n ...\n }\n },\n :exchange
55
+ => {\n :name => \"some_exchange\",\n :params => {\n :durable
56
+ => true,\n ...\n }\n },\n :timestamp_tag => \"@timestamp\"\n
57
+ \ })\n\n supports :exception => true, :report => true\n end.run_action(:enable)\n\nArguments
58
+ take the form of an options hash, with the following options:\n\n* :connection -
59
+ http://rubybunny.info/articles/connecting.html\n* :queue - rabbit
60
+ queue info to use. name is set to \"chef-client\" + durable = true by default\n*
61
+ :exchange - rabbit exchange to use .default_exchange + durable = true
62
+ by default \n* :timestamp_tag - tag for timestamp \"timestamp\" by default\n*
63
+ :blacklist ({}) - A hash of cookbooks, resources and actions to ignore in
64
+ the change list.\n\n= BLACKLISTING:\n\nSome resources report themselves as having
65
+ updated on every run even if nothing changed, or are just things you don't care
66
+ about. To reduce the amount of noise in your logs these can be ignored by providing
67
+ a blacklist. In this example we don't want to be told about the GELF handler being
68
+ activated:\n\n chef_handler \"Chef::RABBIT::Handler\" do\n source \"chef/rabbit\"\n
69
+ \ arguments({\n :blacklist => {\n \"chef_handler\" => {\n \"chef_handler\"
66
70
  => [ \"nothing\", \"enable\" ]\n }\n }\n })\n\n supports
67
71
  :exception => true, :report => true\n end.run_action(:enable)\n\n= LICENSE and
68
- AUTHOR:\n\nCopyright 2014 by MTN Sattelite Communications\n\nPermission is hereby
69
- granted, free of charge, to any person obtaining a copy\nof this software and associated
70
- documentation files (the \"Software\"), to\ndeal in the Software without restriction,
71
- including without limitation the\nrights to use, copy, modify, merge, publish, distribute,
72
- sublicense, and/or\nsell copies of the Software, and to permit persons to whom the
73
- Software is\nfurnished to do so, subject to the following conditions:\n\nThe above
74
- copyright notice and this permission notice shall be included in\nall copies or
75
- substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT
76
- WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
77
- OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
78
- EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
79
- OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM,
80
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\nIN THE SOFTWARE.\n"
72
+ AUTHOR:\n\nCopyright 2014 by MTN Sattelite Communications\n\nLicensed under the
73
+ Apache License, Version 2.0 (the “License”); you may not use this file except in
74
+ compliance with the License. You may obtain a copy of the License at \n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless
75
+ required by applicable law or agreed to in writing, software distributed under the
76
+ License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
77
+ ANY KIND, either express or implied. \nSee the License for the specific language
78
+ governing permissions and limitations under the License.\n"
81
79
  email:
82
80
  - marat.garafutdinov@mtnsart.com
83
81
  executables: []