class RooOnRails::Checks::Papertrail::DrainExists

Check if a Heroku app is setup to a log drain to Papertrail

Input context

Output context:

Public Instance Methods

call() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 28
def call
  # find the PT drain
  data = client.log_drain.list(app_name).
         select { |h| h['url'] =~ /papertrailapp/ }
  fail! "no Papertrail drain found on #{bold app_name}" if data.empty?
  fail! "multiple Papertrail drains found on #{bold app_name}" if data.length > 1

  data = data.first
  fail! "app is draining to #{data['url']} instead of #{papertrail_url}" if data['url'] != papertrail_url

  pass "found drain setup with token #{data['token']} on #{bold app_name}"
  context.papertrail.system_name![env] = data['token']
end
fix() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 42
def fix
  client.log_drain.create(app_name, url: papertrail_url)
end
intro() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 24
def intro
  'Checking for Papertrail drain...'
end

Private Instance Methods

app_name() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 48
def app_name
  context.heroku.app[env]
end
client() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 52
def client
  context.heroku.api_client
end
papertrail_url() click to toggle source
# File lib/roo_on_rails/checks/papertrail/drain_exists.rb, line 56
def papertrail_url
  format 'syslog+tls://%s:%s',
         context.papertrail.dest.host,
         context.papertrail.dest.port
end