add option to specify the rdap server

Signed-off-by: Alarig Le Lay <alarig@swordarmor.fr>
This commit is contained in:
Alarig Le Lay 2024-07-26 00:22:08 +02:00
parent 7a34bd7060
commit eacd1368d6
Signed by: alarig
GPG key ID: 7AFE62C6DF8BCDEC

View file

@ -105,10 +105,13 @@ def parse_ldap(domain, rdap_server):
return raw_expiration
def expiration(domain):
def expiration(domain, server):
"""Find the expiration date for the domain."""
raw_expiration = parse_ldap(domain, find_rdap_server(domain))
if server is None:
raw_expiration = parse_ldap(domain, find_rdap_server(domain))
else:
raw_expiration = parse_ldap(domain, server)
# we have parsed the eventAction field about expiration
if isinstance(raw_expiration[0], int):
@ -161,12 +164,13 @@ class Expiration(nagiosplugin.Resource):
not cached because we can not presume of the data lifetime.
"""
def __init__(self, domain):
def __init__(self, domain, server):
self.domain = domain
self.server = server
def probe(self):
try:
days_to_expiration = expiration(self.domain)
days_to_expiration = expiration(self.domain, self.server)
except requests.exceptions.ConnectionError as err:
raise nagiosplugin.CheckError(
f'The connection to the RDAP server failed: {err}'
@ -206,6 +210,9 @@ def main():
'-c', '--critical', metavar='range', default='15',
help='critical expiration max days. Default=15'
)
argp.add_argument(
'-s', '--server', default=None, help='Specify the RDAP base URL (eg. https://rdap.nic.bzh/)'
)
argp.add_argument(
'-v', '--verbose', action='count', default=0, help='be more verbose'
)
@ -229,7 +236,7 @@ def main():
domain = pyunycode.convert(args.domain)
check = nagiosplugin.Check(
Expiration(domain),
Expiration(domain, args.server),
nagiosplugin.ScalarContext(
'daystoexpiration',
warning=wrange,