| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package os::aix::local::mode::lvsync; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'state: %s [lp: %s pp: %s pv: %s]', |
| 34 |
$self->{result_values}->{state}, |
| 35 |
$self->{result_values}->{lp}, |
| 36 |
$self->{result_values}->{pp}, |
| 37 |
$self->{result_values}->{pv} |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
sub prefix_lv_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return sprintf( |
| 45 |
"Logical volume '%s' [mount point: %s] ", |
| 46 |
$options{instance_value}->{lv}, |
| 47 |
$options{instance_value}->{mount} |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
sub set_counters { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
$self->{maps_counters_type} = [ |
| 55 |
{ name => 'lvs', type => 1, cb_prefix_output => 'prefix_lv_output', message_multiple => 'All logical volumes are ok', skipped_code => { -10 => 1 } } |
| 56 |
]; |
| 57 |
|
| 58 |
$self->{maps_counters}->{lvs} = [ |
| 59 |
{ label => 'status', type => 2, critical_default => '%{state} =~ /stale/i', set => { |
| 60 |
key_values => [ |
| 61 |
{ name => 'state' }, { name => 'mount' }, |
| 62 |
{ name => 'lv' }, { name => 'pp' }, |
| 63 |
{ name => 'pv' }, { name => 'lp' }, |
| 64 |
{ name => 'type' } |
| 65 |
], |
| 66 |
closure_custom_output => $self->can('custom_status_output'), |
| 67 |
closure_custom_perfdata => sub { return 0; }, |
| 68 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 69 |
} |
| 70 |
} |
| 71 |
]; |
| 72 |
}; |
| 73 |
|
| 74 |
sub new { |
| 75 |
my ($class, %options) = @_; |
| 76 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 77 |
bless $self, $class; |
| 78 |
|
| 79 |
$options{options}->add_options(arguments => { |
| 80 |
'filter-type:s' => { name => 'filter_type' }, |
| 81 |
'filter-mount:s' => { name => 'filter_mount' } |
| 82 |
}); |
| 83 |
|
| 84 |
return $self; |
| 85 |
} |
| 86 |
|
| 87 |
sub manage_selection { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
my ($stdout) = $options{custom}->execute_command( |
| 91 |
command => 'lsvg', |
| 92 |
command_options => '-o | lsvg -i -l 2>&1' |
| 93 |
); |
| 94 |
|
| 95 |
$self->{lvs} = {}; |
| 96 |
my @lines = split /\n/, $stdout; |
| 97 |
# Header not needed |
| 98 |
shift @lines; |
| 99 |
if (scalar @lines != 0){ |
| 100 |
foreach my $line (@lines) { |
| 101 |
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); |
| 102 |
my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7); |
| 103 |
|
| 104 |
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 105 |
$type !~ /$self->{option_results}->{filter_type}/); |
| 106 |
next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' && |
| 107 |
$mount !~ /$self->{option_results}->{filter_mount}/); |
| 108 |
|
| 109 |
$self->{lvs}->{$mount} = { |
| 110 |
lv => $lv, |
| 111 |
mount => $mount, |
| 112 |
type => $type, |
| 113 |
lp => $lp, |
| 114 |
pp => $pp, |
| 115 |
pv => $pv, |
| 116 |
state => $lvstate |
| 117 |
}; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
if (scalar(keys %{$self->{lvs}}) <= 0) { |
| 122 |
$self->{output}->add_option_msg(short_msg => "No logical volumes found."); |
| 123 |
$self->{output}->option_exit(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
1; |
| 128 |
|
| 129 |
__END__ |
| 130 |
|
| 131 |
=head1 MODE |
| 132 |
|
| 133 |
Check vg mirroring. |
| 134 |
Command used: lsvg -o | lsvg -i -l 2>&1 |
| 135 |
|
| 136 |
=over 8 |
| 137 |
|
| 138 |
=item B<--filter-type> |
| 139 |
|
| 140 |
Filter filesystem type (regexp can be used). |
| 141 |
|
| 142 |
=item B<--filter-mount> |
| 143 |
|
| 144 |
Filter storage mount point (regexp can be used). |
| 145 |
|
| 146 |
=item B<--unknown-status> |
| 147 |
|
| 148 |
Define the conditions to match for the status to be UNKNOWN. |
| 149 |
You can use the following variables: %{state}, %{lv}, %{mount}, %{type}. |
| 150 |
|
| 151 |
=item B<--warning-status> |
| 152 |
|
| 153 |
Define the conditions to match for the status to be WARNING. |
| 154 |
You can use the following variables: %{state}, %{lv}, %{mount}, %{type}. |
| 155 |
|
| 156 |
=item B<--critical-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /stale/i'). |
| 159 |
You can use the following variables: %{state}, %{lv}, %{mount}, %{type}. |
| 160 |
|
| 161 |
=back |
| 162 |
|
| 163 |
=cut |