Skip to content

Instantly share code, notes, and snippets.

@kmayer
Created October 27, 2016 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmayer/abed3364ccd6906c2751a1dc51b604a8 to your computer and use it in GitHub Desktop.
Save kmayer/abed3364ccd6906c2751a1dc51b604a8 to your computer and use it in GitHub Desktop.
LogentriesAlertsController
class LogentriesAlertsController < ApplicationController
skip_before_action :verify_authenticity_token
def create
return head(:unprocessable_entity) unless
LogentriesAuth.new(request).authorized?
if what =~ /R1[45]/ &&
who =~ /web\.\d+/
Redis.current.set(
"puma::stop::#{who}",
"*** HEROKU ERROR #{what} ***",
ex: 60.seconds
)
end
head :ok
end
private
def logentries_payload
params.require(:payload)
end
def message
@message ||= JSON
.parse(logentries_payload)
.dig('event', 'm')
end
def who
@who ||= message
.match(/heroku ([^\s]+)/)
.to_a
.dig(1)
end
def what
@what ||= message
.match(/- - Error (\w\d+) /)
.to_a
.dig(1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment