knife-spork-berks 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +19 -0
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +284 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +35 -0
  7. data/README.md +406 -0
  8. data/Rakefile +2 -0
  9. data/knife-spork-berks.gemspec +22 -0
  10. data/lib/chef/knife/spork-bump.rb +86 -0
  11. data/lib/chef/knife/spork-check.rb +149 -0
  12. data/lib/chef/knife/spork-databag-create.rb +53 -0
  13. data/lib/chef/knife/spork-databag-delete.rb +51 -0
  14. data/lib/chef/knife/spork-databag-edit.rb +54 -0
  15. data/lib/chef/knife/spork-databag-fromfile.rb +82 -0
  16. data/lib/chef/knife/spork-environment-create.rb +43 -0
  17. data/lib/chef/knife/spork-environment-delete.rb +36 -0
  18. data/lib/chef/knife/spork-environment-edit.rb +37 -0
  19. data/lib/chef/knife/spork-environment-fromfile.rb +42 -0
  20. data/lib/chef/knife/spork-info.rb +30 -0
  21. data/lib/chef/knife/spork-node-create.rb +38 -0
  22. data/lib/chef/knife/spork-node-delete.rb +38 -0
  23. data/lib/chef/knife/spork-node-edit.rb +45 -0
  24. data/lib/chef/knife/spork-node-fromfile.rb +43 -0
  25. data/lib/chef/knife/spork-node-runlistadd.rb +48 -0
  26. data/lib/chef/knife/spork-node-runlistremove.rb +42 -0
  27. data/lib/chef/knife/spork-node-runlistset.rb +42 -0
  28. data/lib/chef/knife/spork-omni.rb +107 -0
  29. data/lib/chef/knife/spork-promote.rb +166 -0
  30. data/lib/chef/knife/spork-role-create.rb +43 -0
  31. data/lib/chef/knife/spork-role-delete.rb +36 -0
  32. data/lib/chef/knife/spork-role-edit.rb +37 -0
  33. data/lib/chef/knife/spork-role-fromfile.rb +42 -0
  34. data/lib/chef/knife/spork-upload.rb +129 -0
  35. data/lib/knife-spork.rb +3 -0
  36. data/lib/knife-spork/plugins.rb +25 -0
  37. data/lib/knife-spork/plugins/campfire.rb +211 -0
  38. data/lib/knife-spork/plugins/eventinator.rb +317 -0
  39. data/lib/knife-spork/plugins/foodcritic.rb +46 -0
  40. data/lib/knife-spork/plugins/git.rb +197 -0
  41. data/lib/knife-spork/plugins/graphite.rb +25 -0
  42. data/lib/knife-spork/plugins/grove.rb +161 -0
  43. data/lib/knife-spork/plugins/hipchat.rb +131 -0
  44. data/lib/knife-spork/plugins/irccat.rb +298 -0
  45. data/lib/knife-spork/plugins/jabber.rb +129 -0
  46. data/lib/knife-spork/plugins/plugin.rb +105 -0
  47. data/lib/knife-spork/plugins/statusnet.rb +118 -0
  48. data/lib/knife-spork/runner.rb +277 -0
  49. data/plugins/Campfire.md +43 -0
  50. data/plugins/Eventinator.md +30 -0
  51. data/plugins/Foodcritic.md +53 -0
  52. data/plugins/Git.md +46 -0
  53. data/plugins/Graphite.md +30 -0
  54. data/plugins/Grove.md +31 -0
  55. data/plugins/HipChat.md +50 -0
  56. data/plugins/Irccat.md +50 -0
  57. data/plugins/Jabber.md +61 -0
  58. data/plugins/README.md +70 -0
  59. data/plugins/StatusNet.md +41 -0
  60. data/plugins/Template.md +34 -0
  61. metadata +170 -0
@@ -0,0 +1,129 @@
1
+ require 'chef/knife'
2
+ require 'chef/exceptions'
3
+ require 'chef/cookbook_loader'
4
+ require 'chef/cookbook_uploader'
5
+ require 'knife-spork/runner'
6
+ require 'socket'
7
+
8
+ module KnifeSpork
9
+ class SporkUpload < Chef::Knife
10
+ include KnifeSpork::Runner
11
+
12
+ CHECKSUM = 'checksum'
13
+ MATCH_CHECKSUM = /[0-9a-f]{32,}/
14
+
15
+ banner 'knife spork upload [COOKBOOKS...] (options)'
16
+
17
+ option :cookbook_path,
18
+ :short => '-o PATH:PATH',
19
+ :long => '--cookbook-path PATH:PATH',
20
+ :description => 'A colon-separated path to look for cookbooks in',
21
+ :proc => lambda { |o| o.split(':') }
22
+
23
+ option :freeze,
24
+ :long => '--freeze',
25
+ :description => 'Freeze this version of the cookbook so that it cannot be overwritten',
26
+ :boolean => true
27
+
28
+ option :depends,
29
+ :short => '-D',
30
+ :long => '--include-dependencies',
31
+ :description => 'Also upload cookbook dependencies'
32
+
33
+ if defined?(::Berkshelf)
34
+ option :berksfile,
35
+ :short => '-b',
36
+ :long => 'berksfile',
37
+ :description => 'Path to a Berksfile to operate off of',
38
+ :default => File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
39
+ end
40
+
41
+ def run
42
+ self.config = Chef::Config.merge!(config)
43
+ config[:cookbook_path] ||= Chef::Config[:cookbook_path]
44
+
45
+ if @name_args.empty?
46
+ show_usage
47
+ ui.error("You must specify the --all flag or at least one cookbook name")
48
+ exit 1
49
+ end
50
+
51
+ #First load so plugins etc know what to work with
52
+ @cookbooks = load_cookbooks(name_args)
53
+ include_dependencies if config[:depends]
54
+
55
+ run_plugins(:before_upload)
56
+
57
+ #Reload cookbook in case a VCS plugin found updates
58
+ @cookbooks = load_cookbooks(name_args)
59
+ include_dependencies if config[:depends]
60
+
61
+ upload
62
+ run_plugins(:after_upload)
63
+ end
64
+
65
+ private
66
+ def include_dependencies
67
+ @cookbooks.each do |cookbook|
68
+ @cookbooks.concat(load_cookbooks(cookbook.metadata.dependencies.keys))
69
+ end
70
+
71
+ @cookbooks.uniq!
72
+ end
73
+
74
+ def upload
75
+ # upload cookbooks in reverse so that dependencies are satisfied first
76
+ @cookbooks.reverse.each do |cookbook|
77
+ begin
78
+ check_dependencies(cookbook)
79
+ if name_args.include?(cookbook.name.to_s)
80
+ uploader = Chef::CookbookUploader.new(cookbook, ::Chef::Config.cookbook_path)
81
+ if uploader.respond_to?(:upload_cookbooks)
82
+ # Chef >= 10.14.0
83
+ uploader.upload_cookbooks
84
+ ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
85
+ cookbook.freeze_version
86
+ uploader.upload_cookbooks
87
+ else
88
+ uploader.upload_cookbook
89
+ ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
90
+ cookbook.freeze_version
91
+ uploader.upload_cookbook
92
+
93
+ end
94
+ end
95
+ rescue Net::HTTPServerException => e
96
+ if e.response.code == '409'
97
+ ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!"
98
+ exit(1)
99
+ else
100
+ raise
101
+ end
102
+ end
103
+ end
104
+
105
+ ui.msg "Successfully uploaded #{@cookbooks.collect{|c| "#{c.name}@#{c.version}"}.join(', ')}!"
106
+ end
107
+
108
+ # Ensures that all the cookbooks dependencies are either already on the server or being uploaded in this pass
109
+ def check_dependencies(cookbook)
110
+ cookbook.metadata.dependencies.each do |cookbook_name, version|
111
+ unless server_side_cookbooks(cookbook_name, version)
112
+ ui.error "#{cookbook.name} depends on #{cookbook_name} (#{version}), which is not currently being uploaded and cannot be found on the server!"
113
+ exit(1)
114
+ end
115
+ end
116
+ end
117
+
118
+ def server_side_cookbooks(cookbook_name, version)
119
+ if Chef::CookbookVersion.respond_to?(:list_all_versions)
120
+ @server_side_cookbooks ||= Chef::CookbookVersion.list_all_versions
121
+ else
122
+ @server_side_cookbooks ||= Chef::CookbookVersion.list
123
+ end
124
+
125
+ hash = @server_side_cookbooks[cookbook_name]
126
+ hash && hash['versions'] && hash['versions'].any?{ |v| Chef::VersionConstraint.new(version).include?(v['version']) }
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,3 @@
1
+ module KnifeSpork
2
+ require 'knife-spork/plugins'
3
+ end
@@ -0,0 +1,25 @@
1
+ module KnifeSpork
2
+ module Plugins
3
+ # Load each of the drop-in plugins
4
+ Dir[File.expand_path('../plugins/**/*.rb', __FILE__)].each { |f| require f }
5
+
6
+ def self.run(options = {})
7
+ hook = options[:hook].to_sym
8
+
9
+ #Load each of the drop-in plugins specified in the custom plugin path
10
+ Dir[File.expand_path("#{options[:config][:custom_plugin_path]}/*.rb")].each { |f| require f }
11
+
12
+ klasses.each do |klass|
13
+ plugin = klass.new(options)
14
+ plugin.send(hook) if plugin.respond_to?(hook) && plugin.enabled?
15
+ end
16
+ end
17
+
18
+ # Get and return a list of all subclasses (plugins) that are not the base plugin
19
+ def self.klasses
20
+ @@klasses ||= self.constants.collect do |c|
21
+ self.const_get(c) if self.const_get(c).is_a?(Class) && self.const_get(c) != KnifeSpork::Plugins::Plugin
22
+ end.compact
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,211 @@
1
+ require 'knife-spork/plugins/plugin'
2
+
3
+ module KnifeSpork
4
+ module Plugins
5
+ class Campfire < Plugin
6
+ name :campfire
7
+
8
+ def perform; end
9
+
10
+ def after_upload
11
+ campfire do |rooms|
12
+ rooms.paste <<-EOH
13
+ #{organization}#{current_user} froze the following cookbooks on Chef Server:
14
+ #{cookbooks.collect{|c| " #{c.name}@#{c.version}"}.join("\n")}
15
+ EOH
16
+ end
17
+ end
18
+
19
+ def after_promote_remote
20
+ campfire do |rooms|
21
+ rooms.paste <<-EOH
22
+ #{organization}#{current_user} promoted cookbooks on Chef Server:
23
+
24
+ cookbooks:
25
+ #{cookbooks.collect{|c| " #{c.name}@#{c.version}"}.join("\n")}
26
+
27
+ environments:
28
+ #{environments.collect{|e| " #{e.name}"}.join("\n")}
29
+ EOH
30
+ end
31
+ end
32
+
33
+ def after_environmentfromfile
34
+ campfire do |rooms|
35
+ rooms.paste <<-EOH
36
+ #{organization}#{current_user} uploaded environment #{object_name}
37
+ EOH
38
+ end
39
+ end
40
+
41
+ def after_environmentedit
42
+ campfire do |rooms|
43
+ rooms.paste <<-EOH
44
+ #{organization}#{current_user} edited environment #{object_name}
45
+ EOH
46
+ end
47
+ end
48
+
49
+ def after_environmentcreate
50
+ campfire do |rooms|
51
+ rooms.paste <<-EOH
52
+ #{organization}#{current_user} created environment #{object_name}
53
+ EOH
54
+ end
55
+ end
56
+
57
+ def after_environmentdelete
58
+ campfire do |rooms|
59
+ rooms.paste <<-EOH
60
+ #{organization}#{current_user} deleted environment #{object_name}
61
+ EOH
62
+ end
63
+ end
64
+
65
+ def after_rolefromfile
66
+ campfire do |rooms|
67
+ rooms.paste <<-EOH
68
+ #{organization}#{current_user} uploaded role #{object_name}
69
+ EOH
70
+ end
71
+ end
72
+
73
+ def after_roleedit
74
+ campfire do |rooms|
75
+ rooms.paste <<-EOH
76
+ #{organization}#{current_user} edited role #{object_name}
77
+ EOH
78
+ end
79
+ end
80
+
81
+ def after_rolecreate
82
+ campfire do |rooms|
83
+ rooms.paste <<-EOH
84
+ #{organization}#{current_user} created role #{object_name}
85
+ EOH
86
+ end
87
+ end
88
+
89
+ def after_roledelete
90
+ campfire do |rooms|
91
+ rooms.paste <<-EOH
92
+ #{organization}#{current_user} deleted role #{object_name}
93
+ EOH
94
+ end
95
+ end
96
+
97
+ def after_databagedit
98
+ campfire do |rooms|
99
+ rooms.paste <<-EOH
100
+ #{organization}#{current_user} edited data bag item #{object_name}:#{object_secondary_name}
101
+ EOH
102
+ end
103
+ end
104
+
105
+ def after_databagdelete
106
+ campfire do |rooms|
107
+ rooms.paste <<-EOH
108
+ #{organization}#{current_user} deleted data bag #{object_name}}
109
+ EOH
110
+ end
111
+ end
112
+
113
+ def after_databagitemdelete
114
+ campfire do |rooms|
115
+ rooms.paste <<-EOH
116
+ #{organization}#{current_user} deleted data bag item #{object_name}:#{object_secondary_name}
117
+ EOH
118
+ end
119
+ end
120
+
121
+ def after_databagcreate
122
+ campfire do |rooms|
123
+ rooms.paste <<-EOH
124
+ #{organization}#{current_user} created data bag #{object_name}
125
+ EOH
126
+ end
127
+ end
128
+
129
+ def after_databagfromfile
130
+ campfire do |rooms|
131
+ rooms.paste <<-EOH
132
+ #{organization}#{current_user} uploaded data bag item #{object_name}:#{object_secondary_name}
133
+ EOH
134
+ end
135
+ end
136
+
137
+ def after_nodeedit
138
+ campfire do |rooms|
139
+ rooms.paste <<-EOH
140
+ #{organization}#{current_user} edited node #{object_name}
141
+ EOH
142
+ end
143
+ end
144
+
145
+ def after_nodedelete
146
+ campfire do |rooms|
147
+ rooms.paste <<-EOH
148
+ #{organization}#{current_user} deleted node #{object_name}
149
+ EOH
150
+ end
151
+ end
152
+
153
+ def after_nodecreate
154
+ campfire do |rooms|
155
+ rooms.paste <<-EOH
156
+ #{organization}#{current_user} created node #{object_name}
157
+ EOH
158
+ end
159
+ end
160
+
161
+ def after_nodefromfile
162
+ campfire do |rooms|
163
+ rooms.paste <<-EOH
164
+ #{organization}#{current_user} uploaded node #{object_name}
165
+ EOH
166
+ end
167
+ end
168
+
169
+ def after_noderunlistadd
170
+ campfire do |rooms|
171
+ rooms.paste <<-EOH
172
+ #{organization}#{current_user} added run_list items to #{object_name}: #{object_secondary_name}
173
+ EOH
174
+ end
175
+ end
176
+
177
+ def after_noderunlistremove
178
+ campfire do |rooms|
179
+ rooms.paste <<-EOH
180
+ #{organization}#{current_user} removed run_list items from #{object_name}: #{object_secondary_name}
181
+ EOH
182
+ end
183
+ end
184
+
185
+ def after_noderunlistset
186
+ campfire do |rooms|
187
+ rooms.paste <<-EOH
188
+ #{organization}#{current_user} set the run_list for #{object_name} to #{object_secondary_name}
189
+ EOH
190
+ end
191
+ end
192
+
193
+ private
194
+ def campfire(&block)
195
+ safe_require 'campy'
196
+
197
+ rooms = [config.rooms || config.room].flatten.compact
198
+ campfire = Campy::Room.new(:account => config.account, :token => config.token)
199
+
200
+ rooms.each do |room_name|
201
+ room = Campy::Room.new(
202
+ :account => config.account,
203
+ :token => config.token,
204
+ :room => room_name
205
+ )
206
+ yield(room) unless room.nil?
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,317 @@
1
+ require 'knife-spork/plugins/plugin'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module KnifeSpork
6
+ module Plugins
7
+ class Eventinator < Plugin
8
+ name :eventinator
9
+
10
+ def perform; end
11
+
12
+ def after_upload
13
+ cookbooks.each do |cookbook|
14
+ event_data = {
15
+ :tag => 'knife',
16
+ :username => current_user,
17
+ :status => "#{organization}#{current_user} uploaded and froze #{cookbook.name}@#{cookbook.version}",
18
+ :metadata => {
19
+ :cookbook_name => cookbook.name,
20
+ :cookbook_version => cookbook.version
21
+ }.to_json
22
+ }
23
+ eventinate(event_data)
24
+ end
25
+ end
26
+
27
+ def after_promote_remote
28
+ environments.each do |environment|
29
+ cookbooks.each do |cookbook|
30
+ event_data = {
31
+ :tag => 'knife',
32
+ :username => current_user,
33
+ :status => "#{organization}#{current_user} promoted #{cookbook.name}(#{cookbook.version}) to #{environment.name}",
34
+ :metadata => {
35
+ :cookbook_name => cookbook.name,
36
+ :cookbook_version => cookbook.version
37
+ }.to_json
38
+ }
39
+ eventinate(event_data)
40
+ end
41
+ end
42
+ end
43
+
44
+ def after_environmentfromfile
45
+ event_data = {
46
+ :tag => 'knife',
47
+ :username => current_user,
48
+ :status => "#{organization}#{current_user} uploaded environment #{object_name}",
49
+ :metadata => {
50
+ :environment_name => object_name,
51
+ }.to_json
52
+ }
53
+ eventinate(event_data)
54
+ end
55
+
56
+ def after_environmentedit
57
+ event_data = {
58
+ :tag => 'knife',
59
+ :username => current_user,
60
+ :status => "#{organization}#{current_user} edited environment #{object_name}",
61
+ :metadata => {
62
+ :environment_name => object_name,
63
+ }.to_json
64
+ }
65
+ eventinate(event_data)
66
+ end
67
+
68
+ def after_environmentcreate
69
+ event_data = {
70
+ :tag => 'knife',
71
+ :username => current_user,
72
+ :status => "#{organization}#{current_user} created environment #{object_name}",
73
+ :metadata => {
74
+ :environment_name => object_name,
75
+ }.to_json
76
+ }
77
+ eventinate(event_data)
78
+ end
79
+
80
+ def after_environmentdelete
81
+ event_data = {
82
+ :tag => 'knife',
83
+ :username => current_user,
84
+ :status => "#{organization}#{current_user} deleted environment #{object_name}",
85
+ :metadata => {
86
+ :environment_name => object_name,
87
+ }.to_json
88
+ }
89
+ eventinate(event_data)
90
+ end
91
+
92
+ def after_rolefromfile
93
+ event_data = {
94
+ :tag => 'knife',
95
+ :username => current_user,
96
+ :status => "#{organization}#{current_user} uploaded role #{object_name}",
97
+ :metadata => {
98
+ :role_name => object_name,
99
+ }.to_json
100
+ }
101
+ eventinate(event_data)
102
+ end
103
+
104
+ def after_roleedit
105
+ event_data = {
106
+ :tag => 'knife',
107
+ :username => current_user,
108
+ :status => "#{organization}#{current_user} edited role #{object_name}",
109
+ :metadata => {
110
+ :role_name => object_name,
111
+ }.to_json
112
+ }
113
+ eventinate(event_data)
114
+ end
115
+
116
+ def after_rolecreate
117
+ event_data = {
118
+ :tag => 'knife',
119
+ :username => current_user,
120
+ :status => "#{organization}#{current_user} created role #{object_name}",
121
+ :metadata => {
122
+ :role_name => object_name,
123
+ }.to_json
124
+ }
125
+ eventinate(event_data)
126
+ end
127
+
128
+ def after_roledelete
129
+ event_data = {
130
+ :tag => 'knife',
131
+ :username => current_user,
132
+ :status => "#{organization}#{current_user} deleted role #{object_name}",
133
+ :metadata => {
134
+ :role_name => object_name,
135
+ }.to_json
136
+ }
137
+ eventinate(event_data)
138
+ end
139
+
140
+ def after_databagedit
141
+ event_data = {
142
+ :tag => 'knife',
143
+ :username => current_user,
144
+ :status => "#{organization}#{current_user} edited data bag item #{object_name}:#{object_secondary_name}",
145
+ :metadata => {
146
+ :databag_name => object_name,
147
+ :databag_item => object_secondary_name,
148
+ }.to_json
149
+ }
150
+ eventinate(event_data)
151
+ end
152
+
153
+ def after_databagcreate
154
+ event_data = {
155
+ :tag => 'knife',
156
+ :username => current_user,
157
+ :status => "#{organization}#{current_user} created data bag #{object_name}",
158
+ :metadata => {
159
+ :databag_name => object_name,
160
+ }.to_json
161
+ }
162
+ eventinate(event_data)
163
+ end
164
+
165
+ def after_databagdelete
166
+ event_data = {
167
+ :tag => 'knife',
168
+ :username => current_user,
169
+ :status => "#{organization}#{current_user} deleted data bag item #{object_name}",
170
+ :metadata => {
171
+ :databag_name => object_name,
172
+ }.to_json
173
+ }
174
+ eventinate(event_data)
175
+ end
176
+
177
+ def after_databagitemdelete
178
+ event_data = {
179
+ :tag => 'knife',
180
+ :username => current_user,
181
+ :status => "#{organization}#{current_user} deleted data bag item #{object_name}:#{object_secondary_name}",
182
+ :metadata => {
183
+ :databag_name => object_name,
184
+ :databag_item => object_secondary_name,
185
+ }.to_json
186
+ }
187
+ eventinate(event_data)
188
+ end
189
+
190
+ def after_databagfromfile
191
+ event_data = {
192
+ :tag => 'knife',
193
+ :username => current_user,
194
+ :status => "#{organization}#{current_user} uploaded data bag item #{object_name}:#{object_secondary_name}",
195
+ :metadata => {
196
+ :databag_name => object_name,
197
+ :databag_item => object_secondary_name,
198
+ }.to_json
199
+ }
200
+ eventinate(event_data)
201
+ end
202
+
203
+ def after_nodeedit
204
+ event_data = {
205
+ :tag => 'knife',
206
+ :username => current_user,
207
+ :status => "#{organization}#{current_user} edited node #{object_name}",
208
+ :metadata => {
209
+ :node_name => object_name
210
+ }.to_json
211
+ }
212
+ eventinate(event_data)
213
+ end
214
+
215
+ def after_nodedelete
216
+ event_data = {
217
+ :tag => 'knife',
218
+ :username => current_user,
219
+ :status => "#{organization}#{current_user} deleted node #{object_name}",
220
+ :metadata => {
221
+ :node_name => object_name
222
+ }.to_json
223
+ }
224
+ eventinate(event_data)
225
+ end
226
+
227
+ def after_nodecreate
228
+ event_data = {
229
+ :tag => 'knife',
230
+ :username => current_user,
231
+ :status => "#{organization}#{current_user} created node #{object_name}",
232
+ :metadata => {
233
+ :node_name => object_name
234
+ }.to_json
235
+ }
236
+ eventinate(event_data)
237
+ end
238
+
239
+ def after_nodefromfile
240
+ event_data = {
241
+ :tag => 'knife',
242
+ :username => current_user,
243
+ :status => "#{organization}#{current_user} uploaded node #{object_name}",
244
+ :metadata => {
245
+ :node_name => object_name
246
+ }.to_json
247
+ }
248
+ eventinate(event_data)
249
+ end
250
+
251
+ def after_noderunlistadd
252
+ event_data = {
253
+ :tag => 'knife',
254
+ :username => current_user,
255
+ :status => "#{organization}#{current_user} added run_list items to #{object_name}: #{object_secondary_name}",
256
+ :metadata => {
257
+ :node_name => object_name,
258
+ :run_list_items => object_secondary_name,
259
+ }.to_json
260
+ }
261
+ eventinate(event_data)
262
+ end
263
+
264
+ def after_noderunlistremove
265
+ event_data = {
266
+ :tag => 'knife',
267
+ :username => current_user,
268
+ :status => "#{organization}#{current_user} removed run_list items from #{object_name}: #{object_secondary_name}",
269
+ :metadata => {
270
+ :node_name => object_name,
271
+ :run_list_items => object_secondary_name,
272
+ }.to_json
273
+ }
274
+ eventinate(event_data)
275
+ end
276
+
277
+ def after_noderunlistset
278
+ event_data = {
279
+ :tag => 'knife',
280
+ :username => current_user,
281
+ :status => "#{organization}#{current_user} set the run_list for #{object_name} to #{object_secondary_name}",
282
+ :metadata => {
283
+ :node_name => object_name,
284
+ :run_list_items => object_secondary_name,
285
+ }.to_json
286
+ }
287
+ eventinate(event_data)
288
+ end
289
+
290
+ def eventinate(event_data)
291
+ begin
292
+ uri = URI.parse(config.url)
293
+ rescue Exception => e
294
+ ui.error 'Could not parse URI for Eventinator.'
295
+ ui.error e.to_s
296
+ return
297
+ end
298
+
299
+ http = Net::HTTP.new(uri.host, uri.port)
300
+ http.read_timeout = config.read_timeout || 5
301
+
302
+ request = Net::HTTP::Post.new(uri.request_uri)
303
+ request.set_form_data(event_data)
304
+
305
+ begin
306
+ response = http.request(request)
307
+ ui.error "Eventinator at #{config.url} did not receive a good response from the server" if response.code != '200'
308
+ rescue Timeout::Error
309
+ ui.error "Eventinator timed out connecting to #{config.url}. Is that URL accessible?"
310
+ rescue Exception => e
311
+ ui.error 'Eventinator error.'
312
+ ui.error e.to_s
313
+ end
314
+ end
315
+ end
316
+ end
317
+ end