diff --git a/.gitignore b/.gitignore index 9106b2a..63d50ed 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /pkg/ /spec/reports/ /tmp/ +/production/ diff --git a/lib/xmon.rb b/lib/xmon.rb index 2015d8a..a64b6ce 100644 --- a/lib/xmon.rb +++ b/lib/xmon.rb @@ -12,6 +12,7 @@ require_relative "xmon/dns" require_relative "xmon/rdap" require_relative "xmon/reverse_dns" +require_relative "xmon/whois" module Xmon class Error < StandardError; end diff --git a/lib/xmon/descriptions.rb b/lib/xmon/descriptions.rb index 7291b40..fde4df9 100644 --- a/lib/xmon/descriptions.rb +++ b/lib/xmon/descriptions.rb @@ -80,6 +80,11 @@ def dns(&) @description = Xmon::DNS.new(self) describe(&) end + + def whois(&) + @description = Xmon::Whois.new(self) + describe(&) + end end class IPv4Description < Description diff --git a/lib/xmon/whois.rb b/lib/xmon/whois.rb index b66df79..0cf0863 100644 --- a/lib/xmon/whois.rb +++ b/lib/xmon/whois.rb @@ -2,8 +2,29 @@ module Xmon class Whois < Description + def initialize(parent, **opts) + @parent = parent + @domain = parent.name + define_attributes([:registrant, :registrar, :expires]) + end + def fetch(record) - ::Whois.whois(record) + response = ::Whois.whois(record) + # only joker.com compatible + { + registrar: response.match(/Registrar URL: https:\/\/(.*)/)[1].strip, + registrant: response.match(/Registrant Organization: (.*)/)[1].strip, + expiration: response.match(/Registrar Registration Expiration Date: (.*)/)[1].strip, + status: response.match(/Domain Status: (.*)/)[1].strip + } + end + + def check + checker = fetch(@domain) + [Xmon.compare(@status, checker[:status].split(" ").first, self), + Xmon.compare(@registrant, checker[:registrant], self), + Xmon.compare(@registrar, checker[:registrar], self), + Xmon.compare(@expires, checker[:expiration][0, 10], self)] end end end