Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy notification lwrp #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions providers/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
action :notify do

require 'httparty'

class Deploy
include HTTParty
format :xml
base_uri 'rpm.newrelic.com'

def initialize
end

def notify(key, app, failure_ok)

@options = {
:headers => { 'x-license-key' => key },
:body => "deployment[app_name]=#{app}"
}
response = self.class.post('/deployments.xml', @options)

if response.has_key?('errors')
if failure_ok
Chef::Log.error("New Relic deploy notification error: #{response['errors']['error']}")
else
Chef::Log.error("New Relic deploy notification error: #{response['errors']['error']}")
raise
end
end
end
end

app = @new_resource.app || @new_resource.name
newrelic = Deploy.new
newrelic.notify(@new_resource.key, app, @new_resource.failure_ok)
end
6 changes: 6 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
# limitations under the License.
#

httparty = chef_gem 'httparty' do
action :nothing
end

httparty.run_action(:install)

case node[:platform]
when "ubuntu", "debian"
include_recipe "newrelic::debian"
Expand Down
11 changes: 11 additions & 0 deletions resources/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def initialize(*args)
super
@action = :notify
end

actions :notify

attribute :key, :kind_of => String, :required => true
attribute :app, :kind_of => String, :required => false
attribute :name, :kind_of => String, :required => true, :name_attribute => true
attribute :failure_ok, :kind_of => [ TrueClass, FalseClass ], :default => true