Sha256: 05e411860cf676684a3525ed1a0a74aeae77d37bf6442b322efb8b3510f0abf4
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
module WatchmonkeyCli module Checkers class WwwAvailability < Checker self.checker_name = "www_availability" def enqueue page, opts = {} app.enqueue(self, page, opts.except(:ssl_expiration)) # if available enable ssl_expiration support if page.start_with?("https://") && opts[:ssl_expiration] != false && !app.running? spawn_sub("ssl_expiration", page, opts[:ssl_expiration].is_a?(Hash) ? opts[:ssl_expiration] : {}) end end def check! result, page, opts = {} begin resp = HTTParty.get(page, no_follow: true, verify: false) result.result = resp rescue HTTParty::RedirectionTooDeep => e result.result = e.response original_response = true rescue Errno::ECONNREFUSED => e result.error! "Failed to fetch #{page} (#{e.class}: #{e.message})" return end # status if opts[:status] stati = [*opts[:status]] result.error! "#{result.result.code} is not in #{stati}!" if !stati.include?(result.result.code.to_i) end # body fixed_body = result.result.body.force_encoding("utf-8") if rx = opts[:body] if rx.is_a?(String) result.error! "body does not include `#{rx}'!" if !fixed_body.include?(rx) elsif rx.is_a?(Regexp) result.error! "body does not match `#{rx}'!" if !fixed_body.match(rx) end end # headers if opts[:headers] hdata = original_response ? result.result : result.result.headers opts[:headers].each do |k, v| if !(v.is_a?(Regexp) ? hdata[k].match(v) : hdata[k] == v) result.error! "header #{k} mismatches (expected `#{v}' got `#{hdata[k] || "nil"}')" end end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
watchmonkey_cli-1.8.3 | lib/watchmonkey_cli/checkers/www_availability.rb |
watchmonkey_cli-1.8.2 | lib/watchmonkey_cli/checkers/www_availability.rb |