Class: KnifeSpork::Plugins::Eventinator

Inherits:
Plugin
  • Object
show all
Defined in:
lib/knife-spork/plugins/eventinator.rb

Instance Method Summary collapse

Methods inherited from Plugin

#enabled?, hook, hooks, #initialize, name

Constructor Details

This class inherits a constructor from KnifeSpork::Plugins::Plugin

Instance Method Details

#after_databagcreateObject



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/knife-spork/plugins/eventinator.rb', line 153

def after_databagcreate
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} created data bag #{object_name}",
      :metadata => {
          :databag_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_databagdeleteObject



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/knife-spork/plugins/eventinator.rb', line 165

def after_databagdelete
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} deleted data bag item #{object_name}",
      :metadata => {
          :databag_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_databageditObject



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/knife-spork/plugins/eventinator.rb', line 140

def after_databagedit
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} edited data bag item #{object_name}:#{object_secondary_name}",
      :metadata => {
          :databag_name => object_name,
          :databag_item => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_databagfromfileObject



190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/knife-spork/plugins/eventinator.rb', line 190

def after_databagfromfile
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} uploaded data bag item #{object_name}:#{object_secondary_name}",
      :metadata => {
          :databag_name => object_name,
          :databag_item => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_databagitemdeleteObject



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/knife-spork/plugins/eventinator.rb', line 177

def after_databagitemdelete
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} deleted data bag item #{object_name}:#{object_secondary_name}",
      :metadata => {
          :databag_name => object_name,
          :databag_item => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_environmentcreateObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/knife-spork/plugins/eventinator.rb', line 68

def after_environmentcreate
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} created environment #{object_name}",
      :metadata => {
          :environment_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_environmentdeleteObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/knife-spork/plugins/eventinator.rb', line 80

def after_environmentdelete
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} deleted environment #{object_name}",
      :metadata => {
          :environment_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_environmenteditObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/knife-spork/plugins/eventinator.rb', line 56

def after_environmentedit
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} edited environment #{object_name}",
      :metadata => {
          :environment_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_environmentfromfileObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/knife-spork/plugins/eventinator.rb', line 44

def after_environmentfromfile
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} uploaded environment #{object_name}",
      :metadata => {
          :environment_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_nodecreateObject



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/knife-spork/plugins/eventinator.rb', line 227

def after_nodecreate
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} created node #{object_name}",
      :metadata => {
          :node_name => object_name
      }.to_json
  }
  eventinate(event_data)
end

#after_nodedeleteObject



215
216
217
218
219
220
221
222
223
224
225
# File 'lib/knife-spork/plugins/eventinator.rb', line 215

def after_nodedelete
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} deleted node #{object_name}",
      :metadata => {
          :node_name => object_name
      }.to_json
  }
  eventinate(event_data)
end

#after_nodeeditObject



203
204
205
206
207
208
209
210
211
212
213
# File 'lib/knife-spork/plugins/eventinator.rb', line 203

def after_nodeedit
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} edited node #{object_name}",
      :metadata => {
          :node_name => object_name
      }.to_json
  }
  eventinate(event_data)
end

#after_nodefromfileObject



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/knife-spork/plugins/eventinator.rb', line 239

def after_nodefromfile
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} uploaded node #{object_name}",
      :metadata => {
          :node_name => object_name
      }.to_json
  }
  eventinate(event_data)
end

#after_noderunlistaddObject



251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/knife-spork/plugins/eventinator.rb', line 251

def after_noderunlistadd
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} added run_list items to #{object_name}: #{object_secondary_name}",
      :metadata => {
          :node_name => object_name,
          :run_list_items => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_noderunlistremoveObject



264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/knife-spork/plugins/eventinator.rb', line 264

def after_noderunlistremove
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} removed run_list items from #{object_name}: #{object_secondary_name}",
      :metadata => {
          :node_name => object_name,
          :run_list_items => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_noderunlistsetObject



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/knife-spork/plugins/eventinator.rb', line 277

def after_noderunlistset
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} set the run_list for #{object_name} to #{object_secondary_name}",
      :metadata => {
          :node_name => object_name,
          :run_list_items => object_secondary_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_promote_remoteObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/knife-spork/plugins/eventinator.rb', line 27

def after_promote_remote
  environments.each do |environment|
    cookbooks.each do |cookbook|
      event_data = {
        :tag => 'knife',
        :username => current_user,
        :status => "#{organization}#{current_user} promoted #{cookbook.name}(#{cookbook.version}) to #{environment.name}",
        :metadata => {
          :cookbook_name => cookbook.name,
          :cookbook_version => cookbook.version
        }.to_json
      }
      eventinate(event_data)
    end
  end
end

#after_rolecreateObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/knife-spork/plugins/eventinator.rb', line 116

def after_rolecreate
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} created role #{object_name}",
      :metadata => {
          :role_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_roledeleteObject



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/knife-spork/plugins/eventinator.rb', line 128

def after_roledelete
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} deleted role #{object_name}",
      :metadata => {
          :role_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_roleeditObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/knife-spork/plugins/eventinator.rb', line 104

def after_roleedit
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} edited role #{object_name}",
      :metadata => {
          :role_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_rolefromfileObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/knife-spork/plugins/eventinator.rb', line 92

def after_rolefromfile
  event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} uploaded role #{object_name}",
      :metadata => {
          :role_name => object_name,
      }.to_json
  }
  eventinate(event_data)
end

#after_uploadObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/knife-spork/plugins/eventinator.rb', line 12

def after_upload
  cookbooks.each do |cookbook|
    event_data = {
      :tag => 'knife',
      :username => current_user,
      :status => "#{organization}#{current_user} uploaded and froze #{cookbook.name}@#{cookbook.version}",
      :metadata => {
        :cookbook_name => cookbook.name,
        :cookbook_version => cookbook.version
      }.to_json
    }
    eventinate(event_data)
  end
end

#eventinate(event_data) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/knife-spork/plugins/eventinator.rb', line 290

def eventinate(event_data)
  begin
      uri = URI.parse(config.url)
    rescue Exception => e
      ui.error 'Could not parse URI for Eventinator.'
      ui.error e.to_s
      return
    end

    http = Net::HTTP.new(uri.host, uri.port)
    http.read_timeout = config.read_timeout || 5

    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data(event_data)

    begin
      response = http.request(request)
      ui.error "Eventinator at #{config.url} did not receive a good response from the server" if response.code != '200'
    rescue Timeout::Error
      ui.error "Eventinator timed out connecting to #{config.url}. Is that URL accessible?"
    rescue Exception => e
      ui.error 'Eventinator error.'
      ui.error e.to_s
    end
end

#performObject



10
# File 'lib/knife-spork/plugins/eventinator.rb', line 10

def perform; end