From d3936963d191fc837cade5b184aa5e59f240c0b5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 10 Jan 2024 21:00:57 +0100 Subject: [PATCH] icinga/check_nsd_zonestatus: add --- README.adoc | 3 +++ icinga/check_nsd_zonestatus | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 icinga/check_nsd_zonestatus diff --git a/README.adoc b/README.adoc index dfb87b4..2f42365 100644 --- a/README.adoc +++ b/README.adoc @@ -4,6 +4,9 @@ Repository of miscellaneous tools which might be useful to others. They are licensed under GPLv3+ except where otherwise noted. :bird: https://bird.network.cz/ +:nsd: https://www.nlnetlabs.nl/projects/nsd/about/ - icinga/check_bird: Connect to {bird}[BIRD] and check if a given list of protocols is running. +- check_nsd_zonestatus: Connect to {nsd}[NSD] and check if all zones are find + (and e.g. not "refreshing"). diff --git a/icinga/check_nsd_zonestatus b/icinga/check_nsd_zonestatus new file mode 100755 index 0000000..a47783e --- /dev/null +++ b/icinga/check_nsd_zonestatus @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +# Simple Nagios-compatible checker for NSD zone status. + +# SPDX-License-Identifier: GPL-3.0-or-later +# Copyright (C) 2021-2024 Simon Ruderich + + +use strict; +use warnings; +use autodie; + +use Monitoring::Plugin; + + +my $np = Monitoring::Plugin->new; + +my $zone; +open my $fh, '-|', '/usr/sbin/nsd-control', 'zonestatus'; +while (<$fh>) { + if (/^zone:\s+(.+)$/) { + $zone = $1; + next; + } + if (/^\s+state: (.+)$/) { + unless (defined $zone) { + $np->add_message(CRITICAL, "cannot parse `nsd-control` output"); + next; + } + + if ($1 eq 'ok' or $1 eq 'master') { + # This is fine + } elsif ($1 eq 'refreshing') { + $np->add_message(WARNING, "$zone: status $1"); + } else { + $np->add_message(CRITICAL, "$zone: status $1"); + } + $zone = undef; + } +} +close $fh; + +$np->plugin_exit($np->check_messages); -- 2.44.1