| 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::mqi::mode::queuemanager; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'status: %s [command server: %s] [channel initiator: %s]', |
| 34 |
$self->{result_values}->{mgr_status}, |
| 35 |
$self->{result_values}->{command_server_status}, |
| 36 |
$self->{result_values}->{channel_initiator_status} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub custom_connections_perfdata { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
$self->{output}->perfdata_add( |
| 44 |
nlabel => $self->{nlabel}, |
| 45 |
instances => $self->{result_values}->{display}, |
| 46 |
value => $self->{result_values}->{connection_count}, |
| 47 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 48 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 49 |
min => 0 |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
sub prefix_qmgr_output { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
return "Queue manager '" . $options{instance_value}->{display} . "' "; |
| 57 |
} |
| 58 |
|
| 59 |
sub set_counters { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{maps_counters_type} = [ |
| 63 |
{ name => 'qmgr', type => 0, cb_prefix_output => 'prefix_qmgr_output', skipped_code => { -10 => 1 } } |
| 64 |
]; |
| 65 |
|
| 66 |
$self->{maps_counters}->{qmgr} = [ |
| 67 |
{ label => 'status', threshold => 0, set => { |
| 68 |
key_values => [ |
| 69 |
{ name => 'mgr_status' }, { name => 'channel_initiator_status' }, |
| 70 |
{ name => 'command_server_status' }, { name => 'display' } |
| 71 |
], |
| 72 |
closure_custom_calc => \&catalog_status_calc, |
| 73 |
closure_custom_output => $self->can('custom_status_output'), |
| 74 |
closure_custom_perfdata => sub { return 0; }, |
| 75 |
closure_custom_threshold_check => \&catalog_status_threshold |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'connections', nlabel => 'queuemanager.connections.count', set => { |
| 79 |
key_values => [ { name => 'connection_count' }, { name => 'display' } ], |
| 80 |
output_template => 'current number of connections: %s', |
| 81 |
closure_custom_perfdata => $self->can('custom_connections_perfdata') |
| 82 |
} |
| 83 |
} |
| 84 |
]; |
| 85 |
} |
| 86 |
|
| 87 |
sub new { |
| 88 |
my ($class, %options) = @_; |
| 89 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 90 |
bless $self, $class; |
| 91 |
|
| 92 |
$options{options}->add_options(arguments => { |
| 93 |
'unknown-status:s' => { name => 'unknown_status', default => '' }, |
| 94 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 95 |
'critical-status:s' => { name => 'critical_status', default => '%{mgr_status} !~ /running/i' }, |
| 96 |
}); |
| 97 |
|
| 98 |
return $self; |
| 99 |
} |
| 100 |
|
| 101 |
sub check_options { |
| 102 |
my ($self, %options) = @_; |
| 103 |
$self->SUPER::check_options(%options); |
| 104 |
|
| 105 |
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); |
| 106 |
} |
| 107 |
|
| 108 |
sub manage_selection { |
| 109 |
my ($self, %options) = @_; |
| 110 |
|
| 111 |
my $result = $options{custom}->execute_command( |
| 112 |
command => 'InquireQueueManagerStatus', |
| 113 |
attrs => { } |
| 114 |
); |
| 115 |
|
| 116 |
$self->{qmgr} = { |
| 117 |
display => $options{custom}->get_qmgr_name(), |
| 118 |
channel_initiator_status => lc($result->[0]->{ChannelInitiatorStatus}), |
| 119 |
mgr_status => lc($result->[0]->{QMgrStatus}), |
| 120 |
command_server_status => lc($result->[0]->{CommandServerStatus}), |
| 121 |
connection_count => $result->[0]->{ConnectionCount} |
| 122 |
}; |
| 123 |
} |
| 124 |
|
| 125 |
1; |
| 126 |
|
| 127 |
__END__ |
| 128 |
|
| 129 |
=head1 MODE |
| 130 |
|
| 131 |
Check queue manager. |
| 132 |
|
| 133 |
=over 8 |
| 134 |
|
| 135 |
=item B<--unknown-status> |
| 136 |
|
| 137 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 138 |
You can use the following variables: %{mgr_status}, %{channel_initiator_status}, %{command_server_status} |
| 139 |
|
| 140 |
=item B<--warning-status> |
| 141 |
|
| 142 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 143 |
You can use the following variables: %{mgr_status}, %{channel_initiator_status}, %{command_server_status} |
| 144 |
|
| 145 |
=item B<--critical-status> |
| 146 |
|
| 147 |
Define the conditions to match for the status to be CRITICAL (default: '%{mgr_status} !~ /running/i'). |
| 148 |
You can use the following variables: %{mgr_status}, %{channel_initiator_status}, %{command_server_status} |
| 149 |
|
| 150 |
=item B<--warning-*> B<--critical-*> |
| 151 |
|
| 152 |
Thresholds. |
| 153 |
Can be: 'connections'. |
| 154 |
|
| 155 |
=back |
| 156 |
|
| 157 |
=cut |