Created
October 27, 2016 21:22
-
-
Save kmayer/abed3364ccd6906c2751a1dc51b604a8 to your computer and use it in GitHub Desktop.
LogentriesAlertsController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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