3
### check_rabbitmq_partition
5
# Use the management API to check if partitions error conditions exist.
7
# baseed on check_rabbitmq_watermark.pl,
8
# Originally by Nathan Vonnahme, n8v at users dot sourceforge
9
# dot net, July 19 2006
11
##############################################################################
21
use vars qw($VERSION $PROGNAME $verbose $timeout);
24
# get the base name of this script for use in the examples
26
$PROGNAME = basename($0);
29
##############################################################################
30
# define and get the command line options.
31
# see the command line option guidelines at
32
# http://nagiosplug.sourceforge.net/developer-guidelines.html#PLUGOPTIONS
35
# Instantiate Nagios::Plugin object (the 'usage' parameter is mandatory)
36
my $p = Nagios::Plugin->new(
37
usage => "Usage: %s [options] -H hostname",
40
blurb => 'This plugin uses the RabbitMQ management API to check if the mem_alarm has been triggered',
43
$p->add_arg(spec => 'hostname|host|H=s',
44
help => "Specify the host to connect to",
47
$p->add_arg(spec => 'port=i',
48
help => "Specify the port to connect to (default: %s)",
51
$p->add_arg(spec => 'node|n=s',
52
help => "Specify the node name (default is hostname)"
54
$p->add_arg(spec => 'username|user|u=s',
55
help => "Username (default: %s)",
58
$p->add_arg(spec => 'password|p=s',
59
help => "Password (default: %s)",
63
$p->add_arg(spec => 'ssl|ssl!',
64
help => "Use SSL (default: false)",
68
$p->add_arg(spec => 'proxy|proxy!',
69
help => "Use environment proxy (default: true)",
73
# Parse arguments and process standard ones (e.g. usage, help, version)
77
# perform sanity checking on command line options
80
##############################################################################
83
my $hostname=$p->opts->hostname;
84
my $port=$p->opts->port;
86
my $nodename = $p->opts->node;
89
$hostname =~ /^([a-zA-Z0-9-]*)/;
93
my $url = sprintf("http%s://%s:%d/api/nodes/rabbit\@%s", ($p->opts->ssl ? "s" : ""), $hostname, $port, $nodename);
95
my $ua = LWP::UserAgent->new(env_proxy => $p->opts->proxy);
96
$ua->agent($PROGNAME.' ');
97
$ua->timeout($p->opts->timeout);
98
# Different security domains in 2.5 and 2.6
99
$ua->credentials("$hostname:$port",
100
"RabbitMQ Management", $p->opts->username, $p->opts->password);
101
$ua->credentials("$hostname:$port",
102
"Management: Web UI", $p->opts->username, $p->opts->password);
103
my $req = HTTP::Request->new(GET => $url);
104
my $res = $ua->request($req);
106
if (!$res->is_success) {
107
# Deal with standard error conditions - make the messages more sensible
108
if ($res->code == 400) {
109
my $bodyref = decode_json $res->content;
110
$p->nagios_exit(CRITICAL, $bodyref->{'reason'});
112
$res->code == 404 and $p->nagios_die("Not found");
113
$res->code == 401 and $p->nagios_die("Access refused");
114
if ($res->code < 200 or $res->code > 400 ) {
115
$p->nagios_exit(CRITICAL, "Received ".$res->status_line);
118
my $bodyref = decode_json $res->content;
120
my $partitions=$bodyref->{'partitions'};
121
ref($partitions) eq "ARRAY" or $p->nagios_exit(CRITICAL, $res->content);
122
scalar(@$partitions)==0 or $p->nagios_exit(CRITICAL, "Partitions detected: @$partitions");
124
my($code, $message) = (OK, "No Partitions");
126
return_code => $code,
132
check_rabbitmq_partition - Nagios plugin using RabbitMQ management API to check if a cluster partition has occured
136
check_rabbitmq_partition [options] -H hostname
140
Use the management interface of RabbitMQ to check if a cluster partition has occured.
142
It uses Nagios::Plugin and accepts all standard Nagios options.
158
Set a timeout for the check in seconds
160
=item -H | --hostname | --host
162
The host to connect to
166
The port to connect to (default: 55672)
170
Use SSL when connecting (default: false)
174
The node name (default is hostname)
176
=item --username | --user
178
The user to connect as (default: guest)
182
The password for the user (default: guest)
188
The defaults all work with a standard fresh install of RabbitMQ, and all that
189
is needed is to specify the host to connect to:
191
check_rabbitmq_node -H rabbit.example.com
193
This returns a standard Nagios result:
195
RABBITMQ_NODE OK - No Partitions
199
The check tries to provide useful error messages on the status line for
200
standard error conditions.
202
Otherwise it returns the HTTP Error message returned by the management
207
Returns zero if check is OK otherwise returns standard Nagios exit codes to
208
signify WARNING, UNKNOWN or CRITICAL state.
212
See Nagios::Plugin(3)
214
The RabbitMQ management plugin is described at
215
http://www.rabbitmq.com/management.html
219
This file is part of nagios-plugins-rabbitmq.
221
Copyright 2010, Platform 14.
223
Licensed under the Apache License, Version 2.0 (the "License");
224
you may not use this file except in compliance with the License.
225
You may obtain a copy of the License at
227
http://www.apache.org/licenses/LICENSE-2.0
229
Unless required by applicable law or agreed to in writing, software
230
distributed under the License is distributed on an "AS IS" BASIS,
231
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
232
See the License for the specific language governing permissions and
233
limitations under the License.
237
James Casey <jamesc.000@gmail.com>