Merge pull request #2418 from centreon/fix-2346

Fix #2346
This commit is contained in:
qgarnier 2020-12-08 11:33:59 +01:00 committed by GitHub
commit 30fdcdad33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 493 additions and 31 deletions

View File

@ -0,0 +1,466 @@
#
# 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 storage::hp::p2000::xmlapi::mode::controllers;
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_ng);
sub custom_write_cache_calc {
my ($self, %options) = @_;
my $diff_hits = ($options{new_datas}->{$self->{instance} . '_write-cache-hits'} - $options{old_datas}->{$self->{instance} . '_write-cache-hits'});
my $total = $diff_hits
+ ($options{new_datas}->{$self->{instance} . '_write-cache-misses'} - $options{old_datas}->{$self->{instance} . '_write-cache-misses'});
if ($total == 0) {
$self->{error_msg} = "skipped";
return -2;
}
$self->{result_values}->{'write-cache-hits_prct'} = $diff_hits * 100 / $total;
return 0;
}
sub custom_read_cache_calc {
my ($self, %options) = @_;
my $diff_hits = ($options{new_datas}->{$self->{instance} . '_read-cache-hits'} - $options{old_datas}->{$self->{instance} . '_read-cache-hits'});
my $total = $diff_hits
+ ($options{new_datas}->{$self->{instance} . '_read-cache-misses'} - $options{old_datas}->{$self->{instance} . '_read-cache-misses'});
if ($total == 0) {
$self->{error_msg} = "skipped";
return -2;
}
$self->{result_values}->{'read-cache-hits_prct'} = $diff_hits * 100 / $total;
return 0;
}
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s%s',
$self->{result_values}->{status},
$self->{result_values}->{status} ne 'ok' ?
'[reason: ' . $self->{result_values}->{reason} . '][recommendation: ' . $self->{result_values}->{recommendation} . ']' : ''
);
}
sub controller_long_output {
my ($self, %options) = @_;
return "checking controller '" . $options{instance_value}->{name} . "'";
}
sub prefix_controller_output {
my ($self, %options) = @_;
return "Controller '" . $options{instance_value}->{name} . "' ";
}
sub prefix_network_output {
my ($self, %options) = @_;
return "network '" . $options{instance_value}->{name} . "' ";
}
sub prefix_port_output {
my ($self, %options) = @_;
return "port '" . $options{instance_value}->{name} . "' ";
}
sub prefix_expander_port_output {
my ($self, %options) = @_;
return "expander port '" . $options{instance_value}->{name} . "' ";
}
sub prefix_compact_flash_output {
my ($self, %options) = @_;
return "compact flash '" . $options{instance_value}->{name} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'controllers', type => 3, cb_prefix_output => 'prefix_controller_output', cb_long_output => 'controller_long_output', indent_long_output => ' ', message_multiple => 'All controllers are ok',
group => [
{ name => 'controller_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'controller_stats', type => 0, skipped_code => { -10 => 1 } },
{ name => 'networks', display_long => 1, cb_prefix_output => 'prefix_network_output', message_multiple => 'networks are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'ports', display_long => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'ports are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'expander_ports', display_long => 1, cb_prefix_output => 'prefix_expander_port_output', message_multiple => 'expander ports are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'compact_flash', display_long => 1, cb_prefix_output => 'prefix_compact_flash_output', message_multiple => 'compact flash are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
];
$self->{maps_counters}->{controller_status} = [
{
label => 'controller-status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'name' },
{ name => 'recommendation' }, { name => 'reason' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{networks} = [
{
label => 'network-status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'name' },
{ name => 'recommendation' }, { name => 'reason' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{ports} = [
{
label => 'port-status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'name' },
{ name => 'recommendation' }, { name => 'reason' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{expander_ports} = [
{
label => 'expander-port-status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'name' },
{ name => 'recommendation' }, { name => 'reason' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{compact_flash} = [
{
label => 'compact-flash-status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [
{ name => 'status' }, { name => 'name' },
{ name => 'recommendation' }, { name => 'reason' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{controller_stats} = [
{ label => 'read', nlabel => 'controller.io.read.usage.bytespersecond', set => {
key_values => [ { name => 'data-read-numeric', per_second => 1 } ],
output_template => 'read i/o: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'write', nlabel => 'controller.io.write.usage.bytespersecond', set => {
key_values => [ { name => 'data-written-numeric', per_second => 1 } ],
output_template => 'write i/o: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 },
],
}
},
{ label => 'read-cache-hits', nlabel => 'controller.cache.read.hits.percentage', set => {
key_values => [ { name => 'read-cache-hits', diff => 1 }, { name => 'read-cache-misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_read_cache_calc'),
output_template => 'read cache hits: %.2f %%',
output_use => 'read-cache-hits_prct', threshold_use => 'read-cache-hits_prct',
perfdatas => [
{ value => 'read-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'write-cache-hits', nlabel => 'controller.cache.write.hits.percentage', set => {
key_values => [ { name => 'write-cache-hits', diff => 1 }, { name => 'write-cache-misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_write_cache_calc'),
output_template => 'write cache hits: %.2f %%',
output_use => 'write-cache-hits_prct', threshold_use => 'write-cache-hits_prct',
perfdatas => [
{ value => 'write-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'iops', nlabel => 'controller.io.usage.iops', set => {
key_values => [ { name => 'iops' } ],
output_template => 'iops: %s',
perfdatas => [
{ unit => 'iops', min => 0, label_extra_instance => 1 }
]
}
}
];
}
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-controller-name:s' => { name => 'filter_controller_name' }
});
return $self;
}
my $map_health = {
0 => 'ok', 1 => 'degraded',
2 => 'failed', 3 => 'unknown',
4 => 'not available',
};
my $map_base_type = {
'compact-flash' => 'compact_flash',
'expander-ports' => 'expander_ports',
'port' => 'ports',
'network-parameters' => 'networks'
};
sub manage_selection {
my ($self, %options) = @_;
my ($controllers) = $options{custom}->get_infos(
cmd => 'show controllers',
base_type => 'controllers',
properties_name => '^OBJECT|durable-id|health-numeric|health-reason|health-recommendation$'
);
$self->{controllers} = {};
foreach my $ctrl (@$controllers) {
my $name = lc($ctrl->{'durable-id'});
if (defined($self->{option_results}->{filter_controller_name}) && $self->{option_results}->{filter_controller_name} ne '' &&
$name !~ /$self->{option_results}->{filter_controller_name}/) {
$self->{output}->output_add(long_msg => "skipping controller '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{controllers}->{$name} = {
name => $name,
controller_status => {
name => $name,
status => $map_health->{ $ctrl->{'health-numeric'} },
reason => defined($ctrl->{'health-reason'}) ? $ctrl->{'health-reason'} : '-',
recommendation => defined($ctrl->{'health-recommendation'}) ? $ctrl->{'health-recommendation'} : '-'
},
compact_flash => {},
networks => {},
ports => {},
expander_ports => {},
};
foreach (@{$ctrl->{OBJECT}}) {
next if (!defined($map_base_type->{ $_->{basetype} }));
my ($id, $status, $reason, $recommendation);
foreach my $prop (@{$_->{PROPERTY}}) {
$id = $prop->{content} if ($prop->{name} eq 'durable-id');
$status = $map_health->{ $prop->{content} } if ($prop->{name} eq 'health-numeric');
$reason = $prop->{content} if ($prop->{name} eq 'health-reason');
$recommendation = $prop->{content} if ($prop->{name} eq 'health-recommendation');
}
$self->{controllers}->{$name}->{ $map_base_type->{ $_->{basetype} } }->{$id} = {
name => $id,
status => $status,
reason => defined($reason) ? $reason : '-',
recommendation => defined($recommendation) ? $recommendation : '-'
};
}
}
if (scalar(keys %{$self->{controllers}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No controller found.');
$self->{output}->option_exit();
}
my ($stats) = $options{custom}->get_infos(
cmd => 'show controller-statistics',
base_type => 'controller-statistics',
properties_name => '^durable-id|data-read-numeric|data-written-numeric|write-cache-hits|write-cache-misses|read-cache-hits|read-cache-misses|iops$'
);
foreach (@$stats) {
my $name = lc($_->{'durable-id'});
next if (!defined($self->{controllers}->{$name}));
$self->{controllers}->{$name}->{controller_stats} = $_;
}
$self->{cache_name} = 'hp_p2000_' . $options{custom}->{hostname} . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_controller_name}) ? md5_hex($self->{option_results}->{filter_controller_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check controllers.
=over 8
=item B<--filter-controller-name>
Filter controllers by controller name (can be a regexp).
=item B<--unknown-controller-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-controller-status>
Set warning threshold for status (Default: '%{status} =~ /degraded/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-controller-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=item B<--unknown-network-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-network-status>
Set warning threshold for status (Default: '%{status} =~ /degraded/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-network-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=item B<--unknown-port-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-port-status>
Set warning threshold for status (Default: '%{status} =~ /degraded/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-port-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=item B<--unknown-expander-port-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-expander-port-status>
Set warning threshold for status (Default: '%{status} =~ /degraded/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-expander-port-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=item B<--unknown-compact-flash-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-compact-flash-status>
Set warning threshold for status (Default: '%{status} =~ /degraded/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-compact-flash-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'read', 'write', 'iops', 'write-cache-hits', 'read-cache-hits'.
=back
=cut

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
@ -55,12 +55,17 @@ sub set_counters {
];
$self->{maps_counters}->{vdisk} = [
{ label => 'status', threshold => 0, set => {
{
label => 'status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /degraded/i',
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
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,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'usage', nlabel => 'vdisk.space.usage.bytes', set => {
@ -68,8 +73,8 @@ sub set_counters {
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'used_space', template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' },
],
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'usage-free', nlabel => 'vdisk.space.free.bytes', display_ok => 0, set => {
@ -77,8 +82,8 @@ sub set_counters {
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ value => 'free_space', template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' },
],
unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'usage-prct', nlabel => 'vdisk.space.usage.percentage', display_ok => 0, set => {
@ -86,10 +91,10 @@ sub set_counters {
output_template => 'used : %.2f %%',
perfdatas => [
{ value => 'prct_used_space', template => '%.2f', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display' },
unit => '%', label_extra_instance => 1, instance_use => 'display' }
],
}
},
}
];
}
@ -99,22 +104,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /degraded/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /failed/i' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub prefix_vdisk_output {
my ($self, %options) = @_;
@ -198,7 +193,7 @@ Filter virtual disk name (can be a regexp).
=item B<--unknown-status>
Set unknon threshold for status (Default: '%{status} =~ /unknown/i').
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-status>

View File

@ -60,7 +60,7 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes statistics are ok', skipped_code => { -2 => 1, -10 => 1 } },
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes statistics are ok', skipped_code => { -2 => 1, -10 => 1 } }
];
$self->{maps_counters}->{volume} = [
@ -69,8 +69,8 @@ sub set_counters {
output_template => 'Read I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 },
],
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => {
@ -78,8 +78,8 @@ sub set_counters {
output_template => 'Write I/O : %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 },
],
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'read-cache-hits', nlabel => 'volume.cache.read.hits.percentage', set => {
@ -89,8 +89,8 @@ sub set_counters {
output_use => 'read-cache-hits_prct', threshold_use => 'read-cache-hits_prct',
perfdatas => [
{ value => 'read-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'write-cache-hits', nlabel => 'volume.cache.write.hits.percentage', set => {
@ -100,8 +100,8 @@ sub set_counters {
output_use => 'write-cache-hits_prct', threshold_use => 'write-cache-hits_prct',
perfdatas => [
{ value => 'write-cache-hits_prct', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1 },
],
unit => '%', min => 0, max => 100, label_extra_instance => 1 }
]
}
},
{ label => 'iops', nlabel => 'volume.io.usage.iops', set => {

View File

@ -32,6 +32,7 @@ sub new {
$self->{version} = '0.1';
$self->{modes} = {
'controllers' => 'storage::hp::p2000::xmlapi::mode::controllers',
'health' => 'storage::hp::p2000::xmlapi::mode::health',
'list-volumes' => 'storage::hp::p2000::xmlapi::mode::listvolumes',
'vdisks' => 'storage::hp::p2000::xmlapi::mode::vdisks',