From 87d0d06985b3811637771c02ef59d41cc44e8c74 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 13 Mar 2020 11:19:57 +0100 Subject: [PATCH] (enh)plugin - add type filtering capability --- apps/mq/ibmmq/mqi/custom/api.pm | 458 ++++++++++++------------- apps/mq/ibmmq/mqi/mode/channels.pm | 426 ++++++++++++----------- apps/mq/ibmmq/mqi/mode/listchannels.pm | 216 ++++++------ 3 files changed, 555 insertions(+), 545 deletions(-) diff --git a/apps/mq/ibmmq/mqi/custom/api.pm b/apps/mq/ibmmq/mqi/custom/api.pm index d305b06ef..12ae46fbc 100644 --- a/apps/mq/ibmmq/mqi/custom/api.pm +++ b/apps/mq/ibmmq/mqi/custom/api.pm @@ -1,229 +1,229 @@ -# -# 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::custom::api; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::misc; - -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port' }, - 'channel:s' => { name => 'channel' }, - 'timeout:s' => { name => 'timeout' } - }); - } - $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MQI OPTIONS', once => 1); - - $self->{output} = $options{output}; - $self->{mode} = $options{mode}; - - centreon::plugins::misc::mymodule_load( - output => $self->{output}, - module => 'MQSeries::QueueManager', - error_msg => "Cannot load module 'MQSeries::QueueManager'." - ); - centreon::plugins::misc::mymodule_load( - output => $self->{output}, - module => 'MQSeries::Command', - error_msg => "Cannot load module 'MQSeries::Command'." - ); - - $self->{connected} = 0; - return $self; -} - -sub set_options { - my ($self, %options) = @_; - - $self->{option_results} = $options{option_results}; -} - -sub set_defaults { - my ($self, %options) = @_; - - foreach (keys %{$options{default}}) { - if ($_ eq $self->{mode}) { - for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { - foreach my $opt (keys %{$options{default}->{$_}[$i]}) { - if (!defined($self->{option_results}->{$opt}[$i])) { - $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; - } - } - } - } - } -} - -sub check_options { - my ($self, %options) = @_; - - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; - $self->{channel} = (defined($self->{option_results}->{channel})) ? $self->{option_results}->{channel} : ''; - $self->{port} = (defined($self->{option_results}->{port})) && $self->{option_results}->{port} =~ /(\d+)/ ? $1 : 1414; - $self->{timeout} = (defined($self->{option_results}->{timeout})) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 30; - - if ($self->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); - $self->{output}->option_exit(); - } - if ($self->{channel} eq '') { - $self->{output}->add_option_msg(short_msg => 'Need to specify --channel option.'); - $self->{output}->option_exit(); - } - - return 0; -} - -sub get_hostname { - my ($self, %options) = @_; - - return $self->{hostname}; -} - -sub get_port { - my ($self, %options) = @_; - - return $self->{port}; -} - -sub get_qmgr_name { - my ($self, %options) = @_; - - return $self->{qmgr_name}; -} - -sub my_logger {} - -sub connect { - my ($self, %options) = @_; - - return if ($self->{connected} == 1); - - my $reason; - $self->{qmgr} = MQSeries::QueueManager->new( - QueueManager => '', - ConnectTimeout => $self->{timeout}, - Carp => \&my_logger, - Reason => \$reason, - ClientConn => { - 'ChannelName' => $self->{channel}, - 'TransportType' => 'TCP', - 'ConnectionName' => $self->{hostname} . '(' . $self->{port} . ')', - 'MaxMsgLength' => 16 * 1024 * 1024 - } - ); - if (!$self->{qmgr}) { - $self->{output}->add_option_msg(short_msg => 'unable to connect to the queue manager: ' . MQSeries::MQReasonToText($reason)); - $self->{output}->option_exit(); - } - - $self->{mq_command} = MQSeries::Command->new(QueueManager => $self->{qmgr}, CommandVersion => eval('MQSeries::MQCFH_VERSION_3')); - if (!$self->{mq_command}) { - $self->{output}->add_option_msg(short_msg => 'unable to instantiate command object'); - $self->{output}->option_exit(); - } - - $self->{connected} = 1; - - my $results = $self->execute_command(command => 'InquireQueueManager'); - $self->{qmgr_name} = $results->[0]->{QMgrName}; -} - -sub execute_command { - my ($self, %options) = @_; - - $self->connect(); - my @results; - if ($options{command} eq 'InquireQueueManager') { - @results = $self->{mq_command}->InquireQueueManager(%{$options{attrs}}); - } elsif ($options{command} eq 'InquireQueueManagerStatus') { - @results = $self->{mq_command}->InquireQueueManagerStatus(%{$options{attrs}}); - } elsif ($options{command} eq 'InquireChannelStatus') { - @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) { - $self->{output}->add_option_msg(short_msg => "method '$options{command}' issue: " . $self->{mq_command}->ReasonText()); - $self->{output}->option_exit(); - } - - return \@results; -} - -1; - -__END__ - -=head1 NAME - -IBM MQ MQI - -=head1 CUSTOM MQI OPTIONS - -IBM MQ MQI - -=over 8 - -=item B<--hostname> - -Hostname or IP address. - -=item B<--port> - -Port used (Default: 1414) - -=item B<--channel> - -Channel name. - -=item B<--timeout> - -Set timeout in seconds (Default: 30). - -=back - -=head1 DESCRIPTION - -B. - -=cut +# +# 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::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'channel:s' => { name => 'channel' }, + 'timeout:s' => { name => 'timeout' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MQI OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'MQSeries::QueueManager', + error_msg => "Cannot load module 'MQSeries::QueueManager'." + ); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'MQSeries::Command', + error_msg => "Cannot load module 'MQSeries::Command'." + ); + + $self->{connected} = 0; + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{channel} = (defined($self->{option_results}->{channel})) ? $self->{option_results}->{channel} : ''; + $self->{port} = (defined($self->{option_results}->{port})) && $self->{option_results}->{port} =~ /(\d+)/ ? $1 : 1414; + $self->{timeout} = (defined($self->{option_results}->{timeout})) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 30; + + if ($self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + if ($self->{channel} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --channel option.'); + $self->{output}->option_exit(); + } + + return 0; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub get_qmgr_name { + my ($self, %options) = @_; + + return $self->{qmgr_name}; +} + +sub my_logger {} + +sub connect { + my ($self, %options) = @_; + + return if ($self->{connected} == 1); + + my $reason; + $self->{qmgr} = MQSeries::QueueManager->new( + QueueManager => '', + ConnectTimeout => $self->{timeout}, + Carp => \&my_logger, + Reason => \$reason, + ClientConn => { + 'ChannelName' => $self->{channel}, + 'TransportType' => 'TCP', + 'ConnectionName' => $self->{hostname} . '(' . $self->{port} . ')', + 'MaxMsgLength' => 16 * 1024 * 1024 + } + ); + if (!$self->{qmgr}) { + $self->{output}->add_option_msg(short_msg => 'unable to connect to the queue manager: ' . MQSeries::MQReasonToText($reason)); + $self->{output}->option_exit(); + } + + $self->{mq_command} = MQSeries::Command->new(QueueManager => $self->{qmgr}, CommandVersion => eval('MQSeries::MQCFH_VERSION_3')); + if (!$self->{mq_command}) { + $self->{output}->add_option_msg(short_msg => 'unable to instantiate command object'); + $self->{output}->option_exit(); + } + + $self->{connected} = 1; + + my $results = $self->execute_command(command => 'InquireQueueManager'); + $self->{qmgr_name} = $results->[0]->{QMgrName}; +} + +sub execute_command { + my ($self, %options) = @_; + + $self->connect(); + my @results; + if ($options{command} eq 'InquireQueueManager') { + @results = $self->{mq_command}->InquireQueueManager(%{$options{attrs}}); + } elsif ($options{command} eq 'InquireQueueManagerStatus') { + @results = $self->{mq_command}->InquireQueueManagerStatus(%{$options{attrs}}); + } elsif ($options{command} eq 'InquireChannelStatus') { + @results = $self->{mq_command}->InquireChannelStatus(%{$options{attrs}}); + } elsif ($options{command} eq 'InquireQueueStatus') { + @results = $self->{mq_command}->InquireQueueStatus(%{$options{attrs}}); + } elsif ($options{command} eq 'InquireChannel') { + @results = $self->{mq_command}->InquireChannel(%{$options{attrs}}); + } + + if (!@results) { + $self->{output}->add_option_msg(short_msg => "method '$options{command}' issue: " . $self->{mq_command}->ReasonText()); + $self->{output}->option_exit(); + } + + return \@results; +} + +1; + +__END__ + +=head1 NAME + +IBM MQ MQI + +=head1 CUSTOM MQI OPTIONS + +IBM MQ MQI + +=over 8 + +=item B<--hostname> + +Hostname or IP address. + +=item B<--port> + +Port used (Default: 1414) + +=item B<--channel> + +Channel name. + +=item B<--timeout> + +Set timeout in seconds (Default: 30). + +=back + +=head1 DESCRIPTION + +B. + +=cut \ No newline at end of file diff --git a/apps/mq/ibmmq/mqi/mode/channels.pm b/apps/mq/ibmmq/mqi/mode/channels.pm index 0f36b3cf6..d832b408b 100644 --- a/apps/mq/ibmmq/mqi/mode/channels.pm +++ b/apps/mq/ibmmq/mqi/mode/channels.pm @@ -1,209 +1,217 @@ -# -# 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::channels; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); - -sub custom_status_output { - my ($self, %options) = @_; - - return sprintf( - 'status: %s [message channel agent: %s]', - $self->{result_values}->{channel_status}, - $self->{result_values}->{mca_status} - ); -} - -sub custom_traffic_in_perfdata { - my ($self) = @_; - - $self->{output}->perfdata_add( - nlabel => $self->{nlabel}, unit => 'b/s', - instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], - value => $self->{result_values}->{traffic_in_per_second}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), - min => 0 - ); -} - -sub custom_traffic_out_perfdata { - my ($self) = @_; - - $self->{output}->perfdata_add( - nlabel => $self->{nlabel}, unit => 'b/s', - instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], - value => $self->{result_values}->{traffic_out_per_second}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), - min => 0 - ); -} - -sub prefix_channel_output { - my ($self, %options) = @_; - - return "Channel '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{channel_name} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } }, - ]; - - $self->{maps_counters}->{channel} = [ - { label => 'status', threshold => 0, set => { - key_values => [ - { name => 'qmgr_name' }, { name => 'channel_name' }, - { name => 'channel_status' }, { name => 'mca_status' } - ], - closure_custom_calc => \&catalog_status_calc, - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold - } - }, - { label => 'traffic-in', nlabel => 'channel.traffic.in.bitspersecond', set => { - key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], - output_template => 'traffic in: %s %s/s', - per_second => 1, output_change_bytes => 2, - closure_custom_perfdata => $self->can('custom_traffic_in_perfdata') - } - }, - { label => 'traffic-out', nlabel => 'channel.traffic.out.bitspersecond', set => { - key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], - output_template => 'traffic out: %s %s/s', - per_second => 1, output_change_bytes => 2, - closure_custom_perfdata => $self->can('custom_traffic_out_perfdata') - } - } - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); - 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|idle/i' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); -} - -sub manage_selection { - my ($self, %options) = @_; - - my $result = $options{custom}->execute_command( - 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}, - channel_status => lc($_->{ChannelStatus}), - mca_status => lc($_->{MCAStatus}), - traffic_in => $_->{BytesReceived} * 8, - traffic_out => $_->{BytesSent} * 8 - }; - } - - 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}->{$_} = { - 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')); -} - -1; - -__END__ - -=head1 MODE - -Check channels. - -=over 8 - -=item B<--filter-name> - -Filter channel name (Can use regexp). - -=item B<--unknown-status> - -Set unknown threshold for status (Default: ''). -Can used special variables like: %{channel_status}, %{mca_status} - -=item B<--warning-status> - -Set warning threshold for status (Default: ''). -Can used special variables like: %{channel_status}, %{mca_status} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{channel_status} !~ /running|idle/i'). -Can used special variables like: %{channel_status}, %{mca_status} - -=item B<--warning-*> B<--critical-*> - -Thresholds. -Can be: 'traffic-in', 'traffic-out'. - -=back - -=cut +# +# 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::channels; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s [message channel agent: %s]', + $self->{result_values}->{channel_status}, + $self->{result_values}->{mca_status} + ); +} + +sub custom_traffic_in_perfdata { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, unit => 'b/s', + instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], + value => $self->{result_values}->{traffic_in_per_second}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub custom_traffic_out_perfdata { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, unit => 'b/s', + instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], + value => $self->{result_values}->{traffic_out_per_second}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); +} + +sub prefix_channel_output { + my ($self, %options) = @_; + + return "Channel '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{channel_name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{channel} = [ + { label => 'status', threshold => 0, set => { + key_values => [ + { name => 'qmgr_name' }, { name => 'channel_name' }, + { name => 'channel_status' }, { name => 'mca_status' } + ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'traffic-in', nlabel => 'channel.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], + output_template => 'traffic in: %s %s/s', + per_second => 1, output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_traffic_in_perfdata') + } + }, + { label => 'traffic-out', nlabel => 'channel.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], + output_template => 'traffic out: %s %s/s', + per_second => 1, output_change_bytes => 2, + closure_custom_perfdata => $self->can('custom_traffic_out_perfdata') + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{channel_status} !~ /running|idle/i' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command( + command => 'InquireChannelStatus', + attrs => { } + ); + my $names = $options{custom}->execute_command( + command => 'InquireChannel', + 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}/); + next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' + && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/); + + $self->{channel}->{$_->{ChannelName}} = { + qmgr_name => $options{custom}->get_qmgr_name(), + channel_name => $_->{ChannelName}, + channel_status => lc($_->{ChannelStatus}), + channel_type => $_->{ChannelType}, + mca_status => lc($_->{MCAStatus}), + traffic_in => $_->{BytesReceived} * 8, + traffic_out => $_->{BytesSent} * 8 + }; + } + + foreach (@$names) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/); + next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' + && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/); + + if (!defined($self->{channel}->{$_->{ChannelName}})) { + $self->{channel}->{$_->{ChannelName}} = { + qmgr_name => $options{custom}->get_qmgr_name(), + channel_name => $_->{ChannelName}, + channel_status => 'idle', + channel_type => $_->{ChannelType}, + 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')); +} + +1; + +__END__ + +=head1 MODE + +Check channels. + +=over 8 + +=item B<--filter-name> + +Filter channel name (Can use regexp). + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{channel_status}, %{mca_status} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{channel_status}, %{mca_status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{channel_status} !~ /running|idle/i'). +Can used special variables like: %{channel_status}, %{mca_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'traffic-in', 'traffic-out'. + +=back + +=cut \ No newline at end of file diff --git a/apps/mq/ibmmq/mqi/mode/listchannels.pm b/apps/mq/ibmmq/mqi/mode/listchannels.pm index 9ab046c25..c68519074 100644 --- a/apps/mq/ibmmq/mqi/mode/listchannels.pm +++ b/apps/mq/ibmmq/mqi/mode/listchannels.pm @@ -1,107 +1,109 @@ -# -# 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 +# +# 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 => 'InquireChannel', + attrs => {} + ); + + $self->{channel} = {}; + foreach (@$result) { + $self->{channel}->{$_->{ChannelName}} = { + name => $_->{ChannelName}, + type => $_->{ChannelType} + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort keys %{$self->{channel}}) { + $self->{output}->output_add(long_msg => + sprintf( + '[name = %s][type = %s]', + $self->{channel}->{$_}->{name}, + $self->{channel}->{$_}->{type} + ) + ); + } + $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','type']); +} + +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 \ No newline at end of file