]> ruderich.org/simon Gitweb - misc/misc.git/blob - icinga/check_nsd_zonestatus
icinga/check_nsd_zonestatus: add
[misc/misc.git] / icinga / check_nsd_zonestatus
1 #!/usr/bin/perl
2
3 # Simple Nagios-compatible checker for NSD zone status.
4
5 # SPDX-License-Identifier: GPL-3.0-or-later
6 # Copyright (C) 2021-2024  Simon Ruderich
7
8
9 use strict;
10 use warnings;
11 use autodie;
12
13 use Monitoring::Plugin;
14
15
16 my $np = Monitoring::Plugin->new;
17
18 my $zone;
19 open my $fh, '-|', '/usr/sbin/nsd-control', 'zonestatus';
20 while (<$fh>) {
21     if (/^zone:\s+(.+)$/) {
22         $zone = $1;
23         next;
24     }
25     if (/^\s+state: (.+)$/) {
26         unless (defined $zone) {
27             $np->add_message(CRITICAL, "cannot parse `nsd-control` output");
28             next;
29         }
30
31         if ($1 eq 'ok' or $1 eq 'master') {
32             # This is fine
33         } elsif ($1 eq 'refreshing') {
34             $np->add_message(WARNING, "$zone: status $1");
35         } else {
36             $np->add_message(CRITICAL, "$zone: status $1");
37         }
38         $zone = undef;
39     }
40 }
41 close $fh;
42
43 $np->plugin_exit($np->check_messages);