centreon-plugins/os/aix/local/mode/lvsync.pm

174 lines
5.0 KiB
Perl
Raw Normal View History

2014-04-24 14:50:23 +02:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# 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.
#
2014-04-24 14:50:23 +02:00
2014-04-30 11:26:57 +02:00
package os::aix::local::mode::lvsync;
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
use base qw(centreon::plugins::templates::counter);
2014-04-24 14:50:23 +02:00
use strict;
use warnings;
2020-06-02 16:18:36 +02:00
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'state: %s [lp: %s pp: %s pv: %s]',
$self->{result_values}->{state},
$self->{result_values}->{lp},
$self->{result_values}->{pp},
$self->{result_values}->{pv}
);
}
sub prefix_lv_output {
my ($self, %options) = @_;
return sprintf(
"Logical volume '%s' [mount point: %s] ",
$options{instance_value}->{lv},
$options{instance_value}->{mount}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'lvs', type => 1, cb_prefix_output => 'prefix_lv_output', message_multiple => 'All logical volumes are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{lvs} = [
{ label => 'status', threshold => 0, set => {
key_values => [
{ name => 'state' }, { name => 'mount' },
{ name => 'lv' }, { name => 'pp' },
{ name => 'pv' }, { name => 'lp' },
{ name => 'type' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
}
];
};
2014-04-24 14:50:23 +02:00
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
2020-06-02 16:18:36 +02:00
$options{options}->add_options(arguments => {
'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 => '%{state} =~ /stale/i' },
});
2014-04-24 14:50:23 +02:00
$self->{result} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
2020-06-02 16:18:36 +02:00
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
2014-04-24 14:50:23 +02:00
}
sub manage_selection {
my ($self, %options) = @_;
2020-06-02 16:18:36 +02:00
my ($stdout) = $options{custom}->execute_command(
command => 'lsvg',
command_options => '-o | lsvg -i -l 2>&1'
);
$self->{lvs} = {};
2014-04-24 14:50:23 +02:00
my @lines = split /\n/, $stdout;
# Header not needed
shift @lines;
2014-04-30 11:26:57 +02:00
if (scalar @lines != 0){
foreach my $line (@lines) {
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7);
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
2020-06-02 16:18:36 +02:00
$type !~ /$self->{option_results}->{filter_type}/);
next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
$mount !~ /$self->{option_results}->{filter_mount}/);
2014-04-30 11:26:57 +02:00
2020-06-02 16:18:36 +02:00
$self->{lvs}->{$mount} = {
lv => $lv,
mount => $mount,
type => $type,
lp => $lp,
pp => $pp,
pv => $pv,
state => $lvstate
};
2014-04-24 14:50:23 +02:00
}
}
2020-06-02 16:18:36 +02:00
if (scalar(keys %{$self->{lvs}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No logical volumes found.");
$self->{output}->option_exit();
2014-04-24 14:50:23 +02:00
}
}
1;
__END__
=head1 MODE
Check vg mirroring.
2020-06-02 16:18:36 +02:00
Command used: lsvg -o | lsvg -i -l 2>&1
2014-04-24 14:50:23 +02:00
=over 8
2020-06-02 16:18:36 +02:00
=item B<--filter-type>
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
Filter filesystem type (regexp can be used).
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
=item B<--filter-mount>
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
Filter storage mount point (regexp can be used).
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
=item B<--unknown-status>
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
Set unknown threshold for status.
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
=item B<--warning-status>
2014-04-30 11:26:57 +02:00
2020-06-02 16:18:36 +02:00
Set warning threshold for status.
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
2014-04-30 11:26:57 +02:00
2020-06-02 16:18:36 +02:00
=item B<--critical-status>
2014-04-24 14:50:23 +02:00
2020-06-02 16:18:36 +02:00
Set critical threshold for status (Default: '%{state} =~ /stale/i').
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
2014-04-24 14:50:23 +02:00
=back
=cut