#!/usr/bin/python3
#
# Univention Monitoring Plugin
#
# SPDX-FileCopyrightText: 2022-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

from univention.config_registry import ucr
from univention.monitoring import Alert


class DNS(Alert):

    def write_metrics(self):
        hostname = ucr.get('monitoring/dns/lookup-domain', 'www.univention.de')
        rc, output = self.exec_command(['/usr/lib/nagios/plugins/check_dns', '-H', hostname])
        self.write_metric('univention_dns_resolveable', 1 if rc == 0 else 0)
        self.log.debug(output)


if __name__ == '__main__':
    DNS.main()
