Skip to content

Instantly share code, notes, and snippets.

@andriytyurnikov
Last active August 12, 2019 08:58
Show Gist options
  • Select an option

  • Save andriytyurnikov/317a0a63123eea06025911f6a1250ac1 to your computer and use it in GitHub Desktop.

Select an option

Save andriytyurnikov/317a0a63123eea06025911f6a1250ac1 to your computer and use it in GitHub Desktop.
PokuponRuntimeChecker
#!/usr/bin/env ruby
require 'net/http'
require 'net/smtp'
class PokuponRuntimeChecker
SMTP_HOST = "smtp.gmail.com"
SMTP_PORT = 587
SMPT_FROM_DOMAIN = ""
SMTP_USERNAME = ""
SMTP_PASSWORD = ""
URIS = [ URI("https://pokupon.ua"),
URI("https://partner.pokupon.ua") ]
def run
while true do
URIS.each do |uri|
_check_uri(uri)
end
sleep 1
end
end
private
def _check_uri(uri)
response = Net::HTTP.get_response(uri)
unless response.is_a?(Net::HTTPSuccess)
_send_email_notification_for(uri)
end
end
def _send_email_notification_for(uri)
message = <<MESSAGE_END
From: <uptime.checker@pokupon.ua>
To: <alert@pokupon.ua>
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP e-mail test
Site #{uri.to_s} is down
MESSAGE_END
smtp = Net::SMTP.new(SMTP_HOST, SMTP_PORT)
smtp.enable_starttls_auto
smtp.start(
SMPT_FROM_DOMAIN,
SMTP_USERNAME,
SMTP_PASSWORD,
:login) do |smtp|
smtp.enable_tls
smtp.send_message message, "uptime.check@pokupon.ua", "alert@pokupon.ua"
end
end
end
PokuponRuntimeChecker.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment