📜 ⬆️ ⬇️

How we started monitoring the domains and what came of it

Hello! It all started with the fact that we have divorced a lot of domains that need to be renewed on time. And so, after one failure with the extension of the domains, it was decided to start monitoring the expiration date of the domain and display it in Nagios monitoring.


How to monitor?



We had several domains in the zones kz, ru, kg, ge, com.
')
The easiest way to find out all the necessary information about the domain is to run whois. In theory, everyone should know this. But how to implement this whole thing in monitoring?

What to monitor?


Rummaging through the Internet, the python-whois module was found. He did a good job for the com, net and other domains described in the module description.

There was not enough functionality for several domains in kg zones.
As a result, a fork of the python-whois-extended project has appeared which expands the functionality for large TLDs.

Ok, how to implement nagios?



It's simple, we write a simple check.
#!/usr/bin/env python # # Usage: # python check_domain.py -d DOMAIN import whois from datetime import datetime from sys import exit from optparse import OptionParser def check_domain(domain): q = whois.query(domain) if (q.expiration_date - datetime.now()).days <= 30: print "CRITICAL: Domain: {0} expires on {1}".format(domain, q.expiration_date) exit(2) print "OK: Domain: {0} expires on {1}".format(domain, q.expiration_date) if __name__ == '__main__': parser = OptionParser() parser.add_option("-d", "--domain", dest="domain", help="Domain to monitor expiry date") (options, args) = parser.parse_args() if not options.domain: print parser.print_help() exit(0) check_domain(options.domain) 


What is he doing? Shines red in the monitoring for a month before the expiration of the domain.

Interestingly, another maintainer appeared, who added support for the hk, cn and kr TLD.

The current list of supported domains is:
com, net, org, uk, pl, ru, lv, jp, co_jp, de, at, eu, biz, info, name, us, co, me, be, nz, cz, it, fr, kg, vc, fm, tv, edu, ca, cn, kr, hk

Module code here
Pull requests, feature requests are invoked!
I hope my experience will help get rid of this problem.

Source: https://habr.com/ru/post/251619/


All Articles