3
### check_rabbitmq_watermark.pl
5
# Use the management API to check if mem_alarm or disk_free_alarm has been triggered.
7
# Originally by Nathan Vonnahme, n8v at users dot sourceforge
8
# dot net, July 19 2006
10
##############################################################################
20
use vars qw($VERSION $PROGNAME $verbose $timeout);
23
# get the base name of this script for use in the examples
25
$PROGNAME = basename($0);
28
##############################################################################
29
# define and get the command line options.
30
# see the command line option guidelines at
31
# http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS
34
# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory)
35
my $p = Nagios::Plugin->new(
36
usage => "Usage: %s [options] -H hostname",
39
blurb => 'This plugin uses the RabbitMQ management API to check if the mem_alarm or disk_free_alarm has been triggered',
42
$p->add_arg(spec => 'hostname|host|H=s',
43
help => "Specify the host to connect to",
46
$p->add_arg(spec => 'port=i',
47
help => "Specify the port to connect to (default: %s)",
50
$p->add_arg(spec => 'node|n=s',
51
help => "Specify the node name (default is hostname)"
53
$p->add_arg(spec => 'username|user|u=s',
54
help => "Username (default: %s)",
57
$p->add_arg(spec => 'password|p=s',
58
help => "Password (default: %s)",
62
$p->add_arg(spec => 'vhost=s',
63
help => "Specify the vhost to test (default: %s)",
67
$p->add_arg(spec => 'ssl|ssl!',
68
help => "Use SSL (default: false)",
72
$p->add_arg(spec => 'proxy|proxy!',
73
help => "Use environment proxy (default: true)",
77
# Parse arguments and process standard ones (e.g. usage, help, version)
81
# perform sanity checking on command line options
84
##############################################################################
87
my $hostname=$p->opts->hostname;
88
my $port=$p->opts->port;
89
my $vhost=uri_escape($p->opts->vhost);
91
my $nodename = $p->opts->node;
94
$hostname =~ /^([a-zA-Z0-9-]*)/;
98
my $url = sprintf("http%s://%s:%d/api/nodes/rabbit\@%s", ($p->opts->ssl ? "s" : ""), $hostname, $port, $nodename);
100
my $ua = LWP::UserAgent->new(env_proxy => $p->opts->proxy);
101
$ua->agent($PROGNAME.' ');
102
$ua->timeout($p->opts->timeout);
103
# Different security domains in 2.5 and 2.6
104
$ua->credentials("$hostname:$port",
105
"RabbitMQ Management", $p->opts->username, $p->opts->password);
106
$ua->credentials("$hostname:$port",
107
"Management: Web UI", $p->opts->username, $p->opts->password);
108
my $req = HTTP::Request->new(GET => $url);
109
my $res = $ua->request($req);
111
if (!$res->is_success) {
112
# Deal with standard error conditions - make the messages more sensible
113
if ($res->code == 400) {
114
my $bodyref = decode_json $res->content;
115
$p->nagios_exit(CRITICAL, $bodyref->{'reason'});
117
$res->code == 404 and $p->nagios_die("Not found");
118
$res->code == 401 and $p->nagios_die("Access refused");
119
if ($res->code < 200 or $res->code > 400 ) {
120
$p->nagios_exit(CRITICAL, "Received ".$res->status_line);
124
my $bodyref = decode_json $res->content;
125
my @checks = ("mem_alarm", "disk_free_alarm");
127
for my $check (@checks) {
128
if ($bodyref->{$check} eq 0) {
129
$p->add_message(OK, "$check");
131
$p->add_message(CRITICAL, "$check");
135
my($code, $message) = $p->check_messages(join_all=>', ');
137
return_code => $code,
143
check_rabbitmq_watermark - Nagios plugin using RabbitMQ management API to check if the mem_alarm or disk_free_alarm has been triggered
147
check_rabbitmq_watermark [options] -H hostname
151
Use the management interface of RabbitMQ to check if the mem_alarm or disk_free_alarm has been triggered.
153
It uses Nagios::Plugin and accepts all standard Nagios options.
169
Set a timeout for the check in seconds
171
=item -H | --hostname | --host
173
The host to connect to
177
The port to connect to (default: 55672)
181
Use SSL when connecting (default: false)
185
The vhost to create the test queue within (default: /)
189
The node name (default is hostname)
191
=item --username | --user
193
The user to connect as (default: guest)
197
The password for the user (default: guest)
203
The defaults all work with a standard fresh install of RabbitMQ, and all that
204
is needed is to specify the host to connect to:
206
check_rabbitmq_watermark -H rabbit.example.com
208
This returns a standard Nagios result:
210
RABBITMQ_ALIVENESS OK - vhost: /
212
You can choose a different vhost to use for the check also:
214
check_rabbitmq_watermark -H rabbit.example.com --vhost /foo
218
The check tries to provide useful error messages on the status line for
219
standard error conditions.
221
Otherwise it returns the HTTP Error message returned by the management
226
Returns zero if check is OK otherwise returns standard Nagios exit codes to
227
signify WARNING, UNKNOWN or CRITICAL state.
231
See Nagios::Plugin(3)
233
The RabbitMQ management plugin is described at
234
http://www.rabbitmq.com/management.html
238
This file is part of nagios-plugins-rabbitmq.
240
Copyright 2010, Platform 14.
242
Licensed under the Apache License, Version 2.0 (the "License");
243
you may not use this file except in compliance with the License.
244
You may obtain a copy of the License at
246
http://www.apache.org/licenses/LICENSE-2.0
248
Unless required by applicable law or agreed to in writing, software
249
distributed under the License is distributed on an "AS IS" BASIS,
250
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
251
See the License for the specific language governing permissions and
252
limitations under the License.
256
James Casey <jamesc.000@gmail.com>