-
-
Save bmurtagh/a39526a7610103872dbe to your computer and use it in GitHub Desktop.
This file contains 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
require 'mechanize' | |
require 'nokogiri' | |
require 'mail' | |
require 'yaml' | |
# current time for entries | |
def current_time | |
time = Time.new | |
time.strftime("%b %d %H:%M:%S") | |
end | |
# testing reading config values from config file | |
config = YAML.load_file('config.yaml') | |
smtp_server = config['smtp_server'] | |
username = config['username'] | |
password = config['password'] | |
port = config['port'] | |
use_ttls = config['use_ttls'] | |
use_ssl = config['use_ssl'] | |
enable_auto_ttls = config['enable_auto_ttls'] | |
openssl_verify_mode = config['openssl_verify_mode'] | |
#puts "#{config['smtp_server']}" | |
#puts "#{config['username']}" | |
#puts "#{config['password']}" | |
#puts "#{config['port']}" | |
#puts "#{config['use_ttls']}" | |
#puts "#{config['use_ssl']}" | |
#puts "#{config['enable_auto_ttls']}" | |
#puts "#{config['openssl_verify_mode']}" | |
#p @smtp_server | |
#p @username | |
#p @password | |
#p @port | |
#p @use_ttls | |
#p @use_ssl | |
#p @enable_auto_ttls | |
#p @openssl_verify_mode | |
# email notification | |
def send_email(sub, message) | |
#Mail.defaults do | |
# delivery_method :smtp, { | |
# address: @smtp_server, # fqdn or ip of mail server | |
# port: @port, | |
# user_name: @username, | |
# password: @password, | |
# enable_starttls_auto: @enable_auto_ttls, | |
# openssl_verify_mode: @openssl_verify_mode, | |
# ssl: @use_ssl, | |
# tls: @use_ttls, | |
# } | |
#end | |
Mail.defaults do | |
delivery_method :smtp, { | |
address: "", # fqdn or ip of mail server | |
port: 25, | |
user_name: "", | |
password: "", | |
enable_starttls_auto: false, | |
openssl_verify_mode: "none", | |
ssl: false, | |
tls: false, | |
} | |
end | |
Mail.deliver do | |
from 'test@domain.com' | |
to 'test2@domain.com' | |
subject sub | |
body message | |
end | |
end | |
class CoreDial_AWS_Status | |
def initialize | |
url = 'http://status.aws.amazon.com' | |
agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } | |
# catch if we get a bad response (non-200, 301, 302) from url | |
begin | |
html = agent.get(url).body | |
rescue Mechanize::ResponseCodeError => e | |
puts e.response_code | |
send_email("[AWS_URL_ISSUE] " + " - " + url + " (" + e.response_code + ")", url + " (" + e.response_code + ")") | |
end | |
@html_doc = Nokogiri::HTML(html) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment