+#!/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);