Last active
December 17, 2015 08:49
Revisions
-
mikeda revised this gist
May 15, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/local/bin/ruby # -*- encoding: utf-8 -*- require 'net/http' -
mikeda created this gist
May 15, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/naviplus/ruby/sysadmin/bin/ruby # -*- encoding: utf-8 -*- require 'net/http' require 'uri' require 'pp' configs = [ { desc: '正常', url: 'http://mikeda.jp/wiki/', regex: /MikedaWiki/, timeout: 1}, { desc: '中身がおかしい', url: 'http://mikeda.jp/wiki/', regex: /XXXYYYZZZ/, timeout: 1}, { desc: '重たい', url: 'http://test01.mikeda.jp/5sec.php', regex: /test/, timeout: 1}, { desc: 'NotFound', url: 'http://test01.mikeda.jp/notfound', regex: /test/, timeout: 1}, { desc: '接続できない', url: 'http://s01.mikeda.jp/', regex: /test/, timeout: 1}, { desc: '名前解決できない', url: 'http://XXX.mikeda.jp', regex: /test/, timeout: 1}, ] errors = [] configs.each do |config| # puts "check #{config[:desc]}" url = URI.parse(config[:url]) begin http = Net::HTTP.new(url.host, url.port) http.open_timeout = 1 # とりあえず res = http.start {|http| http.read_timeout = config[:timeout] http.get(url.path) } rescue Timeout::Error errors << "Error #{config[:desc]}: timeout(#{config[:timeout]}sec)" next rescue => e errors << e.to_s next end if res.code != "200" errors << "Error #{config[:desc]}: bad response(#{res.code})" elsif res.body !~ config[:regex] errors << "Error #{config[:desc]}: node include '#{config[:regex].to_s}'" end end pp errors exit errors.empty? ? 0 : 2