Debian Codegraph @

src/apps/mq/ibmmq/restapi/mode/queuemanagers.pm

raw
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::queuemanagers;
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_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s [channel initiator: %s]',
34 $self->{result_values}->{mgr_status},
35 $self->{result_values}->{channel_initiator_status}
36 );
37 }
38
39 sub prefix_qmgr_output {
40 my ($self, %options) = @_;
41
42 return "Queue manager '" . $options{instance_value}->{display} . "' ";
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'qmgr', type => 1, cb_prefix_output => 'prefix_qmgr_output', skipped_code => { -10 => 1 } }
50 ];
51
52 $self->{maps_counters}->{qmgr} = [
53 { label => 'status', type => 2, critical_default => '%{mgr_status} !~ /running/i', set => {
54 key_values => [
55 { name => 'mgr_status' }, { name => 'channel_initiator_status' },
56 { name => 'display' }
57 ],
58 closure_custom_output => $self->can('custom_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold_ng
61 }
62 },
63 { label => 'connections', nlabel => 'queuemanager.connections.count', set => {
64 key_values => [ { name => 'connection_count' } ],
65 output_template => 'current number of connections: %s',
66 perfdatas => [
67 { template => '%d', min => 0, label_extra_instance => 1 }
68 ]
69 }
70 }
71 ];
72 }
73
74 sub new {
75 my ($class, %options) = @_;
76 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
77 bless $self, $class;
78
79 $options{options}->add_options(arguments => {
80 'qmgr-name:s' => { name => 'qmgr_name' },
81 'filter-qmgr-name:s' => { name => 'filter_qmgr_name' }
82 });
83
84 return $self;
85 }
86
87 sub manage_selection {
88 my ($self, %options) = @_;
89
90 my @lists = ();
91 if (defined($self->{option_results}->{qmgr_name}) && $self->{option_results}->{qmgr_name} ne '') {
92 @lists = ($self->{option_results}->{qmgr_name});
93 } else {
94 my $names = $options{custom}->request_api(
95 endpoint => '/qmgr/'
96 );
97 foreach (@{$names->{qmgr}}) {
98 push @lists, $_->{name};
99 }
100 }
101
102 $self->{qmgr} = {};
103 foreach my $name (@lists) {
104 if (defined($self->{option_results}->{filter_qmgr_name}) && $self->{option_results}->{filter_qmgr_name} ne '' &&
105 $name !~ /$self->{option_results}->{filter_qmgr_name}/) {
106 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
107 next;
108 }
109
110 my $infos = $options{custom}->request_api(
111 endpoint => '/qmgr/' . $name,
112 get_param => ['status=*']
113 );
114
115 $self->{qmgr}->{$name} = {
116 display => $name,
117 channel_initiator_status => lc($infos->{qmgr}->[0]->{status}->{channelInitiatorState}),
118 mgr_status => lc($infos->{qmgr}->[0]->{state}),
119 connection_count => $infos->{qmgr}->[0]->{status}->{connectionCount}
120 };
121 }
122
123 if (scalar(keys %{$self->{qmgr}}) <= 0) {
124 $self->{output}->add_option_msg(short_msg => 'No queue managers found');
125 $self->{output}->option_exit();
126 }
127 }
128
129 1;
130
131 __END__
132
133 =head1 MODE
134
135 Check queue managers.
136
137 =over 8
138
139 =item B<--qmgr-name>
140
141 Check exact queue manager (no API listing call).
142
143 =item B<--filter-qmgr-name>
144
145 Filter queue managers by name (can be a regexp).
146
147 =item B<--unknown-status>
148
149 Define the conditions to match for the status to be UNKNOWN.
150 You can use the following variables: %{mgr_status}, %{channel_initiator_status}
151
152 =item B<--warning-status>
153
154 Define the conditions to match for the status to be WARNING.
155 You can use the following variables: %{mgr_status}, %{channel_initiator_status}
156
157 =item B<--critical-status>
158
159 Define the conditions to match for the status to be CRITICAL (default: '%{mgr_status} !~ /running/i').
160 You can use the following variables: %{mgr_status}, %{channel_initiator_status}
161
162 =item B<--warning-*> B<--critical-*>
163
164 Thresholds.
165 Can be: 'connections'.
166
167 =back
168
169 =cut