Fix #2007: break changes

This commit is contained in:
garnier-quentin 2020-06-02 16:18:36 +02:00
parent 0f0e06ffd4
commit d014632380
9 changed files with 531 additions and 726 deletions

View File

@ -0,0 +1,170 @@
#
# 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 os::aix::local::custom::cli;
use strict;
use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'timeout:s' => { name => 'timeout', default => 45 },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' },
'sudo:s' => { name => 'sudo' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{ssh} = centreon::plugins::ssh->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
return 0;
}
sub execute_command {
my ($self, %options) = @_;
my ($stdout, $exit_code);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout, $exit_code) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : $options{command_options},
timeout => $self->{option_results}->{timeout},
no_quit => $options{no_quit}
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
sudo => $self->{option_results}->{sudo},
options => { timeout => $self->{option_results}->{timeout} },
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : $options{command_options},
no_quit => $options{no_quit}
);
}
$self->{output}->output_add(long_msg => "command response: $stdout", debug => 1);
return ($stdout, $exit_code);
}
1;
__END__
=head1 NAME
ssh
=head1 SYNOPSIS
my ssh
=head1 CLI OPTIONS
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 45).
=item B<--command>
Command to get information. Used it you have output in a file.
=item B<--command-path>
Command path.
=item B<--command-options>
Command options.
=item B<--sudo>
sudo command.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -24,41 +24,33 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' }, 'exec-command:s' => { name => 'exec_command' },
'remote' => { name => 'remote' }, 'exec-command-path:s' => { name => 'exec_command_path' },
'ssh-option:s@' => { name => 'ssh_option' }, 'exec-command-options:s' => { name => 'exec_command_options' },
'ssh-path:s' => { name => 'ssh_path' }, 'manage-returns:s' => { name => 'manage_returns', default => '' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'separator:s' => { name => 'separator', default => '#' }
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' },
'manage-returns:s' => { name => 'manage_returns', default => '' },
'separator:s' => { name => 'separator', default => '#' },
}); });
$self->{manage_returns} = {};
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (!defined($self->{option_results}->{command})) { if (!defined($self->{option_results}->{exec_command})) {
$self->{output}->add_option_msg(short_msg => "Need to specify command option."); $self->{output}->add_option_msg(short_msg => "Need to specify exec-command option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{manage_returns} = {};
foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) { foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
next if (!($entry =~ /(.*?),(.*?),(.*)/)); next if (!($entry =~ /(.*?),(.*?),(.*)/));
next if (!$self->{output}->is_litteral_status(status => $2)); next if (!$self->{output}->is_litteral_status(status => $2));
@ -77,15 +69,13 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout, $exit_code) = centreon::plugins::misc::execute( my ($stdout, $exit_code) = $options{custom}->execute_command(
output => $self->{output}, command => $self->{option_results}->{exec_command},
options => $self->{option_results}, command_path => $self->{option_results}->{exec_command_path},
sudo => $self->{option_results}->{sudo}, command_options => $self->{option_results}->{exec_command_options},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
no_quit => 1 no_quit => 1
); );
my $long_msg = $stdout; my $long_msg = $stdout;
$long_msg =~ s/\|/~/mg; $long_msg =~ s/\|/~/mg;
$self->{output}->output_add(long_msg => $long_msg); $self->{output}->output_add(long_msg => $long_msg);
@ -109,11 +99,11 @@ sub run {
if (defined($exit_code)) { if (defined($exit_code)) {
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'code', nlabel => 'command.exit.code.count',
value => $exit_code value => $exit_code
); );
} }
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -137,44 +127,16 @@ Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command prob
Set the separator used in --manage-returns (default : #) Set the separator used in --manage-returns (default : #)
=item B<--remote> =item B<--exec-command>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to test (Default: none). Command to test (Default: none).
You can use 'sh' to use '&&' or '||'. You can use 'sh' to use '&&' or '||'.
=item B<--command-path> =item B<--exec-command-path>
Command path (Default: none). Command path (Default: none).
=item B<--command-options> =item B<--exec-command-options>
Command options (Default: none). Command options (Default: none).

View File

@ -24,24 +24,13 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'errpt' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '' },
'error-type:s' => { name => 'error_type' }, 'error-type:s' => { name => 'error_type' },
'error-class:s' => { name => 'error_class' }, 'error-class:s' => { name => 'error_class' },
'error-id:s' => { name => 'error_id' }, 'error-id:s' => { name => 'error_id' },
@ -51,16 +40,16 @@ sub new {
'filter-resource:s' => { name => 'filter_resource' }, 'filter-resource:s' => { name => 'filter_resource' },
'filter-id:s' => { name => 'filter_id' }, 'filter-id:s' => { name => 'filter_id' },
'exclude-id:s' => { name => 'exclude_id' }, 'exclude-id:s' => { name => 'exclude_id' },
'format-date' => { name => 'format_date' }, 'format-date' => { name => 'format_date' }
}); });
$self->{result} = {};
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (defined($self->{option_results}->{exclude_id}) && defined($self->{option_results}->{error_id})) { if (defined($self->{option_results}->{exclude_id}) && defined($self->{option_results}->{error_id})) {
$self->{output}->add_option_msg(short_msg => "Please use --error-id OR --exclude-id, these options are mutually exclusives"); $self->{output}->add_option_msg(short_msg => "Please use --error-id OR --exclude-id, these options are mutually exclusives");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -69,8 +58,8 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_options = '';
my $extra_options = '';
if (defined($self->{option_results}->{error_type})){ if (defined($self->{option_results}->{error_type})){
$extra_options .= ' -T '.$self->{option_results}->{error_type}; $extra_options .= ' -T '.$self->{option_results}->{error_type};
} }
@ -88,7 +77,7 @@ sub manage_selection {
if (defined($self->{option_results}->{timezone})){ if (defined($self->{option_results}->{timezone})){
$ENV{TZ} = $self->{option_results}->{timezone}; $ENV{TZ} = $self->{option_results}->{timezone};
} }
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($retention);
$year = $year - 100; $year = $year - 100;
if (length($sec) == 1){ if (length($sec) == 1){
$sec = '0' . $sec; $sec = '0' . $sec;
@ -109,17 +98,13 @@ sub manage_selection {
$retention = $mon . $mday . $hour . $min . $year; $retention = $mon . $mday . $hour . $min . $year;
$extra_options .= ' -s '.$retention; $extra_options .= ' -s '.$retention;
} }
$extra_options .= $self->{option_results}->{command_options};
my $stdout = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'errpt',
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $extra_options command_options => $extra_options
); );
my $results = {};
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header not needed # Header not needed
shift @lines; shift @lines;
@ -127,50 +112,65 @@ sub manage_selection {
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
my ($identifier, $timestamp, $resource_name, $description) = ($1, $2, $5, $6); my ($identifier, $timestamp, $resource_name, $description) = ($1, $2, $5, $6);
$self->{result}->{ $timestamp . '~' . $identifier . '~' . $resource_name } = { description => $description }; $results->{ $timestamp . '~' . $identifier . '~' . $resource_name } = { description => $description };
} }
return $results;
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_message = ''; my $extra_message = '';
if (defined($self->{option_results}->{retention})) { if (defined($self->{option_results}->{retention})) {
$extra_message = ' since ' . $self->{option_results}->{retention} . ' seconds'; $extra_message = ' since ' . $self->{option_results}->{retention} . ' seconds';
} }
$self->manage_selection(); my $results = $self->manage_selection(custom => $options{custom});
$self->{output}->output_add( $self->{output}->output_add(
severity => 'OK', severity => 'OK',
short_msg => sprintf("No error found%s.", $extra_message) short_msg => sprintf("No error found%s.", $extra_message)
); );
my $total_error = 0; my $total_error = 0;
foreach my $errpt_error (sort(keys %{$self->{result}})) { foreach my $errpt_error (sort(keys %$results)) {
my @split_error = split ('~', $errpt_error); my @split_error = split ('~', $errpt_error);
my $timestamp = $split_error[0]; my $timestamp = $split_error[0];
my $identifier = $split_error[1]; my $identifier = $split_error[1];
my $resource_name = $split_error[2]; my $resource_name = $split_error[2];
my $description = $self->{result}->{$errpt_error}->{description}; my $description = $results->{$errpt_error}->{description};
next if (defined($self->{option_results}->{filter_resource}) && $self->{option_results}->{filter_resource} ne '' && next if (defined($self->{option_results}->{filter_resource}) && $self->{option_results}->{filter_resource} ne '' &&
$resource_name !~ /$self->{option_results}->{filter_resource}/); $resource_name !~ /$self->{option_results}->{filter_resource}/);
next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
$identifier !~ /$self->{option_results}->{filter_id}/); $identifier !~ /$self->{option_results}->{filter_id}/);
my $output_date = $split_error[0]; my $output_date = $split_error[0];
if (defined($self->{option_results}->{format_date})) { if (defined($self->{option_results}->{format_date})) {
my ($month, $day, $hour, $minute, $year) = unpack("(A2)*", $output_date); my ($month, $day, $hour, $minute, $year) = unpack("(A2)*", $output_date);
$output_date = sprintf("20%s/%s/%s %s:%s", $year, $month, $day, $hour, $minute); $output_date = sprintf("20%s/%s/%s %s:%s", $year, $month, $day, $hour, $minute);
} }
$total_error++; $total_error++;
if (defined($description)) { if (defined($description)) {
$self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s Description: %s", $identifier, $self->{output}->output_add(
$output_date, $resource_name, $description)); long_msg => sprintf(
"Error '%s' Date: %s ResourceName: %s Description: %s",
$identifier,
$output_date,
$resource_name,
$description
)
);
} else { } else {
$self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier, $self->{output}->output_add(
$output_date, $resource_name)); long_msg => sprintf(
"Error '%s' Date: %s ResourceName: %s",
$identifier,
$output_date,
$resource_name
)
);
} }
} }
@ -192,46 +192,10 @@ __END__
=head1 MODE =head1 MODE
Check errpt messages. Check errpt messages.
Command used: 'errpt' with dynamic options
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'errpt').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--error-type> =item B<--error-type>
Filter error type separated by a coma (INFO, PEND, PERF, PERM, TEMP, UNKN). Filter error type separated by a coma (INFO, PEND, PERF, PERM, TEMP, UNKN).

View File

@ -24,54 +24,40 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All inode partitions are ok' } { name => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All inode partitions are ok' }
]; ];
$self->{maps_counters}->{inodes} = [ $self->{maps_counters}->{inodes} = [
{ label => 'usage', set => { { label => 'usage', nlabel => 'storage.inodes.usage.percentage', set => {
key_values => [ { name => 'used' }, { name => 'display' } ], key_values => [ { name => 'used' } ],
output_template => 'Used: %s %%', output_template => 'used: %s %%',
perfdatas => [ perfdatas => [
{ label => 'used', value => 'used', template => '%d', { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, ]
],
} }
}, }
]; ];
} }
sub prefix_inodes_output { sub prefix_inodes_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Inodes partition '" . $options{instance_value}->{display} . "' "; return "Inodes partition '" . $options{instance_value}->{display} . "' ";
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' }, 'filter-fs:s' => { name => 'filter_fs' },
"remote" => { name => 'remote' }, 'filter-mount:s' => { name => 'filter_mount' }
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'df' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-i -v 2>&1' },
"filter-fs:s" => { name => 'filter_fs', },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
}); });
return $self; return $self;
@ -80,15 +66,11 @@ sub new {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout, $exit_code) = centreon::plugins::misc::execute( my ($stdout, $exit_code) = $options{custom}->execute_command(
output => $self->{output}, command => 'df',
options => $self->{option_results}, command_options => '-i -v 2>&1'
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
no_quit => 1
); );
$self->{inodes} = {}; $self->{inodes} = {};
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header not needed # Header not needed
@ -100,29 +82,21 @@ sub manage_selection {
# #
#Filesystem 512-blocks Free %Used Iused %Iused Mounted on #Filesystem 512-blocks Free %Used Iused %Iused Mounted on
#/dev/hd0 19368 9976 48% 4714 5% / #/dev/hd0 19368 9976 48% 4714 5% /
next if ($line !~ /^(\S+)/); next if ($line !~ /^(\S+)/);
my $fs = $1; my $fs = $1;
next if ($line !~ /(\d+)%\s+([^%]*?)$/); next if ($line !~ /(\d+)%\s+([^%]*?)$/);
my ($ipercent, $mount) = ($1, $2); my ($ipercent, $mount) = ($1, $2);
next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
$fs !~ /$self->{option_results}->{filter_fs}/); $fs !~ /$self->{option_results}->{filter_fs}/);
next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) $mount !~ /$self->{option_results}->{filter_mount}/);
&& $mount !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount ne $self->{option_results}->{name});
$self->{inodes}->{$mount} = { display => $mount, used => $ipercent }; $self->{inodes}->{$mount} = { display => $mount, used => $ipercent };
} }
if (scalar(keys %{$self->{inodes}}) <= 0) { if (scalar(keys %{$self->{inodes}}) <= 0) {
if ($exit_code != 0) {
$self->{output}->output_add(long_msg => "command output:" . $stdout);
}
$self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)"); $self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -135,49 +109,17 @@ __END__
=head1 MODE =head1 MODE
Check inodes usage on partitions. Check inodes usage on partitions.
Command used: df -i -v 2>&1
=over 8 =over 8
=item B<--remote> =item B<--filter-fs>
Execute command remotely in 'ssh'. Filter filesystem (regexp can be used).
=item B<--hostname> =item B<--filter-mount>
Hostname to query (need --remote). Filter mountpoint (regexp can be used).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'df').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-i -v 2>&1').
=item B<--warning-usage> =item B<--warning-usage>
@ -187,22 +129,6 @@ Threshold warning in percent.
Threshold critical in percent. Threshold critical in percent.
=item B<--name>
Set the storage mount point (empty means 'check all storages')
=item B<--regexp>
Allows to use regexp to filter storage mount point (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=item B<--filter-fs>
Filter filesystem (regexp can be used).
=back =back
=cut =cut

View File

@ -24,29 +24,17 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-fs:s' => { name => 'filter_fs' },
"hostname:s" => { name => 'hostname' }, 'filter-mount:s' => { name => 'filter_mount' }
"remote" => { name => 'remote' }, });
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'df' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-P -k 2>&1' },
"filter-fs:s" => { name => 'filter_fs', },
"filter-mount:s" => { name => 'filter_mount', },
});
$self->{result} = {};
return $self; return $self;
} }
@ -58,12 +46,12 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'df',
sudo => $self->{option_results}->{sudo}, command_options => '-P -k 2>&1'
command => $self->{option_results}->{command}, );
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}); my $results = {};
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header not needed # Header not needed
shift @lines; shift @lines;
@ -73,29 +61,39 @@ sub manage_selection {
if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
$fs !~ /$self->{option_results}->{filter_fs}/) { $fs !~ /$self->{option_results}->{filter_fs}/) {
$self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter fs"); $self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter fs", debug => 1);
next; next;
} }
if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' && if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
$mount !~ /$self->{option_results}->{filter_mount}/) { $mount !~ /$self->{option_results}->{filter_mount}/) {
$self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter mount"); $self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter mount", debug => 1);
next; next;
} }
$self->{result}->{$mount} = {fs => $fs}; $results->{$mount} = { fs => $fs };
} }
return $results;
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->manage_selection(); my $results = $self->manage_selection(custom => $options{custom});
foreach my $name (sort(keys %{$self->{result}})) { foreach my $name (sort(keys %$results)) {
$self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . ']'); $self->{output}->output_add(
long_msg => sprintf(
"'%s' [fs = %s]",
$name,
$results->{$name}->{fs}
)
);
} }
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => 'List storages:'); severity => 'OK',
short_msg => 'List storages:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
@ -109,11 +107,12 @@ sub disco_format {
sub disco_show { sub disco_show {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->manage_selection(); my $results = $self->manage_selection(custom => $options{custom});
foreach my $name (sort(keys %{$self->{result}})) { foreach my $name (sort(keys %$results)) {
$self->{output}->add_disco_entry(name => $name, $self->{output}->add_disco_entry(
fs => $self->{result}->{$name}->{fs}, name => $name,
); fs => $results->{$name}->{fs},
);
} }
} }
@ -124,50 +123,10 @@ __END__
=head1 MODE =head1 MODE
List storages. List storages.
Command used: df -P -k 2>&1
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'df').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-P -k 2>&1').
=item B<--filter-fs> =item B<--filter-fs>
Filter filesystem (regexp can be used). Filter filesystem (regexp can be used).

View File

@ -20,53 +20,89 @@
package os::aix::local::mode::lvsync; package os::aix::local::mode::lvsync;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; 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
}
}
];
};
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-type:s' => { name => 'filter_type' },
"hostname:s" => { name => 'hostname' }, 'unknown-status:s' => { name => 'unknown_status', default => '' },
"remote" => { name => 'remote' }, 'warning-status:s' => { name => 'warning_status', default => '' },
"ssh-option:s@" => { name => 'ssh_option' }, 'critical-status:s' => { name => 'critical_status', default => '%{state} =~ /stale/i' },
"ssh-path:s" => { name => 'ssh_path' }, });
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'lsvg' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-o | lsvg -i -l 2>&1' },
"filter-state:s" => { name => 'filter_state', default => 'stale' },
"filter-type:s" => { name => 'filter_type', },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{result} = {}; $self->{result} = {};
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'lsvg',
sudo => $self->{option_results}->{sudo}, command_options => '-o | lsvg -i -l 2>&1'
command => $self->{option_results}->{command}, );
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}); $self->{lvs} = {};
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header not needed # Header not needed
shift @lines; shift @lines;
@ -75,62 +111,27 @@ sub manage_selection {
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); 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); my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7);
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
$lvstate !~ /$self->{option_results}->{filter_state}/);
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$type !~ /$self->{option_results}->{filter_type}/); $type !~ /$self->{option_results}->{filter_type}/);
next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) $mount !~ /$self->{option_results}->{filter_mount}/);
&& $mount !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount ne $self->{option_results}->{name});
$self->{result}->{$mount} = {lv => $lv, type => $type, lp => $lp, pp => $pp, pv => $pv, lvstate => $lvstate}; $self->{lvs}->{$mount} = {
lv => $lv,
mount => $mount,
type => $type,
lp => $lp,
pp => $pp,
pv => $pv,
state => $lvstate
};
} }
} }
}
sub run { if (scalar(keys %{$self->{lvs}}) <= 0) {
my ($self, %options) = @_; $self->{output}->add_option_msg(short_msg => "No logical volumes found.");
$self->{output}->option_exit();
$self->manage_selection();
if (scalar(keys %{$self->{result}}) <= 0) {
$self->{output}->output_add(long_msg => 'All LV are ok.');
$self->{output}->output_add(severity => 'OK',
short_msg => 'All LV are ok.');
} else {
my $num_disk_check = 0;
foreach my $name (sort(keys %{$self->{result}})) {
$num_disk_check++;
my $lv = $self->{result}->{$name}->{lv};
my $type = $self->{result}->{$name}->{type};
my $lp = $self->{result}->{$name}->{lp};
my $pp = $self->{result}->{$name}->{pp};
my $pv = $self->{result}->{$name}->{pv};
my $lvstate = $self->{result}->{$name}->{lvstate};
my $mount = $name;
$self->{output}->output_add(long_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s PP: %s PV: %s]", $lv,
$mount, $lvstate,
$lp, $pp, $pv));
$self->{output}->output_add(severity => 'critical',
short_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s PP: %s PV: %s]", $lv,
$mount, $lvstate,
$lp, $pp, $pv));
}
if ($num_disk_check == 0) {
$self->{output}->add_option_msg(short_msg => "No lv checked.");
$self->{output}->option_exit();
}
} }
$self->{output}->display();
$self->{output}->exit();
} }
1; 1;
@ -140,70 +141,33 @@ __END__
=head1 MODE =head1 MODE
Check vg mirroring. Check vg mirroring.
Command used: lsvg -o | lsvg -i -l 2>&1
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'lsvg').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-o | lsvg -i -l 2>&1').
=item B<--name>
Set the storage mount point (empty means 'check all storages')
=item B<--regexp>
Allows to use regexp to filter storage mount point (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=item B<--filter-state>
Filter filesystem state (Default: stale) (regexp can be used).
=item B<--filter-type> =item B<--filter-type>
Filter filesystem type (regexp can be used). Filter filesystem type (regexp can be used).
=item B<--filter-mount>
Filter storage mount point (regexp can be used).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{state} =~ /stale/i').
Can used special variables like: %{state}, %{lv}, %{mount}, %{type}.
=back =back
=cut =cut

View File

@ -24,19 +24,18 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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);
use centreon::plugins::misc;
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf('Process [command => %s] [arg: %s] [state: %s] [elapsed => %s]', return sprintf(
'Process [command => %s] [arg: %s] [state: %s] [elapsed => %s]',
$self->{result_values}->{cmd}, $self->{result_values}->{cmd},
$self->{result_values}->{args}, $self->{result_values}->{args},
$self->{result_values}->{state}, $self->{result_values}->{state},
$self->{result_values}->{elapsed} $self->{result_values}->{elapsed}
); );
return $msg;
} }
sub set_counters { sub set_counters {
@ -63,9 +62,10 @@ sub set_counters {
$self->{maps_counters}->{alarm} = [ $self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'ppid' }, { name => 'state' }, key_values => [
{ name => 'elapsed' }, { name => 'cmd' }, { name => 'args' } ], { name => 'ppid' }, { name => 'state' },
closure_custom_calc => \&catalog_status_calc, { name => 'elapsed' }, { name => 'cmd' }, { name => 'args' }
],
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold,
@ -80,22 +80,12 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'ps' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1' },
'filter-command:s' => { name => 'filter_command' }, 'filter-command:s' => { name => 'filter_command' },
'filter-arg:s' => { name => 'filter_arg' }, 'filter-arg:s' => { name => 'filter_arg' },
'filter-state:s' => { name => 'filter_state' }, 'filter-state:s' => { name => 'filter_state' },
'filter-ppid:s' => { name => 'filter_ppid' }, 'filter-ppid:s' => { name => 'filter_ppid' },
'warning-status:s' => { name => 'warning_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' }
}); });
return $self; return $self;
@ -147,13 +137,9 @@ sub get_time_seconds {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'ps',
options => $self->{option_results}, command_options => '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1'
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
); );
$self->{alarms}->{global} = { alarm => {} }; $self->{alarms}->{global} = { alarm => {} };
@ -194,51 +180,10 @@ __END__
=head1 MODE =head1 MODE
Check AIX processes. Check AIX processes.
Can filter on commands, arguments and states. Command used: ps -e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'ps').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a 2>&1').
=item B<--filter-command> =item B<--filter-command>
Filter process commands (regexp can be used). Filter process commands (regexp can be used).
@ -269,7 +214,8 @@ Can used special variables like: %{ppid}, %{state}, %{elapsed}, %{cmd}, %{args}
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>
Thresholds. Can be: 'total'. Thresholds.
Can be: 'total'.
=back =back

View File

@ -20,173 +20,144 @@
package os::aix::local::mode::storage; package os::aix::local::mode::storage;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
return sprintf(
'space usage 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_space},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
);
}
sub prefix_storage_output {
my ($self, %options) = @_;
return "Storage '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'storages', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{storages} = [
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
key_values => [
{ name => 'used_space' }, { name => 'free_space' },
{ name => 'prct_used_space' }, { name => 'prct_free_space' },
{ name => 'total_space' }
],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'usage-free', nlabel => 'storage.space.free.bytes', display_ok => 0, set => {
key_values => [
{ name => 'free_space' }, { name => 'used_space' },
{ name => 'prct_used_space' }, { name => 'prct_free_space' },
{ name => 'total_space' }
],
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 }
]
}
},
{ label => 'usage-prct', nlabel => 'storageresource.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used_space' } ],
output_template => 'used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
];
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-fs:s' => { name => 'filter_fs' },
"hostname:s" => { name => 'hostname' }, 'filter-mount:s' => { name => 'filter_mount' },
"remote" => { name => 'remote' }, 'space-reservation:s' => { name => 'space_reservation' }
"ssh-option:s@" => { name => 'ssh_option' }, });
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'df' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-P -k 2>&1' },
"filter-fs:s" => { name => 'filter_fs', },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
"space-reservation:s" => { name => 'space_reservation' },
});
$self->{result} = {};
return $self;
}
sub check_options { return $self;
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'df',
sudo => $self->{option_results}->{sudo}, command_options => '-P -k 2>&1'
command => $self->{option_results}->{command}, );
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}); $self->{storages} = {};
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header not needed # Header not needed
shift @lines; shift @lines;
foreach my $line (@lines) { foreach my $line (@lines) {
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
my ($fs, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6); my ($fs, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6);
next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
$fs !~ /$self->{option_results}->{filter_fs}/); $fs !~ /$self->{option_results}->{filter_fs}/);
next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) $mount !~ /$self->{option_results}->{filter_mount}/);
&& $mount !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount !~ /$self->{option_results}->{name}/);
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $mount ne $self->{option_results}->{name});
next if ($size !~ m/^\d+$/ || $used !~ m/^\d+$/ || $available !~ m/^\d+$/); next if ($size !~ /^\d+$/ || $used !~ /^\d+$/ || $available !~ /^\d+$/);
next if ($size == 0);
$self->{result}->{$mount} = {fs => $fs, total => $size, used => $used, free => $available}; $size = $size * 1024;
} my $reserved_value = 0;
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No storage found for mount point '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No storage found.");
}
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection();
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All storages are ok.');
}
my $num_disk_check = 0;
foreach my $name (sort(keys %{$self->{result}})) {
my $total_size = $self->{result}->{$name}->{total} * 1024;
if (defined($self->{option_results}->{space_reservation})) { if (defined($self->{option_results}->{space_reservation})) {
$total_size = $total_size - ($self->{option_results}->{space_reservation} * $total_size / 100); $reserved_value = $self->{option_results}->{space_reservation} * $size / 100;
} }
next if ($total_size == 0); my $used_space = $used * 1024;
my $free_space = $size - $used_space - $reserved_value;
$num_disk_check++; my $prct_used_space = $used_space * 100 / ($size - $reserved_value);
my $total_used = $self->{result}->{$name}->{used} * 1024; my $prct_free_space = 100 - $prct_used_space;
my $total_free = $self->{result}->{$name}->{free} * 1024; # limit to 100. Better output.
my $prct_used = $total_used * 100 / $total_size; if ($prct_used_space > 100) {
my $prct_free = 100 - $prct_used; $free_space = 0;
$prct_used_space = 100;
my ($exit, $threshold_value); $prct_free_space = 0;
$threshold_value = $total_used;
$threshold_value = $total_free if (defined($self->{option_results}->{free}));
if ($self->{option_results}->{units} eq '%') {
$threshold_value = $prct_used;
$threshold_value = $prct_free if (defined($self->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size);
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used);
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $total_used));
$self->{output}->output_add(long_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name,
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $prct_used,
$total_free_value . " " . $total_free_unit, $prct_free));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name,
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $prct_used,
$total_free_value . " " . $total_free_unit, $prct_free));
}
my $label = 'used';
my $value_perf = $total_used;
if (defined($self->{option_results}->{free})) {
$label = 'free';
$value_perf = $total_free;
} }
my $extra_label = '';
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); $self->{storages}->{$mount} = {
my %total_options = (); display => $mount,
if ($self->{option_results}->{units} eq '%') { total_space => $size,
$total_options{total} = $total_size; used_space => $used_space,
$total_options{cast_int} = 1; free_space => $free_space,
} prct_used_space => $prct_used_space,
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', prct_free_space => $prct_free_space
value => $value_perf, };
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options),
min => 0, max => $total_size);
} }
if ($num_disk_check == 0) { if (scalar(keys %{$self->{storages}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage checked."); $self->{output}->add_option_msg(short_msg => "No storage found.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{output}->display();
$self->{output}->exit();
} }
1; 1;
@ -196,87 +167,28 @@ __END__
=head1 MODE =head1 MODE
Check storage usages. Check storage usages.
Command used: df -P -k 2>&1
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'df').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-P -k 2>&1').
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--free>
Thresholds are on free space left.
=item B<--name>
Set the storage mount point (empty means 'check all storages')
=item B<--regexp>
Allows to use regexp to filter storage mount point (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=item B<--filter-fs> =item B<--filter-fs>
Filter filesystem (regexp can be used). Filter filesystem (regexp can be used).
=item B<--filter-mount>
Filter mountpoint (regexp can be used).
=item B<--space-reservation> =item B<--space-reservation>
Some filesystem has space reserved (like ext4 for root). Some filesystem has space reserved (like ext4 for root).
The value is in percent of total (Default: none). The value is in percent of total (Default: none).
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
=back =back
=cut =cut

View File

@ -22,7 +22,7 @@ package os::aix::local::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -30,15 +30,17 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( $self->{modes} = {
'cmd-return' => 'os::aix::local::mode::cmdreturn', 'cmd-return' => 'os::aix::local::mode::cmdreturn',
'errpt' => 'os::aix::local::mode::errpt', 'errpt' => 'os::aix::local::mode::errpt',
'inodes' => 'os::aix::local::mode::inodes', 'inodes' => 'os::aix::local::mode::inodes',
'list-storages' => 'os::aix::local::mode::liststorages', 'list-storages' => 'os::aix::local::mode::liststorages',
'lvsync' => 'os::aix::local::mode::lvsync', 'lvsync' => 'os::aix::local::mode::lvsync',
'process' => 'os::aix::local::mode::process', 'process' => 'os::aix::local::mode::process',
'storage' => 'os::aix::local::mode::storage', 'storage' => 'os::aix::local::mode::storage'
); };
$self->{custom_modes}->{cli} = 'os::aix::local::custom::cli';
return $self; return $self;
} }