(enh)plugin - add type filtering capability

This commit is contained in:
Sims24 2020-03-13 11:19:57 +01:00
parent ba1594b4ae
commit 87d0d06985
3 changed files with 555 additions and 545 deletions

View File

@ -1,229 +1,229 @@
# #
# Copyright 2020 Centreon (http://www.centreon.com/) # Copyright 2020 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package apps::mq::ibmmq::mqi::custom::api; package apps::mq::ibmmq::mqi::custom::api;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = {}; my $self = {};
bless $self, $class; bless $self, $class;
if (!defined($options{output})) { if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n"; print "Class Custom: Need to specify 'output' argument.\n";
exit 3; exit 3;
} }
if (!defined($options{options})) { if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit(); $options{output}->option_exit();
} }
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' }, 'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' }, 'port:s' => { name => 'port' },
'channel:s' => { name => 'channel' }, 'channel:s' => { name => 'channel' },
'timeout:s' => { name => 'timeout' } 'timeout:s' => { name => 'timeout' }
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MQI OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM MQI OPTIONS', once => 1);
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{mode} = $options{mode}; $self->{mode} = $options{mode};
centreon::plugins::misc::mymodule_load( centreon::plugins::misc::mymodule_load(
output => $self->{output}, output => $self->{output},
module => 'MQSeries::QueueManager', module => 'MQSeries::QueueManager',
error_msg => "Cannot load module 'MQSeries::QueueManager'." error_msg => "Cannot load module 'MQSeries::QueueManager'."
); );
centreon::plugins::misc::mymodule_load( centreon::plugins::misc::mymodule_load(
output => $self->{output}, output => $self->{output},
module => 'MQSeries::Command', module => 'MQSeries::Command',
error_msg => "Cannot load module 'MQSeries::Command'." error_msg => "Cannot load module 'MQSeries::Command'."
); );
$self->{connected} = 0; $self->{connected} = 0;
return $self; return $self;
} }
sub set_options { sub set_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{option_results} = $options{option_results}; $self->{option_results} = $options{option_results};
} }
sub set_defaults { sub set_defaults {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (keys %{$options{default}}) { foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) { if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) { foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) { if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
} }
} }
} }
} }
} }
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{channel} = (defined($self->{option_results}->{channel})) ? $self->{option_results}->{channel} : ''; $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->{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; $self->{timeout} = (defined($self->{option_results}->{timeout})) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 30;
if ($self->{hostname} eq '') { if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ($self->{channel} eq '') { if ($self->{channel} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --channel option.'); $self->{output}->add_option_msg(short_msg => 'Need to specify --channel option.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
return 0; return 0;
} }
sub get_hostname { sub get_hostname {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{hostname}; return $self->{hostname};
} }
sub get_port { sub get_port {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{port}; return $self->{port};
} }
sub get_qmgr_name { sub get_qmgr_name {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{qmgr_name}; return $self->{qmgr_name};
} }
sub my_logger {} sub my_logger {}
sub connect { sub connect {
my ($self, %options) = @_; my ($self, %options) = @_;
return if ($self->{connected} == 1); return if ($self->{connected} == 1);
my $reason; my $reason;
$self->{qmgr} = MQSeries::QueueManager->new( $self->{qmgr} = MQSeries::QueueManager->new(
QueueManager => '', QueueManager => '',
ConnectTimeout => $self->{timeout}, ConnectTimeout => $self->{timeout},
Carp => \&my_logger, Carp => \&my_logger,
Reason => \$reason, Reason => \$reason,
ClientConn => { ClientConn => {
'ChannelName' => $self->{channel}, 'ChannelName' => $self->{channel},
'TransportType' => 'TCP', 'TransportType' => 'TCP',
'ConnectionName' => $self->{hostname} . '(' . $self->{port} . ')', 'ConnectionName' => $self->{hostname} . '(' . $self->{port} . ')',
'MaxMsgLength' => 16 * 1024 * 1024 'MaxMsgLength' => 16 * 1024 * 1024
} }
); );
if (!$self->{qmgr}) { if (!$self->{qmgr}) {
$self->{output}->add_option_msg(short_msg => 'unable to connect to the queue manager: ' . MQSeries::MQReasonToText($reason)); $self->{output}->add_option_msg(short_msg => 'unable to connect to the queue manager: ' . MQSeries::MQReasonToText($reason));
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{mq_command} = MQSeries::Command->new(QueueManager => $self->{qmgr}, CommandVersion => eval('MQSeries::MQCFH_VERSION_3')); $self->{mq_command} = MQSeries::Command->new(QueueManager => $self->{qmgr}, CommandVersion => eval('MQSeries::MQCFH_VERSION_3'));
if (!$self->{mq_command}) { if (!$self->{mq_command}) {
$self->{output}->add_option_msg(short_msg => 'unable to instantiate command object'); $self->{output}->add_option_msg(short_msg => 'unable to instantiate command object');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{connected} = 1; $self->{connected} = 1;
my $results = $self->execute_command(command => 'InquireQueueManager'); my $results = $self->execute_command(command => 'InquireQueueManager');
$self->{qmgr_name} = $results->[0]->{QMgrName}; $self->{qmgr_name} = $results->[0]->{QMgrName};
} }
sub execute_command { sub execute_command {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->connect(); $self->connect();
my @results; my @results;
if ($options{command} eq 'InquireQueueManager') { if ($options{command} eq 'InquireQueueManager') {
@results = $self->{mq_command}->InquireQueueManager(%{$options{attrs}}); @results = $self->{mq_command}->InquireQueueManager(%{$options{attrs}});
} elsif ($options{command} eq 'InquireQueueManagerStatus') { } elsif ($options{command} eq 'InquireQueueManagerStatus') {
@results = $self->{mq_command}->InquireQueueManagerStatus(%{$options{attrs}}); @results = $self->{mq_command}->InquireQueueManagerStatus(%{$options{attrs}});
} elsif ($options{command} eq 'InquireChannelStatus') { } elsif ($options{command} eq 'InquireChannelStatus') {
@results = $self->{mq_command}->InquireChannelStatus(%{$options{attrs}}); @results = $self->{mq_command}->InquireChannelStatus(%{$options{attrs}});
} elsif ($options{command} eq 'InquireQueueStatus') { } elsif ($options{command} eq 'InquireQueueStatus') {
@results = $self->{mq_command}->InquireQueueStatus(%{$options{attrs}}); @results = $self->{mq_command}->InquireQueueStatus(%{$options{attrs}});
} elsif ($options{command} eq 'InquireChannelNames') { } elsif ($options{command} eq 'InquireChannel') {
@results = $self->{mq_command}->InquireChannelNames(%{$options{attrs}}); @results = $self->{mq_command}->InquireChannel(%{$options{attrs}});
} }
if (!@results) { if (!@results) {
$self->{output}->add_option_msg(short_msg => "method '$options{command}' issue: " . $self->{mq_command}->ReasonText()); $self->{output}->add_option_msg(short_msg => "method '$options{command}' issue: " . $self->{mq_command}->ReasonText());
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
return \@results; return \@results;
} }
1; 1;
__END__ __END__
=head1 NAME =head1 NAME
IBM MQ MQI IBM MQ MQI
=head1 CUSTOM MQI OPTIONS =head1 CUSTOM MQI OPTIONS
IBM MQ MQI IBM MQ MQI
=over 8 =over 8
=item B<--hostname> =item B<--hostname>
Hostname or IP address. Hostname or IP address.
=item B<--port> =item B<--port>
Port used (Default: 1414) Port used (Default: 1414)
=item B<--channel> =item B<--channel>
Channel name. Channel name.
=item B<--timeout> =item B<--timeout>
Set timeout in seconds (Default: 30). Set timeout in seconds (Default: 30).
=back =back
=head1 DESCRIPTION =head1 DESCRIPTION
B<custom>. B<custom>.
=cut =cut

View File

@ -1,209 +1,217 @@
# #
# Copyright 2020 Centreon (http://www.centreon.com/) # Copyright 2020 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package apps::mq::ibmmq::mqi::mode::channels; package apps::mq::ibmmq::mqi::mode::channels;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf( return sprintf(
'status: %s [message channel agent: %s]', 'status: %s [message channel agent: %s]',
$self->{result_values}->{channel_status}, $self->{result_values}->{channel_status},
$self->{result_values}->{mca_status} $self->{result_values}->{mca_status}
); );
} }
sub custom_traffic_in_perfdata { sub custom_traffic_in_perfdata {
my ($self) = @_; my ($self) = @_;
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
nlabel => $self->{nlabel}, unit => 'b/s', nlabel => $self->{nlabel}, unit => 'b/s',
instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}],
value => $self->{result_values}->{traffic_in_per_second}, value => $self->{result_values}->{traffic_in_per_second},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0 min => 0
); );
} }
sub custom_traffic_out_perfdata { sub custom_traffic_out_perfdata {
my ($self) = @_; my ($self) = @_;
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
nlabel => $self->{nlabel}, unit => 'b/s', nlabel => $self->{nlabel}, unit => 'b/s',
instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}], instances => [$self->{result_values}->{qmgr_name_absolute}, $self->{result_values}->{channel_name_absolute}],
value => $self->{result_values}->{traffic_out_per_second}, value => $self->{result_values}->{traffic_out_per_second},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0 min => 0
); );
} }
sub prefix_channel_output { sub prefix_channel_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Channel '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{channel_name} . "' "; return "Channel '" . $options{instance_value}->{qmgr_name} . ':' . $options{instance_value}->{channel_name} . "' ";
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } }, { name => 'channel', type => 1, cb_prefix_output => 'prefix_channel_output', message_multiple => 'All channels are ok', skipped_code => { -10 => 1 } },
]; ];
$self->{maps_counters}->{channel} = [ $self->{maps_counters}->{channel} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ key_values => [
{ name => 'qmgr_name' }, { name => 'channel_name' }, { name => 'qmgr_name' }, { name => 'channel_name' },
{ name => 'channel_status' }, { name => 'mca_status' } { name => 'channel_status' }, { name => 'mca_status' }
], ],
closure_custom_calc => \&catalog_status_calc, closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold
} }
}, },
{ label => 'traffic-in', nlabel => 'channel.traffic.in.bitspersecond', set => { { label => 'traffic-in', nlabel => 'channel.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ],
output_template => 'traffic in: %s %s/s', output_template => 'traffic in: %s %s/s',
per_second => 1, output_change_bytes => 2, per_second => 1, output_change_bytes => 2,
closure_custom_perfdata => $self->can('custom_traffic_in_perfdata') closure_custom_perfdata => $self->can('custom_traffic_in_perfdata')
} }
}, },
{ label => 'traffic-out', nlabel => 'channel.traffic.out.bitspersecond', set => { { label => 'traffic-out', nlabel => 'channel.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ], key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'qmgr_name' }, { name => 'channel_name' } ],
output_template => 'traffic out: %s %s/s', output_template => 'traffic out: %s %s/s',
per_second => 1, output_change_bytes => 2, per_second => 1, output_change_bytes => 2,
closure_custom_perfdata => $self->can('custom_traffic_out_perfdata') closure_custom_perfdata => $self->can('custom_traffic_out_perfdata')
} }
} }
]; ];
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' }, 'filter-type:s' => { name => 'filter_type' },
'warning-status:s' => { name => 'warning_status', default => '' }, 'unknown-status:s' => { name => 'unknown_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{channel_status} !~ /running|idle/i' }, 'warning-status:s' => { name => 'warning_status', default => '' },
}); 'critical-status:s' => { name => 'critical_status', default => '%{channel_status} !~ /running|idle/i' },
return $self; });
} return $self;
}
sub check_options {
my ($self, %options) = @_; sub check_options {
$self->SUPER::check_options(%options); my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
} $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub manage_selection {
my ($self, %options) = @_; sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->execute_command(
command => 'InquireChannelStatus', my $result = $options{custom}->execute_command(
attrs => { } command => 'InquireChannelStatus',
); attrs => { }
my $names = $options{custom}->execute_command( );
command => 'InquireChannelNames', my $names = $options{custom}->execute_command(
attrs => { } command => 'InquireChannel',
); attrs => { }
);
$self->{channel} = {};
foreach (@$result) { $self->{channel} = {};
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' foreach (@$result) {
&& $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/); next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
&& $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/);
$self->{channel}->{$_->{ChannelName}} = { next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne ''
qmgr_name => $options{custom}->get_qmgr_name(), && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/);
channel_name => $_->{ChannelName},
channel_status => lc($_->{ChannelStatus}), $self->{channel}->{$_->{ChannelName}} = {
mca_status => lc($_->{MCAStatus}), qmgr_name => $options{custom}->get_qmgr_name(),
traffic_in => $_->{BytesReceived} * 8, channel_name => $_->{ChannelName},
traffic_out => $_->{BytesSent} * 8 channel_status => lc($_->{ChannelStatus}),
}; channel_type => $_->{ChannelType},
} mca_status => lc($_->{MCAStatus}),
traffic_in => $_->{BytesReceived} * 8,
foreach (@$names) { traffic_out => $_->{BytesSent} * 8
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}->{$_} = { foreach (@$names) {
qmgr_name => $options{custom}->get_qmgr_name(), next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne ''
channel_name => $_, && $_->{ChannelName} !~ /$self->{option_results}->{filter_name}/);
channel_status => 'idle', next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne ''
mca_status => '-', && $_->{ChannelType} !~ /$self->{option_results}->{filter_type}/);
};
} if (!defined($self->{channel}->{$_->{ChannelName}})) {
} $self->{channel}->{$_->{ChannelName}} = {
qmgr_name => $options{custom}->get_qmgr_name(),
$self->{cache_name} = "ibmmq_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . channel_name => $_->{ChannelName},
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); channel_status => 'idle',
} channel_type => $_->{ChannelType},
mca_status => '-',
1; };
}
__END__ }
=head1 MODE $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'));
Check channels. }
=over 8 1;
=item B<--filter-name> __END__
Filter channel name (Can use regexp). =head1 MODE
=item B<--unknown-status> Check channels.
Set unknown threshold for status (Default: ''). =over 8
Can used special variables like: %{channel_status}, %{mca_status}
=item B<--filter-name>
=item B<--warning-status>
Filter channel name (Can use regexp).
Set warning threshold for status (Default: '').
Can used special variables like: %{channel_status}, %{mca_status} =item B<--unknown-status>
=item B<--critical-status> Set unknown threshold for status (Default: '').
Can used special variables like: %{channel_status}, %{mca_status}
Set critical threshold for status (Default: '%{channel_status} !~ /running|idle/i').
Can used special variables like: %{channel_status}, %{mca_status} =item B<--warning-status>
=item B<--warning-*> B<--critical-*> Set warning threshold for status (Default: '').
Can used special variables like: %{channel_status}, %{mca_status}
Thresholds.
Can be: 'traffic-in', 'traffic-out'. =item B<--critical-status>
=back Set critical threshold for status (Default: '%{channel_status} !~ /running|idle/i').
Can used special variables like: %{channel_status}, %{mca_status}
=cut
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'traffic-in', 'traffic-out'.
=back
=cut

View File

@ -1,107 +1,109 @@
# #
# Copyright 2020 Centreon (http://www.centreon.com/) # Copyright 2020 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package apps::mq::ibmmq::mqi::mode::listchannels; package apps::mq::ibmmq::mqi::mode::listchannels;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => {}); $options{options}->add_options(arguments => {});
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $result = $options{custom}->execute_command( my $result = $options{custom}->execute_command(
command => 'InquireChannelNames', command => 'InquireChannel',
attrs => {} attrs => {}
); );
$self->{channel} = {}; $self->{channel} = {};
foreach (@$result) { foreach (@$result) {
$self->{channel}->{$_} = { $self->{channel}->{$_->{ChannelName}} = {
name => $_ name => $_->{ChannelName},
}; type => $_->{ChannelType}
} };
} }
}
sub run {
my ($self, %options) = @_; sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach (sort keys %{$self->{channel}}) { $self->manage_selection(%options);
$self->{output}->output_add(long_msg => foreach (sort keys %{$self->{channel}}) {
sprintf( $self->{output}->output_add(long_msg =>
'[name = %s]', sprintf(
$self->{channel}->{$_}->{name} '[name = %s][type = %s]',
) $self->{channel}->{$_}->{name},
); $self->{channel}->{$_}->{type}
} )
$self->{output}->output_add( );
severity => 'OK', }
short_msg => 'List channels:' $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();
} $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
sub disco_format { }
my ($self, %options) = @_;
sub disco_format {
$self->{output}->add_disco_format(elements => ['name']); my ($self, %options) = @_;
}
$self->{output}->add_disco_format(elements => ['name','type']);
sub disco_show { }
my ($self, %options) = @_;
sub disco_show {
$self->manage_selection(%options); my ($self, %options) = @_;
foreach (values %{$self->{channel}}) {
$self->{output}->add_disco_entry(%$_); $self->manage_selection(%options);
} foreach (values %{$self->{channel}}) {
} $self->{output}->add_disco_entry(%$_);
}
1; }
__END__ 1;
=head1 MODE __END__
List channels. =head1 MODE
=over 8 List channels.
=back =over 8
=cut =back
=cut