| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package apps::mq::ibmmq::restapi::mode::queues; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
|
| 29 |
sub custom_oldest_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'oldest message: %s', |
| 34 |
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{oldest_msg_age}) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub qmgr_long_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
return "checking queue manager '" . $options{instance_value}->{name} . "'"; |
| 42 |
} |
| 43 |
|
| 44 |
sub prefix_qmgr_output { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
return "queue manager '" . $options{instance_value}->{name} . "' "; |
| 48 |
} |
| 49 |
|
| 50 |
sub prefix_queue_output { |
| 51 |
my ($self, %options) = @_; |
| 52 |
|
| 53 |
return "queue '" . $options{instance_value}->{name} . "' "; |
| 54 |
} |
| 55 |
|
| 56 |
sub set_counters { |
| 57 |
my ($self, %options) = @_; |
| 58 |
|
| 59 |
$self->{maps_counters_type} = [ |
| 60 |
{ name => 'qmgr', type => 3, cb_prefix_output => 'prefix_qmgr_output', cb_long_output => 'qmgr_long_output', indent_long_output => ' ', message_multiple => 'All queue managers are ok', |
| 61 |
group => [ |
| 62 |
{ name => 'queues', display_long => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'queues are ok', type => 1, skipped_code => { -10 => 1 } } |
| 63 |
] |
| 64 |
} |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{queues} = [ |
| 68 |
{ label => 'connections-input', nlabel => 'queue.connections.input.count', set => { |
| 69 |
key_values => [ { name => 'open_input_count' } ], |
| 70 |
output_template => 'current input connections: %s', |
| 71 |
perfdatas => [ |
| 72 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 73 |
] |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'messages-depth', nlabel => 'queue.messages.depth.count', set => { |
| 77 |
key_values => [ { name => 'current_qdepth' }], |
| 78 |
output_template => 'current messages depth: %s', |
| 79 |
perfdatas => [ |
| 80 |
{ template => '%d', min => 0, label_extra_instance => 1 } |
| 81 |
] |
| 82 |
} |
| 83 |
}, |
| 84 |
{ label => 'message-oldest', nlabel => 'queue.message.oldest.seconds', set => { |
| 85 |
key_values => [ { name => 'oldest_msg_age' } ], |
| 86 |
closure_custom_output => $self->can('custom_oldest_output'), |
| 87 |
closure_custom_perfdata => $self->can('custom_oldest_perfdata') |
| 88 |
} |
| 89 |
} |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
sub new { |
| 94 |
my ($class, %options) = @_; |
| 95 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 96 |
bless $self, $class; |
| 97 |
|
| 98 |
$options{options}->add_options(arguments => { |
| 99 |
'qmgr-name:s' => { name => 'qmgr_name' }, |
| 100 |
'queue-name:s' => { name => 'queue_name' }, |
| 101 |
'filter-qmgr-name:s' => { name => 'filter_qmgr_name' }, |
| 102 |
'filter-queue-name:s' => { name => 'filter_queue_name' } |
| 103 |
}); |
| 104 |
|
| 105 |
return $self; |
| 106 |
} |
| 107 |
|
| 108 |
sub manage_selection { |
| 109 |
my ($self, %options) = @_; |
| 110 |
|
| 111 |
my @list_qmgr = (); |
| 112 |
if (defined($self->{option_results}->{qmgr_name}) && $self->{option_results}->{qmgr_name} ne '') { |
| 113 |
@list_qmgr = ($self->{option_results}->{qmgr_name}); |
| 114 |
} else { |
| 115 |
my $names = $options{custom}->request_api( |
| 116 |
endpoint => '/qmgr/' |
| 117 |
); |
| 118 |
foreach (@{$names->{qmgr}}) { |
| 119 |
push @list_qmgr, $_->{name}; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
my $found = 0; |
| 124 |
$self->{qmgr} = {}; |
| 125 |
foreach my $qmgr_name (@list_qmgr) { |
| 126 |
if (defined($self->{option_results}->{filter_qmgr_name}) && $self->{option_results}->{filter_qmgr_name} ne '' && |
| 127 |
$qmgr_name !~ /$self->{option_results}->{filter_qmgr_name}/) { |
| 128 |
$self->{output}->output_add(long_msg => "skipping '" . $qmgr_name . "': no matching filter.", debug => 1); |
| 129 |
next; |
| 130 |
} |
| 131 |
|
| 132 |
my $endpoint = '/qmgr/' . $qmgr_name . '/queue'; |
| 133 |
if (defined($self->{option_results}->{queue_name}) && $self->{option_results}->{queue_name} ne '') { |
| 134 |
$endpoint .= '/' . $self->{option_results}->{queue_name}; |
| 135 |
} |
| 136 |
|
| 137 |
my $queues = $options{custom}->request_api( |
| 138 |
endpoint => $endpoint, |
| 139 |
get_param => ['status=*'] |
| 140 |
); |
| 141 |
foreach my $queue (@{$queues->{queue}}) { |
| 142 |
if (defined($self->{option_results}->{filter_queue_name}) && $self->{option_results}->{filter_queue_name} ne '' && |
| 143 |
$queue->{name} !~ /$self->{option_results}->{filter_queue_name}/) { |
| 144 |
$self->{output}->output_add(long_msg => "skipping '" . $queue->{name} . "': no matching filter.", debug => 1); |
| 145 |
next; |
| 146 |
} |
| 147 |
|
| 148 |
unless (defined($self->{qmgr}->{$qmgr_name})) { |
| 149 |
$self->{qmgr}->{$qmgr_name} = { |
| 150 |
name => $qmgr_name, |
| 151 |
queues => {} |
| 152 |
}; |
| 153 |
} |
| 154 |
|
| 155 |
$self->{qmgr}->{$qmgr_name}->{queues}->{ $queue->{name} } = { |
| 156 |
name => $queue->{name}, |
| 157 |
open_input_count => $queue->{status}->{openInputCount}, |
| 158 |
current_qdepth => $queue->{status}->{currentDepth}, |
| 159 |
oldest_msg_age => $queue->{status}->{oldestMessageAge} |
| 160 |
}; |
| 161 |
$found = 1; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
unless ($found) { |
| 166 |
$self->{output}->add_option_msg(short_msg => 'No queue found'); |
| 167 |
$self->{output}->option_exit(); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
1; |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 MODE |
| 176 |
|
| 177 |
Check queues. |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item B<--qmgr-name> |
| 182 |
|
| 183 |
Check exact queue manager. |
| 184 |
|
| 185 |
=item B<--queue-name> |
| 186 |
|
| 187 |
Check exact queue. |
| 188 |
|
| 189 |
=item B<--filter-qmgr-name> |
| 190 |
|
| 191 |
Filter queue managers by name (can be a regexp). |
| 192 |
|
| 193 |
=item B<--filter-queue-name> |
| 194 |
|
| 195 |
Filter queues by name (can be a regexp). |
| 196 |
|
| 197 |
=item B<--warning-*> B<--critical-*> |
| 198 |
|
| 199 |
Thresholds. |
| 200 |
Can be: 'connections-input', 'messages-depth', 'message-oldest'. |
| 201 |
|
| 202 |
=back |
| 203 |
|
| 204 |
=cut |