| 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::solaris::local::mode::vxdisks; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => { |
| 34 |
'skip-vxdisk' => { name => 'skip_vxdisk' }, |
| 35 |
'skip-vxprint' => { name => 'skip_vxprint' }, |
| 36 |
'warning:s' => { name => 'warning' }, |
| 37 |
'critical:s' => { name => 'critical' } |
| 38 |
}); |
| 39 |
|
| 40 |
return $self; |
| 41 |
} |
| 42 |
|
| 43 |
sub check_options { |
| 44 |
my ($self, %options) = @_; |
| 45 |
$self->SUPER::init(%options); |
| 46 |
|
| 47 |
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { |
| 48 |
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); |
| 49 |
$self->{output}->option_exit(); |
| 50 |
} |
| 51 |
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { |
| 52 |
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); |
| 53 |
$self->{output}->option_exit(); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
sub vdisk_execute { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
my ($stdout) = $options{custom}->execute_command( |
| 61 |
command => 'vxdisk', |
| 62 |
command_options => 'list 2>&1', |
| 63 |
command_path => '/usr/sbin' |
| 64 |
); |
| 65 |
|
| 66 |
my $long_msg = $stdout; |
| 67 |
$long_msg =~ s/\|/~/mg; |
| 68 |
$self->{output}->output_add(long_msg => $long_msg); |
| 69 |
|
| 70 |
foreach (split /\n/, $stdout) { |
| 71 |
if (/(failed)/i ) { |
| 72 |
my $status = $1; |
| 73 |
next if (! /\S+\s+\S+\s+(\S+)\s+/); |
| 74 |
$self->{num_errors}++; |
| 75 |
$self->{vxdisks_name} .= ' [' . $1 . '/' . $status . ']'; |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
sub vxprint_execute { |
| 81 |
my ($self, %options) = @_; |
| 82 |
|
| 83 |
my ($stdout) = $options{custom}->execute_command( |
| 84 |
command => 'vxprint', |
| 85 |
command_options => '-Ath 2>&1', |
| 86 |
command_path => '/usr/sbin' |
| 87 |
); |
| 88 |
|
| 89 |
my $long_msg = $stdout; |
| 90 |
$long_msg =~ s/\|/~/mg; |
| 91 |
$self->{output}->output_add(long_msg => $long_msg); |
| 92 |
|
| 93 |
foreach (split /\n/, $stdout) { |
| 94 |
if (/(NODEVICE|FAILING)/i ) { |
| 95 |
my $status = $1; |
| 96 |
next if (! /^\s*\S+\s+(\S+)\s+/); |
| 97 |
$self->{num_errors}++; |
| 98 |
$self->{vxprint_name} .= ' [' . $1 . '/' . $status . ']'; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
sub run { |
| 104 |
my ($self, %options) = @_; |
| 105 |
$self->{num_errors} = 0; |
| 106 |
$self->{vxdisks_name} = ''; |
| 107 |
$self->{vxprint_name} = ''; |
| 108 |
|
| 109 |
if (!defined($self->{option_results}->{skip_vxdisk})) { |
| 110 |
$self->vdisk_execute(custom => $options{custom}); |
| 111 |
} |
| 112 |
if (!defined($self->{option_results}->{skip_vxprint})) { |
| 113 |
$self->vxprint_execute(custom => $options{custom}); |
| 114 |
} |
| 115 |
|
| 116 |
my ($exit_code) = $self->{perfdata}->threshold_check( |
| 117 |
value => $self->{num_errors}, |
| 118 |
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] |
| 119 |
); |
| 120 |
if ($self->{num_errors} > 0) { |
| 121 |
$self->{output}->output_add( |
| 122 |
severity => $exit_code, |
| 123 |
short_msg => sprintf("Problems on some disks:" . $self->{vxdisks_name} . $self->{vxprint_name}) |
| 124 |
); |
| 125 |
} else { |
| 126 |
$self->{output}->output_add( |
| 127 |
severity => 'OK', |
| 128 |
short_msg => "No problems on disks." |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
$self->{output}->display(); |
| 133 |
$self->{output}->exit(); |
| 134 |
} |
| 135 |
|
| 136 |
1; |
| 137 |
|
| 138 |
__END__ |
| 139 |
|
| 140 |
=head1 MODE |
| 141 |
|
| 142 |
Check Veritas disk status. |
| 143 |
|
| 144 |
Command used: '/usr/sbin/vxdisk list 2>&1' and '/usr/sbin/vxprint -Ath 2>&1' |
| 145 |
|
| 146 |
=over 8 |
| 147 |
|
| 148 |
=item B<--warning> |
| 149 |
|
| 150 |
Warning threshold. |
| 151 |
|
| 152 |
=item B<--critical> |
| 153 |
|
| 154 |
Critical threshold. |
| 155 |
|
| 156 |
=item B<--skip-vxdisk> |
| 157 |
|
| 158 |
Skip 'vxdisk' command (not executed). |
| 159 |
|
| 160 |
=item B<--skip-vxprint> |
| 161 |
|
| 162 |
Skip 'vxprint' command (not executed). |
| 163 |
|
| 164 |
|
| 165 |
=back |
| 166 |
|
| 167 |
=cut |