#!/usr/bin/python
+from __future__ import print_function
import ldns
-import unbound
+from unbound import ub_ctx, idn2dname, RR_TYPE_SOA, RR_TYPE_RRSIG, ub_strerror
from optparse import OptionParser
import sys
from datetime import datetime, timedelta
return delta
def check_dnssec_expire(resolver, name, warn, crit):
- s, result = resolver.resolve(name)
+ s, result = resolver.resolve(name, rrtype=RR_TYPE_SOA)
if 0 != s:
- pass
+ ub_strerror(s)
+ return
s, packet = ldns.ldns_wire2pkt(result.packet)
- rrsigs = packet.rr_list_by_type(unbound.RR_TYPE_RRSIG, ldns.LDNS_SECTION_ANSWER).rrs()
+ rrsigs = packet.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_ANSWER).rrs()
for rrsig in rrsigs:
delta = parse_rrsig_expire(str(rrsig.rrsig_expiration()))
if delta < crit:
- print "CRIT (%s) %s" % (delta, name)
+ print("CRIT (%s) %s" % (delta, name))
elif delta < warn:
- print "WARN (%s) %s" % (delta, name)
+ print("WARN (%s) %s" % (delta, name))
def main():
opts, _args = parser.parse_args()
- resolver = unbound.ub_ctx()
+ resolver = ub_ctx()
resolver.add_ta_file(opts.ancor)
+ encoding = sys.getfilesystemencoding()
for name in opts.names:
- check_dnssec_expire(resolver, name, timedelta(opts.warn), timedelta(opts.crit))
+ check_dnssec_expire(resolver, idn2dname(name.decode(encoding)),
+ timedelta(opts.warn), timedelta(opts.crit))
if __name__ == "__main__":
main()