sensu-plugins / sensu-plugins-network-checks

This plugin provides native network instrumentation for monitoring and metrics collection, including: hardware, TCP response, RBLs, whois, port status, and more.
http://sensu-plugins.io
MIT License
30 stars 76 forks source link

Rework whois checks #71

Closed DrMurx closed 6 years ago

DrMurx commented 6 years ago

Pull Request Checklist

General

Purpose

Improved exception resilience and error reporting of the various whois checks. Also added options to either ignore errors, or report them as warning/critical.

Known Compatibility Issues

The textual output of check-whois-domain-expiration-multi.rb and check-jsonwhois-domain-expiration.rb has slightly changed

majormoses commented 6 years ago

@DrMurx thanks for the contribution! Let me know if you need any help getting through the CI issues.

DrMurx commented 6 years ago

Fixed.

DrMurx commented 6 years ago

I forgot to mention that this solves #67 (like #70 does too) and at least assures that the check doesn't crash, so it would partially solve #61 too.

majormoses commented 6 years ago

@DrMurx thanks for fixing this up overall it looks good (as no one got to my review we will probably close that in favor of this one). Any chance I could get you to provide a testing artifact? It can be manual or automated just something that let's me know it fixes the issue. If manual it is best to include a before and after.

DrMurx commented 6 years ago

@majormoses Sure :)

Here's a manual check on a German TLD (the DeNIC doesn't report any expiration timestamps):

Before:

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
$ ./bin/check-whois-domain-expiration.rb -d google.de
Check failed to run: Whois::AttributeNotSupported, ["/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:130:in `_property_expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:393:in `handle_property'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:240:in `expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:348:in `delegate_property_to_parsers'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:312:in `expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:333:in `method_missing'", "./bin/check-whois-domain-expiration.rb:78:in `initialize'", "/usr/local/lib/ruby/gems/2.5.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:57:in `new'", "/usr/local/lib/ruby/gems/2.5.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"]
$ ./bin/check-whois-domain-expiration-multi.rb -d google.de
Check failed to run: Whois::AttributeNotSupported, ["/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:130:in `_property_expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:393:in `handle_property'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parsers/base.rb:240:in `expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:348:in `delegate_property_to_parsers'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:312:in `expires_on'", "/usr/local/lib/ruby/gems/2.5.0/gems/whois-parser-1.0.0/lib/whois/parser.rb:333:in `method_missing'", "./bin/check-whois-domain-expiration-multi.rb:96:in `block in expiration_results'", "./bin/check-whois-domain-expiration-multi.rb:86:in `each'", "./bin/check-whois-domain-expiration-multi.rb:86:in `expiration_results'", "./bin/check-whois-domain-expiration-multi.rb:113:in `run'", "/usr/local/lib/ruby/gems/2.5.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]
$ ./bin/check-jsonwhois-domain-expiration.rb  -a xxxxxxx -d google.de
Check failed to run: no implicit conversion of nil into String, ["./bin/check-jsonwhois-domain-expiration.rb:112:in `parse'", "./bin/check-jsonwhois-domain-expiration.rb:112:in `get_domain_expiration'", "./bin/check-jsonwhois-domain-expiration.rb:86:in `block in expiration_results'", "./bin/check-jsonwhois-domain-expiration.rb:85:in `each'", "./bin/check-jsonwhois-domain-expiration.rb:85:in `expiration_results'", "./bin/check-jsonwhois-domain-expiration.rb:116:in `run'", "/usr/local/lib/ruby/gems/2.5.0/gems/sensu-plugin-1.4.5/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]

After:

$ git checkout rework_whois_checks
Switched to branch 'rework_whois_checks'
Your branch is up to date with 'origin/rework_whois_checks'.
$ ./bin/check-whois-domain-expiration.rb -d google.de
WhoisDomainExpirationCheck UNKNOWN: google.de can't be checked
$ ./bin/check-whois-domain-expiration-multi.rb -d google.de
WhoisDomainExpirationCheck UNKNOWN: google.de (Parsing error)
$ ./bin/check-jsonwhois-domain-expiration.rb  -a xxxxxxx -d google.de
JSONWhoisDomainExpirationCheck UNKNOWN: google.de (Connection or parsing error)
DrMurx commented 6 years ago

And that's for the new flags I introduced to change the test's criticality in those cases:

$ ./bin/check-whois-domain-expiration-multi.rb -i -d google.de
WhoisDomainExpirationCheck OK: No domains expire in the near term
$ ./bin/check-whois-domain-expiration-multi.rb -r warning -d google.de
WhoisDomainExpirationCheck WARNING: google.de (Parsing error)
$ ./bin/check-whois-domain-expiration-multi.rb -r critical -d google.de
WhoisDomainExpirationCheck CRITICAL: google.de (Parsing error)
majormoses commented 6 years ago

Thanks for that, I will get this released shortly.

majormoses commented 6 years ago

As I just merged and released another PR I rebased on your behalf, as soon as CI passes again I will merge and release.

majormoses commented 6 years ago

released: https://rubygems.org/gems/sensu-plugins-network-checks/versions/2.3.0