3 # Simple Nagios-compatible checker for BIRD protocols.
5 # SPDX-License-Identifier: GPL-3.0-or-later
6 # Copyright (C) 2016-2023 Simon Ruderich
13 use Monitoring::Plugin;
14 use IO::Socket::UNIX ();
17 my $np = Monitoring::Plugin->new(
18 usage => "usage: %s [-s <socket>] <proto>..",
22 help => 'Path to bird UNIX control socket.',
23 default => '/run/bird/bird.ctl',
28 $np->plugin_exit(OK, 'no protocols specified');
31 alarm $np->opts->timeout; # handler already set by Monitoring::Plugin
34 my $bird = IO::Socket::UNIX->new(
35 Type => IO::Socket::UNIX::SOCK_STREAM,
36 Peer => $np->opts->socket,
37 ) or $np->plugin_exit(CRITICAL, "failed to open '" . $np->opts->socket . "'");
39 $_ = <$bird> // $np->plugin_exit(CRITICAL, 'failed to read hello');
40 /^0001 / or $np->plugin_exit(CRITICAL, 'invalid hello');
47 // $np->plugin_exit(CRITICAL, "failed to send command '$cmd'");
51 next if /^\+/; # ignore spontaneous printout
55 $np->plugin_exit(CRITICAL,
56 "error while running command '$cmd': $_");
60 return @result if /^\d{4} /;
62 $np->plugin_exit(CRITICAL, "incomplete output for command '$cmd'");
65 foreach my $name (@ARGV) {
66 foreach (bird_command("show protocols $name")) {
70 my @data = split /\s+/, $_, 6;
73 my $status = $data[3];
74 my $info = $data[5] // '';
75 # Hacky workaround for "timeformat protocol iso long"
76 $info =~ s/^\d{2}:\d{2}:\d{2}\s+//;
78 # Administratively disabled.
79 if ($status ne 'up') {
80 $np->add_message(CRITICAL, "protocol '$name' not up");
84 if ($proto eq 'BGP') {
85 $failed = 1 if $info ne 'Established';
86 } elsif ($proto eq 'OSPF') {
87 $failed = 1 if $info ne 'Running';
89 $np->add_message(WARNING, "unknown protocol '$proto', "
90 . 'please file a bug report');
93 $np->add_message(CRITICAL, "protocol '$name' not running: '$info'");
98 $np->plugin_exit($np->check_messages(join => ', '));