Sha256: 86f452972d70e344eecf07dc8b40e5bef1e0ef808f87c1ec57aaf9ca224e8619

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require 'net/http'

module Bib
  module Opsworks
    class Newrelic

      def publish_deployment(app_name, deploy_data, newrelic_api_key)
        newrelic_params = prepare_publishing_data(app_name, deploy_data)

        newrelic_url = "https://rpm.newrelic.com/deployments.xml"
        url = URI.parse(newrelic_url)
        request = Net::HTTP::Post.new(url.request_uri)
        request.add_field('X-Api-Key', newrelic_api_key)
        request.set_form_data(newrelic_params)

        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        resp = http.request(request)

        resp.is_a? Net::HTTPSuccess
      end

      def prepare_publishing_data(app_name, deploy_data)
        scm_revision = deploy_data["scm"]["revision"]

        if deploy_data["deploying_user"].nil? or deploy_data["deploying_user"].empty?
          deployment_user = "opsworks"
        else
          deployment_user = deploy_data["deploying_user"].split('/')[1]
        end

        newrelic_params = {}
        {
          :app_name => app_name, 
          :user => deployment_user, 
          :revision => scm_revision
        }.each do |k, v|
          newrelic_params["deployment[#{k}]"] = v unless v.nil? || v == ''
        end
        newrelic_params
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
BibOpsworks-0.0.8 lib/bib/opsworks/newrelic.rb
BibOpsworks-0.0.7 lib/bib/opsworks/newrelic.rb