Skip to content

Instantly share code, notes, and snippets.

@moski
Last active January 10, 2018 17:18
Show Gist options
  • Save moski/996567eeaed532d11425 to your computer and use it in GitHub Desktop.
Save moski/996567eeaed532d11425 to your computer and use it in GitHub Desktop.
How to integrate rollbar with AWS opsworks
require 'optparse'
require 'net/http'
namespace :rollbar do
desc "Notify Rollbar about a new deployment"
task :notify do
options = {
:environment => "staging",
:revision => `git log -n 1 --pretty=format:"%H"`,
:rollbar_username => "moski",
}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: rake rollbar::notify [options]"
opts.on("-a", "--access_token ARG", String) { |token| options[:access_token] = token }
opts.on("-e", "--environment ARG", String) { |env| options[:environment] = env}
opts.on("-r", "--revision ARG", String) { |rev| options[:revision] = rev}
opts.on("-u", "--rollbar_username ARG", String) { |u| options[:rollbar_username] = u}
end
optparse.parse!
raise OptionParser::MissingArgument if options[:access_token].nil?
raise OptionParser::MissingArgument if options[:environment].nil?
raise OptionParser::MissingArgument if options[:revision].nil?
raise OptionParser::MissingArgument if options[:rollbar_username].nil?
options[:comment] = `git show -s --format=%B #{options[:revision]}`.strip
puts "access_token = #{options[:access_token]}"
puts "environment= #{options[:environment]}"
puts "revision= #{options[:revision]}"
puts "rollbar_username= #{options[:rollbar_username]}"
puts "comment= #{options[:comment]}"
uri = URI.parse 'https://api.rollbar.com/api/1/deploy/'
request = Net::HTTP::Post.new(uri.request_uri)
request.body = ::JSON.dump(options)
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
http.request(request)
end
puts "Rollbar notification complete."
exit
end
end
# rake rollbar:notify -- --access_token XXXXXXX --rollbar_username moski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment