Debian Codegraph @

src/apps/mq/ibmmq/mqi/mode/queues.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::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 custom_connections_perfdata {
39 my ($self, %options) = @_;
40
41 $self->{output}->perfdata_add(
42 nlabel => $self->{nlabel},
43 instances => [$self->{result_values}->{qmgr_name}, $self->{result_values}->{queue_name}],
44 value => $self->{result_values}->{open_input_count},
45 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
46 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
47 min => 0
48 );
49 }
50
51 sub custom_qdepth_perfdata {
52 my ($self, %options) = @_;
53
54 $self->{output}->perfdata_add(
55 nlabel => $self->{nlabel},
56 instances => [$self->{result_values}->{qmgr_name}, $self->{result_values}->{queue_name}],
57 value => $self->{result_values}->{current_qdepth},
58 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
59 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
60 min => 0
61 );
62 }
63
64 sub custom_oldest_perfdata {
65 my ($self, %options) = @_;
66
67 $self->{output}->perfdata_add(
68 nlabel => $self->{nlabel},
69 instances => [$self->{result_values}->{qmgr_name}, $self->{result_values}->{queue_name}],
70 value => $self->{result_values}->{oldest_msg_age},
71 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
72 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
73 min => 0
74 );
75 }
76
77 sub prefix_queue_output {
78 my ($self, %options) = @_;
79
80 return "Queue '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{queue_name} . "' ";
81 }
82
83 sub set_counters {
84 my ($self, %options) = @_;
85
86 $self->{maps_counters_type} = [
87 { name => 'queue', type => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', skipped_code => { -10 => 1 } },
88 ];
89
90 $self->{maps_counters}->{queue} = [
91 { label => 'connections-input', nlabel => 'queue.connections.input.count', set => {
92 key_values => [ { name => 'open_input_count' }, { name => 'qmgr_name' }, { name => 'queue_name' } ],
93 output_template => 'current input connections: %s',
94 closure_custom_perfdata => $self->can('custom_connections_perfdata')
95 }
96 },
97 { label => 'messages-depth', nlabel => 'queue.messages.depth.count', set => {
98 key_values => [ { name => 'current_qdepth' }, { name => 'qmgr_name' }, { name => 'queue_name' } ],
99 output_template => 'current messages depth: %s',
100 closure_custom_perfdata => $self->can('custom_qdepth_perfdata')
101 }
102 },
103 { label => 'message-oldest', nlabel => 'queue.message.oldest.seconds', set => {
104 key_values => [ { name => 'oldest_msg_age' }, { name => 'qmgr_name' }, { name => 'queue_name' } ],
105 closure_custom_output => $self->can('custom_oldest_output'),
106 closure_custom_perfdata => $self->can('custom_oldest_perfdata')
107 }
108 }
109 ];
110 }
111
112 sub new {
113 my ($class, %options) = @_;
114 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
115 bless $self, $class;
116
117 $options{options}->add_options(arguments => {
118 'filter-name:s' => { name => 'filter_name' }
119 });
120 return $self;
121 }
122
123 sub manage_selection {
124 my ($self, %options) = @_;
125
126 my $result = $options{custom}->execute_command(
127 command => 'InquireQueueStatus',
128 attrs => { QStatusAttrs => ['QName', 'CurrentQDepth', 'OpenInputCount', 'OldestMsgAge'] }
129 );
130
131 $self->{queue} = {};
132 foreach (@$result) {
133 next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
134 && $_->{QName} !~ /$self->{option_results}->{filter_name}/);
135
136 $self->{queue}->{$_->{QName}} = {
137 qmgr_name => $options{custom}->get_qmgr_name(),
138 queue_name => $_->{QName},
139 open_input_count => $_->{OpenInputCount},
140 current_qdepth => $_->{CurrentQDepth},
141 oldest_msg_age => $_->{OldestMsgAge} # in seconds
142 };
143 }
144
145 if (scalar(keys %{$self->{queue}}) <= 0) {
146 $self->{output}->add_option_msg(short_msg => 'No queue found');
147 $self->{output}->option_exit();
148 }
149 }
150
151 1;
152
153 __END__
154
155 =head1 MODE
156
157 Check queues.
158
159 =over 8
160
161 =item B<--filter-name>
162
163 Filter queue name (can use regexp).
164
165 =item B<--warning-*> B<--critical-*>
166
167 Thresholds.
168 Can be: 'connections-input', 'messages-depth', 'message-oldest'.
169
170 =back
171
172 =cut