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_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_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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/knife-spork/plugins/eventinator.rb', line 44

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