Created
September 19, 2011 15:13
-
-
Save okochang/1226724 to your computer and use it in GitHub Desktop.
Login check and post error message to yammer.com
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
# -*- encoding: UTF-8 -*- | |
# このスクリプトはあるURLでログインして失敗したら警告メールをyammerに投稿するスクリプトです | |
# スクリプトを実行するには以下のライブラリが必要となりますので、事前にインストールして下さい | |
# gem install httpclient | |
# gem install tmail | |
# gem install tlsmail | |
require 'rubygems' | |
require 'httpclient' | |
require 'tmail' | |
require 'tlsmail' | |
## 接続先設定 | |
accessurl = 'https://www.example.com/login' | |
userid = 'yourid' | |
psword = 'yourpassword' | |
postdata = "userID=#{userid}&password=#{psword}" | |
## メール設定 | |
maildomain = 'yourdomain.com' | |
mailuser = '[email protected]' | |
mailpass = 'mailpassword' | |
mail = TMail::Mail.new | |
mail.to = '[email protected]' | |
mail.from = '[email protected]' | |
mail.subject = '#alertmail' | |
mail.date = Time.now | |
mail.mime_version = '1.0' | |
mail.set_content_type 'text/plain', {"charset"=>"iso-2022-jp"} | |
mail.body = "#{Time.now} Login_failed_check_for_your_Site" | |
## タイムアウトを指定して監視対象ページにログインをする | |
begin | |
client = HTTPClient.new | |
client.connect_timeout = 60 | |
client.send_timeout = 60 | |
client.receive_timeout = 60 | |
puts c.post_content(accessurl, postdata) | |
## 失敗だった場合はyammerに警告文を投稿する | |
rescue | |
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
Net::SMTP.start('smtp.gmail.com', 587, maildomain, mailuser, mailpass, 'plain') do |smtp| | |
smtp.sendmail(mail.encoded, mail.from, mail.to) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment