This commit is contained in:
garnier-quentin 2019-06-14 13:31:54 +02:00
parent 7e77a33e47
commit 4d0a336c1d
9 changed files with 1204 additions and 0 deletions

View File

@ -0,0 +1,221 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::custom::api;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use URI::Encode;
use JSON::XS;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MODE OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 15672;
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.');
$self->{output}->option_exit();
}
return 0;
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{port};
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto};
$self->{option_results}->{timeout} = $self->{timeout};
if (defined($self->{username}) && $self->{username} ne '') {
$self->{option_results}->{credentials} = 1;
$self->{option_results}->{basic} = 1;
$self->{option_results}->{username} = $self->{username};
$self->{option_results}->{password} = $self->{password};
}
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->set_options(%{$self->{option_results}});
}
sub request {
my ($self, %options) = @_;
$self->settings();
$self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . $options{url_path} . "'", debug => 1);
$self->{output}->output_add(long_msg => "Parameters: '" . join(', ', @{$options{post_param}}) . "'", debug => 1) if (defined($options{post_param}));
my $content = $self->{http}->request(
%options,
unknown_status => '%{http_code} < 200 or %{http_code} >= 300',
critical_status => '',
);
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
return $decoded;
}
sub query {
my ($self, %options) = @_;
return $self->request(url_path => $options{url_path});
}
1;
__END__
=head1 NAME
RabbitMQ Rest API
=head1 CUSTOM MODE OPTIONS
RabbitMQ Rest API
=over 8
=item B<--hostname>
Remote hostname or IP address.
=item B<--port>
Port used (Default: 15672)
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--username>
Specify username for authentication
=item B<--password>
Specify password for authentication
=item B<--timeout>
Set timeout in seconds (Default: 10).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,103 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::listnodes;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/nodes/?columns=name');
$self->{node} = {};
foreach (@$result) {
$self->{node}->{$_->{name}} = {
name => $_->{name},
status => $_->{running} ? 'running' : 'notrunning',
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (sort keys %{$self->{node}}) {
$self->{output}->output_add(long_msg => sprintf(
"[name = %s][status = %s]",
$self->{node}->{$_}->{name}, $self->{node}->{$_}->{status})
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List nodes:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (values %{$self->{node}}) {
$self->{output}->add_disco_entry(%$_);
}
}
1;
__END__
=head1 MODE
List nodes.
=over 8
=back
=cut

View File

@ -0,0 +1,104 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::listqueues;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/queues/?columns=vhost,name,state');
$self->{queue} = {};
foreach (@$result) {
$self->{queue}->{$_->{vhost} . ':' . $_->{name}} = {
vhost => $_->{vhost},
name => $_->{name},
state => $_->{state},
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (sort keys %{$self->{queue}}) {
$self->{output}->output_add(long_msg => sprintf(
"[name = %s][vhost = %s][state = %s]",
$self->{queue}->{$_}->{name}, $self->{queue}->{$_}->{vhost}, $self->{queue}->{$_}->{state})
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List queues:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'vhost', 'state']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (values %{$self->{queue}}) {
$self->{output}->add_disco_entry(%$_);
}
}
1;
__END__
=head1 MODE
List queues.
=over 8
=back
=cut

View File

@ -0,0 +1,106 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::listvhosts;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use URI::Encode;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $uri = URI::Encode->new({encode_reserved => 1});
my $result = $options{custom}->query(url_path => '/api/vhosts/?columns=name');
$self->{vhost} = {};
foreach (@$result) {
my $result_alive = $options{custom}->query(url_path => '/api/aliveness-test/' . $uri->encode($_->{name}));
$self->{vhost}->{$_->{name}} = {
name => $_->{name},
status => $result_alive->{status}
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (sort keys %{$self->{vhost}}) {
$self->{output}->output_add(long_msg => sprintf(
"[name = %s][status = %s]",
$self->{vhost}->{$_}->{name}, $self->{vhost}->{$_}->{status})
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List vhosts:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (values %{$self->{vhost}}) {
$self->{output}->add_disco_entry(%$_);
}
}
1;
__END__
=head1 MODE
List vhosts.
=over 8
=back
=cut

View File

@ -0,0 +1,162 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::nodeusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = "status: '" . $self->{result_values}->{status} . "'";
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{node} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'read', nlabel => 'node.io.read.usage.bytespersecond', set => {
key_values => [ { name => 'io_read_bytes', diff => 1 }, { name => 'display' } ],
output_template => 'read i/o : %s %s/s',
per_second => 1, output_change_bytes => 1,
perfdatas => [
{ value => 'io_read_bytes_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write', nlabel => 'node.io.write.usage.bytespersecond', set => {
key_values => [ { name => 'io_write_bytes', diff => 1 }, { name => 'display' } ],
output_template => 'write i/o : %s %s/s',
per_second => 1, output_change_bytes => 1,
perfdatas => [
{ value => 'io_write_bytes_per_second', template => '%d',
unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_node_output {
my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "running"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/nodes/?columns=name,running,io_write_bytes,io_read_bytes');
$self->{node} = {};
foreach (@$result) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $_->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{node}->{$_->{name}} = {
display => $_->{name},
io_write_bytes => $_->{io_write_bytes},
io_read_bytes => $_->{io_read_bytes},
status => $_->{running} ? 'running' : 'notrunning',
};
}
if (scalar(keys %{$self->{node}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No node found');
$self->{output}->option_exit();
}
$self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check node usage.
=over 8
=item B<--filter-name>
Filter node name (Can use regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} ne "running"').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'read-iops', 'disk-write-iops'.
=back
=cut

View File

@ -0,0 +1,161 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::queueusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = "state: '" . $self->{result_values}->{state} . "'";
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'queue', type => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{queue} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'state' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'queue-msg', nlabel => 'queue.messages.count', set => {
key_values => [ { name => 'queue_messages' }, { name => 'display' } ],
output_template => 'current queue messages : %s',
perfdatas => [
{ label => 'queue_msg', value => 'queue_messages_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'queue-msg-ready', nlabel => 'queue.messages.ready.count', set => {
key_values => [ { name => 'queue_messages_ready' }, { name => 'display' } ],
output_template => 'current queue messages ready : %s',
perfdatas => [
{ label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_queue_output {
my ($self, %options) = @_;
return "Queue '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{state} ne "running"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/queues/?columns=vhost,name,state,messages,messages_ready');
$self->{queue} = {};
foreach (@$result) {
my $name = $_->{vhost} . ':' . $_->{name};
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $_->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{queue}->{$name} = {
display => $name,
queue_messages_ready => $_->{messages_ready},
queue_messages => $_->{messages},
state => $_->{state},
};
}
if (scalar(keys %{$self->{queue}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No queue found');
$self->{output}->option_exit();
}
$self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check queue usage.
=over 8
=item B<--filter-name>
Filter queue name (Can use regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{state}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{state} ne "running"').
Can used special variables like: %{state}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'read-iops', 'disk-write-iops'.
=back
=cut

View File

@ -0,0 +1,132 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::systemusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'queue-msg', nlabel => 'system.queue.messages.count', set => {
key_values => [ { name => 'queue_messages' } ],
output_template => 'current queue messages : %s',
perfdatas => [
{ label => 'queue_msg', value => 'queue_messages_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'queue-msg-ready', nlabel => 'system.queue.messages.ready.count', set => {
key_values => [ { name => 'queue_messages_ready' } ],
output_template => 'current queue messages ready : %s',
perfdatas => [
{ label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'db-event-queue', nlabel => 'system.db.event.queue.count', set => {
key_values => [ { name => 'db_event_queue' } ],
output_template => 'db event queue : %s',
perfdatas => [
{ label => 'db_event_queue', value => 'db_event_queue_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'disk-read-iops', nlabel => 'system.disk.read.usage.iops', set => {
key_values => [ { name => 'disk_reads', diff => 1 } ],
per_second => 1,
output_template => 'disk reads iops : %s',
perfdatas => [
{ label => 'disk_reads', value => 'disk_reads_per_second', template => '%d',
unit => 'iops', min => 0, },
],
}
},
{ label => 'disk-write-iops', nlabel => 'system.disk.write.usage.iops', set => {
key_values => [ { name => 'disk_writes', diff => 1 } ],
per_second => 1,
output_template => 'disk writes iops : %s',
perfdatas => [
{ label => 'disk_writes', value => 'disk_writes_per_second', template => '%d',
unit => 'iops', min => 0, },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/overview');
$self->{global} = {
disk_reads => $result->{message_stats}->{disk_reads},
disk_writes => $result->{message_stats}->{disk_writes},
queue_messages_ready => $result->{queue_totals}->{messages_ready},
queue_messages => $result->{queue_totals}->{messages},
db_event_queue => $result->{statistics_db_event_queue},
};
$self->{cache_name} = "rabbitmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check global system statistics
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'disk-read-iops', 'disk-write-iops',
'queue-msg-ready', 'queue-msg', 'db-event-queue'.
=back
=cut

View File

@ -0,0 +1,160 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::mode::vhostusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use URI::Encode;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status: ' . $self->{result_values}->{status};
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'vhost', type => 1, cb_prefix_output => 'prefix_vhost_output', message_multiple => 'All vhosts are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{vhost} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'queue-msg', nlabel => 'vhost.queue.messages.count', set => {
key_values => [ { name => 'queue_messages' }, { name => 'display' } ],
output_template => 'current queue messages : %s',
perfdatas => [
{ label => 'queue_msg', value => 'queue_messages_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'queue-msg-ready', nlabel => 'vhost.queue.messages.ready.count', set => {
key_values => [ { name => 'queue_messages_ready' }, { name => 'display' } ],
output_template => 'current queue messages ready : %s',
perfdatas => [
{ label => 'queue_msg_ready', value => 'queue_messages_ready_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_vhost_output {
my ($self, %options) = @_;
return "Vhost '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "ok"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->query(url_path => '/api/vhosts');
my $uri = URI::Encode->new({encode_reserved => 1});
$self->{vhost} = {};
foreach (@$result) {
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $_->{name} !~ /$self->{option_results}->{filter_name}/);
my $result_alive = $options{custom}->query(url_path => '/api/aliveness-test/' . $uri->encode($_->{name}));
$self->{vhost}->{$_->{name}} = {
display => $_->{name},
queue_messages_ready => $_->{messages_ready},
queue_messages => $_->{messages},
status => $result_alive->{status}
};
}
if (scalar(keys %{$self->{vhost}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No vhost found');
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check vhost usage.
=over 8
=item B<--filter-name>
Filter vhost name (Can use regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} ne "ok"').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'queue-msg-ready', 'queue-msg'.
=back
=cut

View File

@ -0,0 +1,55 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::mq::rabbitmq::restapi::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'list-nodes' => 'apps::mq::rabbitmq::restapi::mode::listnodes',
'list-queues' => 'apps::mq::rabbitmq::restapi::mode::listqueues',
'list-vhosts' => 'apps::mq::rabbitmq::restapi::mode::listvhosts',
'node-usage' => 'apps::mq::rabbitmq::restapi::mode::nodeusage',
'queue-usage' => 'apps::mq::rabbitmq::restapi::mode::queueusage',
'system-usage' => 'apps::mq::rabbitmq::restapi::mode::systemusage',
'vhost-usage' => 'apps::mq::rabbitmq::restapi::mode::vhostusage',
);
$self->{custom_modes}{api} = 'apps::mq::rabbitmq::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check RabbitMQ with Rest API.
=cut