Sha256: 6cd4154e379a3e104837652cd43c3b6a6b5f85171f243bf6b78a3c9634e66e65

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8
#
#   check-whois-domain-expiration
#
# DESCRIPTION:
#   This plugin checks domain expiration dates using the 'whois' gem.
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Tested on Mac OS X
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: whois
#
# USAGE:
#   $ ./check-whois-domain-expiration.rb -d mijit.com
#   WhoisDomainExpirationCheck OK: mijit.com expires on 02-07-2016 (325 days away)
#
# LICENSE:
#   Copyright 2015 michael j talarczyk <mjt@mijit.com> and contributors.
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.

require 'sensu-plugin/check/cli'
require 'whois'
require 'whois-parser'

#
# Check Whois domain expiration
#
class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
  option :domain,
         short: '-d DOMAIN',
         long: '--domain DOMAIN',
         required: true,
         description: 'Domain to check'

  option :warning,
         short: '-w DAYS',
         long: '--warn DAYS',
         default: 30,
         description: 'Warn if fewer than DAYS away'

  option :critical,
         short: '-c DAYS',
         long: '--critical DAYS',
         default: 7,
         description: 'Critical if fewer than DAYS away'

  option :help,
         short: '-h',
         long: '--help',
         description: 'Show this message',
         on: :tail,
         boolean: true,
         show_options: true,
         exit: 0

  def check_days(num_days,
                 warning_days = config[:warning].to_i,
                 critical_days = config[:critical].to_i)
    if num_days <= critical_days
      critical
    elsif num_days <= warning_days
      warning
    else
      ok
    end
  end

  def initialize
    super()
    whois = Whois.whois(config[:domain])
    @expires_on = DateTime.parse(whois.parser.expires_on.to_s)
    @num_days = (@expires_on - DateTime.now).to_i
  end

  def run
    message "#{config[:domain]} expires on #{@expires_on.strftime('%m-%d-%Y')} (#{@num_days} days away)"
    check_days @num_days
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sensu-plugins-network-checks-2.2.0 bin/check-whois-domain-expiration.rb
sensu-plugins-network-checks-2.1.1 bin/check-whois-domain-expiration.rb
sensu-plugins-network-checks-2.1.0 bin/check-whois-domain-expiration.rb
sensu-plugins-network-checks-2.0.1 bin/check-whois-domain-expiration.rb