Debian Codegraph @

src/apps/mq/ibmmq/mqi/mode/channels.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::mqi::mode::channels;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'status: %s [message channel agent: %s]',
35 $self->{result_values}->{channel_status},
36 $self->{result_values}->{mca_status}
37 );
38 }
39
40 sub custom_traffic_in_perfdata {
41 my ($self) = @_;
42
43 $self->{output}->perfdata_add(
44 nlabel => $self->{nlabel}, unit => 'b/s',
45 instances => [$self->{result_values}->{qmgr_name}, $self->{result_values}->{channel_name}],
46 value => $self->{result_values}->{traffic_in},
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 custom_traffic_out_perfdata {
54 my ($self) = @_;
55
56 $self->{output}->perfdata_add(
57 nlabel => $self->{nlabel}, unit => 'b/s',
58 instances => [$self->{result_values}->{qmgr_name}, $self->{result_values}->{channel_name}],
59 value => $self->{result_values}->{traffic_out},
60 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
61 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
62 min => 0
63 );
64 }
65
66 sub prefix_channel_output {
67 my ($self, %options) = @_;
68
69 return "Channel '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{channel_name} . "' ";
70 }
71
72 sub set_counters {
73 my ($self, %options) = @_;
74
75 $self->{maps_counters_type} = [
76 { name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } },
77 ];
78
79 $self->{maps_counters}->{channel} = [
80 { label => 'status', threshold => 0, set => {
81 key_values => [
82 { name => 'qmgr_name' }, { name => 'channel_name' },
83 { name => 'channel_status' }, { name => 'mca_status' }
84 ],
85 closure_custom_calc => \&catalog_status_calc,
86 closure_custom_output => $self->can('custom_status_output'),
87 closure_custom_perfdata => sub { return 0; },
88 closure_custom_threshold_check => \&catalog_status_threshold
89 }
90 },
91 { label => 'traffic-in', nlabel => 'channel.traffic.in.bitspersecond', set => {
92 key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ],
93 output_template => 'traffic in: %s %s/s',
94 output_change_bytes => 2,
95 closure_custom_perfdata => $self->can('custom_traffic_in_perfdata')
96 }
97 },
98 { label => 'traffic-out', nlabel => 'channel.traffic.out.bitspersecond', set => {
99 key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ],
100 output_template => 'traffic out: %s %s/s',
101 output_change_bytes => 2,
102 closure_custom_perfdata => $self->can('custom_traffic_out_perfdata')
103 }
104 }
105 ];
106 }
107
108 sub new {
109 my ($class, %options) = @_;
110 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
111 bless $self, $class;
112
113 $options{options}->add_options(arguments => {
114 'filter-name:s' => { name => 'filter_name' },
115 'filter-type:s' => { name => 'filter_type' },
116 'unknown-status:s' => { name => 'unknown_status', default => '' },
117 'warning-status:s' => { name => 'warning_status', default => '' },
118 'critical-status:s' => { name => 'critical_status', default => '%{channel_status} !~ /running|idle/i' }
119 });
120
121 return $self;
122 }
123
124 sub check_options {
125 my ($self, %options) = @_;
126 $self->SUPER::check_options(%options);
127
128 $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
129 }
130
131 sub manage_selection {
132 my ($self, %options) = @_;
133
134 my $result = $options{custom}->execute_command(
135 command => 'InquireChannelStatus',
136 attrs => { }
137 );
138 my $names = $options{custom}->execute_command(
139 command => 'InquireChannel',
140 attrs => { }
141 );
142
143 $self->{channel} = {};
144 foreach (@$result) {
145 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
146 && $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/);
147 next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne ''
148 && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/);
149
150 $self->{channel}->{$_->{ChannelName}} = {
151 qmgr_name => $options{custom}->get_qmgr_name(),
152 channel_name => $_->{ChannelName},
153 channel_status => lc($_->{ChannelStatus}),
154 channel_type => $_->{ChannelType},
155 mca_status => lc($_->{MCAStatus}),
156 traffic_in => $_->{BytesReceived} * 8,
157 traffic_out => $_->{BytesSent} * 8
158 };
159 }
160
161 foreach (@$names) {
162 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
163 && $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/);
164 next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne ''
165 && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/i);
166
167 if (!defined($self->{channel}->{$_->{ChannelName}})) {
168 $self->{channel}->{$_->{ChannelName}} = {
169 qmgr_name => $options{custom}->get_qmgr_name(),
170 channel_name => $_->{ChannelName},
171 channel_status => 'idle',
172 channel_type => $_->{ChannelType},
173 mca_status => '-',
174 };
175 }
176 }
177
178 $self->{cache_name} = 'ibmmq_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
179 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
180 }
181
182 1;
183
184 __END__
185
186 =head1 MODE
187
188 Check channels.
189
190 =over 8
191
192 =item B<--filter-name>
193
194 Filter channel name (can use regexp).
195
196 =item B<--filter-type>
197
198 Filter channel type (can use regexp, insensitive search).
199
200 Here is the IBM - Perl mapping about Channel types:
201
202 SDR - Sender
203 SVR - Server
204 RCVR - Receiver
205 RQSTR - Requester
206 CLNTCONN - Clntconn
207 SVRCONN - Svrconn
208 CLUSSDR - ClusterSender
209 CLUSRCVR - ClusterReceiver
210 MQTT - Telemetry
211
212 =item B<--unknown-status>
213
214 Define the conditions to match for the status to be UNKNOWN (default: '').
215 You can use the following variables: %{channel_status}, %{mca_status}
216
217 =item B<--warning-status>
218
219 Define the conditions to match for the status to be WARNING (default: '').
220 You can use the following variables: %{channel_status}, %{mca_status}
221
222 =item B<--critical-status>
223
224 Define the conditions to match for the status to be CRITICAL (default: '%{channel_status} !~ /running|idle/i').
225 You can use the following variables: %{channel_status}, %{mca_status}
226
227 =item B<--warning-*> B<--critical-*>
228
229 Thresholds.
230 Can be: 'traffic-in', 'traffic-out'.
231
232 =back
233
234 =cut