Skip to content

Instantly share code, notes, and snippets.

@neilmarion
Created April 25, 2017 13:54
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 neilmarion/3aaeb0cfa812c12763fb50e71ca78ff1 to your computer and use it in GitHub Desktop.
Save neilmarion/3aaeb0cfa812c12763fb50e71ca78ff1 to your computer and use it in GitHub Desktop.
module HealthCheck
class SlackNotification
attr_accessor :health_check
def initialize(health_check)
@health_check = health_check
end
def send
if beyond_threshold? && activated? && !Rails.env.development?
HTTParty.post(webhook_url,
headers: {'Content-Type' => 'application/json'},
body: request_body.to_json,
)
end
end
private
def request_body
{
username: "g5dashboard",
text: health_check.display_item_list,
icon_emoji: ":white_check_mark:",
channel: health_check.slack_channel,
}
end
def beyond_threshold?
health_check.beyond_threshold?
end
def activated?
health_check.activated?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment