diff --git a/apps/mq/ibmmq/mqi/custom/api.pm b/apps/mq/ibmmq/mqi/custom/api.pm index 4b0038319..d305b06ef 100644 --- a/apps/mq/ibmmq/mqi/custom/api.pm +++ b/apps/mq/ibmmq/mqi/custom/api.pm @@ -178,6 +178,8 @@ sub execute_command { @results = $self->{mq_command}->InquireChannelStatus(%{$options{attrs}}); } elsif ($options{command} eq 'InquireQueueStatus') { @results = $self->{mq_command}->InquireQueueStatus(%{$options{attrs}}); + } elsif ($options{command} eq 'InquireChannelNames') { + @results = $self->{mq_command}->InquireChannelNames(%{$options{attrs}}); } if (!@results) { diff --git a/apps/mq/ibmmq/mqi/mode/channels.pm b/apps/mq/ibmmq/mqi/mode/channels.pm index 8c0bf7a9e..3c063b287 100644 --- a/apps/mq/ibmmq/mqi/mode/channels.pm +++ b/apps/mq/ibmmq/mqi/mode/channels.pm @@ -111,6 +111,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '%{channel_status} !~ /running/i' }, @@ -132,9 +133,16 @@ sub manage_selection { command => 'InquireChannelStatus', attrs => { } ); + my $names = $options{custom}->execute_command( + command => 'InquireChannelNames', + attrs => { } + ); $self->{channel} = {}; foreach (@$result) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/); + $self->{channel}->{$_->{ChannelName}} = { qmgr_name => $options{custom}->get_qmgr_name(), channel_name => $_->{ChannelName}, @@ -145,6 +153,19 @@ sub manage_selection { }; } + foreach (@$names) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_ !~ /$self->{option_results}->{filter_name}/); + if (!defined($self->{channel}->{$_})) { + $self->{channel}->{$_->{ChannelName}} = { + qmgr_name => $options{custom}->get_qmgr_name(), + channel_name => $_, + channel_status => 'idle', + mca_status => '-', + }; + } + } + $self->{cache_name} = "ibmmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } @@ -159,6 +180,10 @@ Check channels. =over 8 +=item B<--filter-name> + +Filter channel name (Can use regexp). + =item B<--unknown-status> Set unknown threshold for status (Default: ''). diff --git a/apps/mq/ibmmq/mqi/mode/listchannels.pm b/apps/mq/ibmmq/mqi/mode/listchannels.pm new file mode 100644 index 000000000..9ab046c25 --- /dev/null +++ b/apps/mq/ibmmq/mqi/mode/listchannels.pm @@ -0,0 +1,107 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::mq::ibmmq::mqi::mode::listchannels; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command( + command => 'InquireChannelNames', + attrs => {} + ); + + $self->{channel} = {}; + foreach (@$result) { + $self->{channel}->{$_} = { + name => $_ + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{channel}}) { + $self->{output}->output_add(long_msg => + sprintf( + '[name = %s]', + $self->{channel}->{$_}->{name} + ) + ); + } + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List channels:' + ); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (values %{$self->{channel}}) { + $self->{output}->add_disco_entry(%$_); + } +} + +1; + +__END__ + +=head1 MODE + +List channels. + +=over 8 + +=back + +=cut diff --git a/apps/mq/ibmmq/mqi/plugin.pm b/apps/mq/ibmmq/mqi/plugin.pm index 78e750bbc..f9fe15aef 100644 --- a/apps/mq/ibmmq/mqi/plugin.pm +++ b/apps/mq/ibmmq/mqi/plugin.pm @@ -32,6 +32,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( 'channels' => 'apps::mq::ibmmq::mqi::mode::channels', + 'list-channels' => 'apps::mq::ibmmq::mqi::mode::listchannels', 'list-queues' => 'apps::mq::ibmmq::mqi::mode::listqueues', 'queues' => 'apps::mq::ibmmq::mqi::mode::queues', 'queue-manager' => 'apps::mq::ibmmq::mqi::mode::queuemanager'