How we started monitoring domains and what came of it

    Hello! It all started with the fact that we have a lot of domains in our company that need to be renewed on time. And so, after one failure with domain renewal, it was decided to start monitoring the domain expiration date 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 domain information you need is to run whois. This, in theory, everyone should know. But how to implement this whole thing into monitoring?

    How to monitor?

    After digging around the Internet, the python-whois module was found . He did his job well for the com, net domains and heaps of other domains described in the module description.

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

    Ok, how to introduce into a nagios?

    It's simple, write a simple check
    #!/usr/bin/env python
    # Usage:
    # python -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 - <= 30:
            print "CRITICAL: Domain: {0} expires on {1}".format(domain, q.expiration_date)
        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()

    What is he doing? Lights up red in monitoring a month before the domain expires.

    Interestingly, another maintainer appeared that added support for hk, cn, and kr TLDs.

    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
    Pool requests, feature requests are welcome!
    I hope my experience will help get rid of this problem.

    Also popular now: