class KnifeSpork::Plugins::Eventinator

Public Instance Methods

after_databagcreate() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 165
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_databagdelete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 177
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_databagedit() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 152
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_databagfromfile() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 202
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_databagitemdelete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 189
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_delete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 27
def after_delete
  event_data = {
    :tag => 'knife',
    :username => current_user,
    :status => "#{organization}#{current_user} deleted the following cookbooks: #{misc_output}",
    :metadata => {
      :deleted_cookbooks => misc_output
    }.to_json
  }
  eventinate(event_data)
end
after_environmentcreate() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 80
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_environmentdelete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 92
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_environmentedit() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 68
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_environmentfromfile() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 56
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_nodecreate() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 239
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_nodedelete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 227
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_nodeedit() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 215
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_nodefromfile() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 251
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_noderunlistadd() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 263
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_noderunlistremove() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 276
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_noderunlistset() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 289
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_remote() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 39
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_rolecreate() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 128
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_roledelete() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 140
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_roleedit() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 116
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_rolefromfile() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 104
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_upload() click to toggle source
# 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) click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 302
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
perform() click to toggle source
# File lib/knife-spork/plugins/eventinator.rb, line 10
def perform; end