break(netapp/ontap/snmp): qtree renamed as quota (#3313)

This commit is contained in:
qgarnier 2021-12-09 11:50:28 +01:00 committed by GitHub
parent 16a18029b1
commit 552c1d5d15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 435 additions and 260 deletions

View File

@ -1,259 +0,0 @@
#
# Copyright 2021 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::netapp::ontap::snmp::mode::qtreeusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'qtree', type => 1, cb_prefix_output => 'prefix_qtree_output', message_multiple => 'All qtree usages are ok.' },
];
$self->{maps_counters}->{qtree} = [
{ label => 'usage', set => {
key_values => [ { name => 'name' }, { name => 'used' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
];
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if ($self->{result_values}->{total} > 0 && defined($self->{instance_mode}->{option_results}->{free})) {
$label = 'free';
$value_perf = $self->{result_values}->{free};
}
my %total_options = ();
if ($self->{result_values}->{total} > 0 && $self->{instance_mode}->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(
label => $label, unit => 'B',
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{name} : undef,
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
# cannot use '%' or free option with unlimited system
return 'ok' if ($self->{result_values}->{total} <= 0 && ($self->{instance_mode}->{option_results}->{units} eq '%' || $self->{instance_mode}->{option_results}->{free}));
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my $msg;
if ($self->{result_values}->{total} <= 0) {
$msg = sprintf("Used: %s (unlimited)", $total_used_value . " " . $total_used_unit);
} else {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
$msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
}
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
return 0 if ($self->{result_values}->{total} == 0);
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
# qtree can be over 100%
if ($self->{result_values}->{free} < 0) {
$self->{result_values}->{free} = 0;
$self->{result_values}->{prct_free} = 0;
}
return 0;
}
sub prefix_qtree_output {
my ($self, %options) = @_;
return "Qtree '" . $options{instance_value}->{name} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
'filter-vserver:s' => { name => 'filter_vserver' },
'filter-volume:s' => { name => 'filter_volume' },
'filter-qtree:s' => { name => 'filter_qtree' },
'not-kbytes' => { name => 'not_kbytes' },
});
return $self;
}
my $mapping = {
qrV2Tree => { oid => '.1.3.6.1.4.1.789.1.4.6.1.14' },
qrV264KBytesUsed => { oid => '.1.3.6.1.4.1.789.1.4.6.1.25' },
qrV264KBytesLimit => { oid => '.1.3.6.1.4.1.789.1.4.6.1.26' },
qrV2VolumeName => { oid => '.1.3.6.1.4.1.789.1.4.6.1.29' },
qrV2Vserver => { oid => '.1.3.6.1.4.1.789.1.4.6.1.30' },
};
sub manage_selection {
my ($self, %options) = @_;
my $multi = 1;
$multi = 1024 unless defined($self->{option_results}->{not_kbytes});
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
my $results = $options{snmp}->get_multiple_table(oids => [
{ oid => $mapping->{qrV2Tree}->{oid} },
{ oid => $mapping->{qrV264KBytesUsed}->{oid} },
{ oid => $mapping->{qrV264KBytesLimit}->{oid} },
{ oid => $mapping->{qrV2VolumeName}->{oid} },
{ oid => $mapping->{qrV2Vserver}->{oid} },
], return_type => 1, nothing_quit => 1);
$self->{qtree} = {};
foreach my $oid (keys %{$results}) {
next if ($oid !~ /^$mapping->{qrV2Tree}->{oid}\.(.*)/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
if (defined($self->{option_results}->{filter_vserver}) && $self->{option_results}->{filter_vserver} ne '' &&
defined($result->{qrV2Vserver}) && $result->{qrV2Vserver} ne '' && $result->{qrV2Vserver} !~ /$self->{option_results}->{filter_vserver}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{qrV2Vserver} . "': no matching vserver name.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_volume}) && $self->{option_results}->{filter_volume} ne '' &&
defined($result->{qrV2VolumeName}) && $result->{qrV2VolumeName} ne '' && $result->{qrV2VolumeName} !~ /$self->{option_results}->{filter_volume}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{qrV2VolumeName} . "': no matching volume name.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_qtree}) && $self->{option_results}->{filter_qtree} ne '' &&
$result->{qrV2Tree} !~ /$self->{option_results}->{filter_qtree}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $result->{qrV2Tree} . "': no matching qtree name.", debug => 1);
next;
}
if (!defined($result->{qrV264KBytesUsed}) && !defined($result->{qrV264KBytesLimit})) {
$self->{output}->output_add(long_msg => "Skipping qtree '" . $result->{qrV2Tree} . "': no used or total values.", debug => 1);
next;
}
my $name = '';
$name = $result->{qrV2Vserver} . '/' if (defined($result->{qrV2Vserver}) && $result->{qrV2Vserver} ne '');
$name .= $result->{qrV2VolumeName} . '/' if (defined($result->{qrV2VolumeName}) && $result->{qrV2VolumeName} ne '');
$name .= $result->{qrV2Tree};
$self->{qtree}->{$instance} = { name => $name, used => $result->{qrV264KBytesUsed} * $multi, total => $result->{qrV264KBytesLimit} * $multi };
}
if (scalar(keys %{$self->{qtree}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entry found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check qtree quote usage.
=over 8
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--free>
Thresholds are on free space left.
=item B<--filter-vserver>
Filter by vserver name (can be a regexp).
=item B<--filter-volume>
Filter by volume name (can be a regexp).
=item B<--filter-qtree>
Filter by qtree name (can be a regexp).
=item B<--not-kbytes>
If qrV264KBytesUsed and qrV264KBytesLimit OIDs are not really KBytes.
=back
=cut

View File

@ -0,0 +1,434 @@
#
# Copyright 2021 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::netapp::ontap::snmp::mode::quotas;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::statefile;
sub prefix_quota_output {
my ($self, %options) = @_;
return sprintf(
"Quota '%s%s%s%s' ",
$options{instance_value}->{vserver} ne '' ? $options{instance_value}->{vserver} . '/' : '',
$options{instance_value}->{volume},
$options{instance_value}->{qtree} ne '' ? '/' . $options{instance_value}->{qtree} : '',
$self->{duplicated}->{$options{instance_value}->{vserver} . $options{instance_value}->{volume} . $options{instance_value}->{qtree} } > 1 ? '/' . $options{instance_value}->{index} : ''
);
}
sub custom_space_usage_perfdata {
my ($self, %options) = @_;
my $instances = [$self->{result_values}->{volume}];
unshift @$instances, $self->{result_values}->{vserver} if ($self->{result_values}->{vserver} ne '');
push @$instances, $self->{result_values}->{qtree} if ($self->{result_values}->{qtree} ne '');
push @$instances, $self->{result_values}->{index}
if ($self->{instance_mode}->{duplicated}->{ $self->{result_values}->{vserver} . $self->{result_values}->{volume} . $self->{result_values}->{qtree} } > 1);
my $warn_label = 'warning-'. $self->{thlabel};
if ($self->{result_values}->{soft_limit} > 0) {
$warn_label = 'warning-' . $self->{thlabel} . '-' . $self->{result_values}->{index};
}
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'B',
instances => $instances,
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => $warn_label),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => $self->{result_values}->{total} > 0 ? $self->{result_values}->{total} : undef
);
}
sub custom_space_usage_free_perfdata {
my ($self, %options) = @_;
my $instances = [$self->{result_values}->{volume}];
unshift @$instances, $self->{result_values}->{vserver} if ($self->{result_values}->{vserver} ne '');
push @$instances, $self->{result_values}->{qtree} if ($self->{result_values}->{qtree} ne '');
push @$instances, $self->{result_values}->{index}
if ($self->{instance_mode}->{duplicated}->{ $self->{result_values}->{vserver} . $self->{result_values}->{volume} . $self->{result_values}->{qtree} } > 1);
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => 'B',
instances => $instances,
value => $self->{result_values}->{free},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => $self->{result_values}->{total}
);
}
sub custom_space_usage_prct_perfdata {
my ($self, %options) = @_;
my $instances = [$self->{result_values}->{volume}];
unshift @$instances, $self->{result_values}->{vserver} if ($self->{result_values}->{vserver} ne '');
push @$instances, $self->{result_values}->{qtree} if ($self->{result_values}->{qtree} ne '');
push @$instances, $self->{result_values}->{index}
if ($self->{instance_mode}->{duplicated}->{ $self->{result_values}->{vserver} . $self->{result_values}->{volume} . $self->{result_values}->{qtree} } > 1);
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
unit => '%',
instances => $instances,
value => sprintf('%.2f', $self->{result_values}->{prct_used}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0, max => 100
);
}
sub custom_space_usage_threshold {
my ($self, %options) = @_;
# the soft_limit override the default warning plugin threshold
my $warn_label = 'warning-'. $self->{thlabel};
if ($self->{result_values}->{soft_limit} > 0) {
$warn_label = 'warning-' . $self->{thlabel} . '-' . $self->{result_values}->{index};
$self->{perfdata}->threshold_validate(label => $warn_label, value => $self->{result_values}->{soft_limit});
}
return $self->{perfdata}->threshold_check(
value => $self->{result_values}->{used}, threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => $warn_label, exit_litteral => 'warning' }
]
);
}
sub custom_space_usage_free_threshold {
my ($self, %options) = @_;
return $self->{perfdata}->threshold_check(
value => $self->{result_values}->{free}, threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
]
);
}
sub custom_space_usage_prct_threshold {
my ($self, %options) = @_;
return $self->{perfdata}->threshold_check(
value => $self->{result_values}->{prct_used}, threshold => [
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' }
]
);
}
sub custom_space_usage_output {
my ($self, %options) = @_;
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my $msg;
if ($self->{result_values}->{total} <= 0) {
$msg = sprintf("used: %s (unlimited)", $total_used_value . " " . $total_used_unit);
} else {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
$msg = sprintf(
"total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
}
return $msg;
}
sub custom_space_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{qtree} = $options{new_datas}->{$self->{instance} . '_qtree'};
$self->{result_values}->{volume} = $options{new_datas}->{$self->{instance} . '_volume'};
$self->{result_values}->{vserver} = $options{new_datas}->{$self->{instance} . '_vserver'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{soft_limit} = $options{new_datas}->{$self->{instance} . '_soft_limit'};
$self->{result_values}->{index} = $options{new_datas}->{$self->{instance} . '_index'};
if ($self->{result_values}->{total} == 0) {
return -10 if ($options{extra_options}->{label} ne 'usage');
return 0;
}
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
# quotas can be over 100%
if ($self->{result_values}->{free} < 0) {
$self->{result_values}->{free} = 0;
$self->{result_values}->{prct_free} = 0;
}
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'quotas', type => 1, cb_prefix_output => 'prefix_quota_output', message_multiple => 'All quotas are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{quotas} = [
{ label => 'space-usage', nlabel => 'quota.space.usage.bytes', set => {
key_values => [
{ name => 'qtree' }, { name => 'volume' }, { name => 'vserver' },
{ name => 'used' }, { name => 'total' }, { name => 'soft_limit' }, { name => 'index' }
],
closure_custom_calc_extra_options => { label => 'usage' },
closure_custom_calc => $self->can('custom_space_usage_calc'),
closure_custom_output => $self->can('custom_space_usage_output'),
closure_custom_threshold_check => $self->can('custom_space_usage_threshold'),
closure_custom_perfdata => $self->can('custom_space_usage_perfdata')
}
},
{ label => 'space-usage-free', nlabel => 'quota.space.free.bytes', display_ok => 0, set => {
key_values => [
{ name => 'qtree' }, { name => 'volume' }, { name => 'vserver' },
{ name => 'used' }, { name => 'total' }, { name => 'soft_limit' }, { name => 'index' }
],
closure_custom_calc_extra_options => { label => 'free' },
closure_custom_calc => $self->can('custom_space_usage_calc'),
closure_custom_output => $self->can('custom_space_usage_output'),
closure_custom_threshold_check => $self->can('custom_space_usage_free_threshold'),
closure_custom_perfdata => $self->can('custom_space_usage_free_perfdata')
}
},
{ label => 'space-usage-prct', nlabel => 'quota.space.usage.percentage', display_ok => 0, set => {
key_values => [
{ name => 'qtree' }, { name => 'volume' }, { name => 'vserver' },
{ name => 'used' }, { name => 'total' }, { name => 'soft_limit' }, { name => 'index' }
],
closure_custom_calc_extra_options => { label => 'prct' },
closure_custom_calc => $self->can('custom_space_usage_calc'),
closure_custom_output => $self->can('custom_space_usage_output'),
closure_custom_threshold_check => $self->can('custom_space_usage_prct_threshold'),
closure_custom_perfdata => $self->can('custom_space_usage_prct_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-index:s' => { name => 'filter_index' },
'filter-vserver:s' => { name => 'filter_vserver' },
'filter-volume:s' => { name => 'filter_volume' },
'filter-qtree:s' => { name => 'filter_qtree' },
'not-kbytes' => { name => 'not_kbytes' },
'cache' => { name => 'cache' },
'cache-time:s' => { name => 'cache_time', default => 180 }
});
$self->{lcache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{cache})) {
$self->{lcache}->check_options(option_results => $self->{option_results});
}
}
my $mapping_infos = {
qtree => { oid => '.1.3.6.1.4.1.789.1.4.6.1.14' }, # qrV2Tree
volume => { oid => '.1.3.6.1.4.1.789.1.4.6.1.29' }, # qrV2VolumeName
vserver => { oid => '.1.3.6.1.4.1.789.1.4.6.1.30' } # qrV2Vserver
};
my $mapping_datas = {
used => { oid => '.1.3.6.1.4.1.789.1.4.6.1.25' }, # qrV264KBytesUsed
total => { oid => '.1.3.6.1.4.1.789.1.4.6.1.26' }, # qrV264KBytesLimit
threshold => { oid => '.1.3.6.1.4.1.789.1.4.6.1.27' }, # qrV264KBytesThreshold
soft_limit => { oid => '.1.3.6.1.4.1.789.1.4.6.1.28' } # qrV264KBytesSoftLimit
};
sub get_snmp_informations {
my ($self, %options) = @_;
return $options{snmp}->get_multiple_table(
oids => [
{ oid => $mapping_infos->{qtree}->{oid} },
{ oid => $mapping_infos->{volume}->{oid} },
{ oid => $mapping_infos->{vserver}->{oid} }
],
return_type => 1,
nothing_quit => 1
);
}
sub get_informations {
my ($self, %options) = @_;
my $infos;
if (defined($self->{option_results}->{cache})) {
my $has_cache_file = $self->{lcache}->read(statefile => 'netapp_cache_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port());
$infos = $self->{lcache}->get(name => 'infos');
if ($has_cache_file == 0 ||
!defined($infos->{updated}) ||
((time() - $infos->{updated}) > (($self->{option_results}->{cache_time}) * 60))) {
$infos = $self->get_snmp_informations(snmp => $options{snmp});
$self->{lcache}->write(data => { infos => { updated => time(), snmp_result => $infos } });
} else {
$infos = $infos->{snmp_result};
}
} else {
$infos = $self->get_snmp_informations(snmp => $options{snmp});
}
return $infos;
}
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
$self->{duplicated} = {};
my $infos = $self->get_informations(snmp => $options{snmp});
$self->{quotas} = {};
foreach my $oid (keys %$infos) {
next if ($oid !~ /^$mapping_infos->{qtree}->{oid}\.(\d+)\.(\d+)$/);
my $instance = $1 . '.' . $2;
my $index = $2;
my $result = $options{snmp}->map_instance(mapping => $mapping_infos, results => $infos, instance => $instance);
$result->{volume} = '' if (!defined($result->{volume}));
$result->{vserver} = '' if (!defined($result->{vserver}));
next if (defined($self->{option_results}->{filter_index}) && $self->{option_results}->{filter_index} ne '' &&
$index !~ /$self->{option_results}->{filter_index}/);
next if (defined($self->{option_results}->{filter_qtree}) && $self->{option_results}->{filter_qtree} ne '' &&
$result->{qtree} !~ /$self->{option_results}->{filter_qtree}/);
next if ($result->{volume} ne '' && defined($self->{option_results}->{filter_volume}) && $self->{option_results}->{filter_volume} ne '' &&
$result->{volume} !~ /$self->{option_results}->{filter_volume}/);
next if ($result->{vserver} ne '' &&defined($self->{option_results}->{filter_vserver}) && $self->{option_results}->{filter_vserver} ne '' &&
$result->{vserver} !~ /$self->{option_results}->{filter_vserver}/);
my $path = $result->{vserver} . $result->{volume} . $result->{qtree};
$self->{duplicated}->{$path} = 0 if (!defined($self->{duplicated}->{$path}));
$self->{duplicated}->{$path}++;
$self->{quotas}->{$instance} = $result;
$self->{quotas}->{$instance}->{index} = $index;
}
my $multi = 1;
$multi = 1024 unless defined($self->{option_results}->{not_kbytes});
$options{snmp}->load(
oids => [ map($_->{oid}, values(%$mapping_datas)) ],
instances => [ map($_, keys(%{$self->{quotas}})) ],
instance_regexp => '^(.*)$'
);
my $snmp_result = $options{snmp}->get_leef();
foreach my $instance (keys %{$self->{quotas}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping_datas, results => $snmp_result, instance => $instance);
$self->{quotas}->{$instance}->{used} = $result->{used} * $multi;
$self->{quotas}->{$instance}->{total} = $result->{total} * $multi;
# we use the lower limit
$result->{threshold} *= $multi;
my $soft_limit = $result->{soft_limit} * $multi;
if ($result->{threshold} > 0 && ($soft_limit == 0 || $result->{threshold} < $soft_limit)) {
$soft_limit = $result->{threshold};
}
$self->{quotas}->{$instance}->{soft_limit} = $soft_limit;
}
if (scalar(keys %{$self->{quotas}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No quota found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check quotas.
=over 8
=item B<--filter-index>
Filter by index (identified entry in the /etc/quotas) (can be a regexp).
=item B<--filter-vserver>
Filter by vserver name (can be a regexp).
=item B<--filter-volume>
Filter by volume name (can be a regexp).
=item B<--filter-qtree>
Filter by qtree name (can be a regexp).
=item B<--cache>
Use cache file to store quota volume/vserver/qtree information.
=item B<--cache-time>
Time in minutes before reloading cache file (default: 180).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct'.
=item B<--not-kbytes>
If qrV264KBytesUsed and qrV264KBytesLimit OIDs are not really KBytes.
=back
=cut

View File

@ -50,7 +50,7 @@ sub new {
'partnerstatus' => 'storage::netapp::ontap::snmp::mode::partnerstatus',
'plexes' => 'storage::netapp::ontap::snmp::mode::plexes',
'psu' => 'storage::netapp::ontap::snmp::mode::psu',
'qtree-usage' => 'storage::netapp::ontap::snmp::mode::qtreeusage',
'quotas' => 'storage::netapp::ontap::snmp::mode::quotas',
'share-calls' => 'storage::netapp::ontap::snmp::mode::sharecalls',
'shelf' => 'storage::netapp::ontap::snmp::mode::shelf',
'sis' => 'storage::netapp::ontap::snmp::mode::sis',