From c09c063754e5e6dbd36e85870ef5cb61253aa1a0 Mon Sep 17 00:00:00 2001 From: Ron Griffin Date: Thu, 6 Oct 2016 15:21:18 -0500 Subject: [PATCH 05/10] If a queue is not found, report an UNKNOWN status (#75) * If a queue is not found, report an UNKNOWN status * Add ignore option to report an OK status if queue doesn't exist * Setting default value for ignore option --- scripts/check_rabbitmq_queue | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/check_rabbitmq_queue b/scripts/check_rabbitmq_queue index b8201d5..0909798 100755 --- a/scripts/check_rabbitmq_queue +++ b/scripts/check_rabbitmq_queue @@ -95,6 +95,11 @@ $p->add_arg(spec => 'proxyurl=s', help => "Use proxy url like http://proxy.domain.com:8080", ); +$p->add_arg(spec => 'ignore|ignore!', + help => "Ignore alerts if queue does not exist (default: false)", + default => 0 +); + # Parse arguments and process standard ones (e.g. usage, help, version) $p->getopts; @@ -131,6 +136,7 @@ my $port=$p->opts->port; my $vhost=uri_escape($p->opts->vhost); my $queue=$p->opts->queue; my $filter=$p->opts->filter; +my $ignore=$p->opts->ignore; my $ua = LWP::UserAgent->new; if (defined $p->opts->proxyurl) @@ -154,6 +160,9 @@ if ($queue eq "all"){ $url = sprintf("http%s://%s:%d/api/queues/%s/%s", ($p->opts->ssl ? "s" : ""), $hostname, $port, $vhost, $queue); } my ($retcode, $result) = request($url); +if ($retcode == 404 && $ignore) { + $p->nagios_exit(OK, "$result : $url"); +} if ($retcode != 200) { $p->nagios_exit(CRITICAL, "$result : $url"); } @@ -296,6 +305,12 @@ messages_unacknowledged and consumers. This field consists of one to four comma-separated thresholds. Specify -1 if no threshold for a particular count. +=item --ignore + +If the queue specified does not exist, this option ignores +CRITICAL alerts and returns a status of OK. Useful for scenarios +where queue existence is optional. + =back =head1 THRESHOLD FORMAT -- 2.20.1