(plugin) os::hpux::local - use backend ssh + new mode list-storages (#3705)
This commit is contained in:
parent
f5b3adb6fd
commit
4266841878
|
@ -26,6 +26,12 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use centreon::plugins::misc;
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
|
sub prefix_inodes_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return "Inodes partition '" . $options{instance_value}->{display} . "' ";
|
||||||
|
}
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -38,58 +44,37 @@ sub set_counters {
|
||||||
key_values => [ { name => 'used' }, { name => 'display' } ],
|
key_values => [ { name => 'used' }, { name => 'display' } ],
|
||||||
output_template => 'Used: %s %%',
|
output_template => 'Used: %s %%',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'used', value => 'used', template => '%d',
|
{ label => 'used', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
]
|
||||||
],
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub prefix_inodes_output {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
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);
|
||||||
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' },
|
'name:s' => { name => 'name' },
|
||||||
"remote" => { name => 'remote' },
|
'regexp' => { name => 'use_regexp' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'regexp-isensitive' => { name => 'use_regexpi' }
|
||||||
"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 => 'bdf' },
|
|
||||||
"command-path:s" => { name => 'command_path' },
|
|
||||||
"command-options:s" => { name => 'command_options', default => '-i 2>&1' },
|
|
||||||
"filter-fs:s" => { name => 'filter_fs', },
|
|
||||||
"name:s" => { name => 'name' },
|
|
||||||
"regexp" => { name => 'use_regexp' },
|
|
||||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
|
||||||
});
|
});
|
||||||
$self->{result} = {};
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 => 'bdf',
|
||||||
options => $self->{option_results},
|
command_options => '-i 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
|
no_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{inodes} = {};
|
$self->{inodes} = {};
|
||||||
my @lines = split /\n/, $stdout;
|
my @lines = split /\n/, $stdout;
|
||||||
# Header not needed
|
# Header not needed
|
||||||
|
@ -133,49 +118,10 @@ __END__
|
||||||
|
|
||||||
Check inodes usage on partitions.
|
Check inodes usage on partitions.
|
||||||
|
|
||||||
|
Command used: bdf -i 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: 'bdf').
|
|
||||||
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 2>&1').
|
|
||||||
|
|
||||||
=item B<--warning-usage>
|
=item B<--warning-usage>
|
||||||
|
|
||||||
Threshold warning in percent.
|
Threshold warning in percent.
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
#
|
||||||
|
# Copyright 2022 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::hpux::local::mode::liststorages;
|
||||||
|
|
||||||
|
use base qw(centreon::plugins::mode);
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
$options{options}->add_options(arguments => {});
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
$self->SUPER::init(%options);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($stdout) = $options{custom}->execute_command(
|
||||||
|
command => 'bdf',
|
||||||
|
command_options => '2>&1',
|
||||||
|
no_quit => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
my $results = {};
|
||||||
|
my @lines = split(/\n/, $stdout);
|
||||||
|
# Header not needed
|
||||||
|
shift @lines;
|
||||||
|
while (my $line = shift @lines) {
|
||||||
|
# When the line is too long, the FS name is printed on a separated line
|
||||||
|
if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
|
||||||
|
$line .= " " . shift(@lines);
|
||||||
|
}
|
||||||
|
next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/);
|
||||||
|
my ($fs, $size, $mount) = ($1, $2 * 1024, $6);
|
||||||
|
|
||||||
|
$results->{$mount} = { fs => $fs, size => $size };
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $results = $self->manage_selection(custom => $options{custom});
|
||||||
|
foreach my $name (sort(keys %$results)) {
|
||||||
|
$self->{output}->output_add(
|
||||||
|
long_msg => sprintf(
|
||||||
|
'[name: %s][fs: %s][size: %s]',
|
||||||
|
$name,
|
||||||
|
$results->{$name}->{fs},
|
||||||
|
$results->{$name}->{size}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output}->output_add(
|
||||||
|
severity => 'OK',
|
||||||
|
short_msg => 'List storages:'
|
||||||
|
);
|
||||||
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_format {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{output}->add_disco_format(elements => ['name', 'fs', 'size']);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub disco_show {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $results = $self->manage_selection(custom => $options{custom});
|
||||||
|
foreach my $name (sort(keys %$results)) {
|
||||||
|
$self->{output}->add_disco_entry(
|
||||||
|
name => $name,
|
||||||
|
fs => $results->{$name}->{fs},
|
||||||
|
size => $results->{$name}->{size}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 MODE
|
||||||
|
|
||||||
|
List storages.
|
||||||
|
|
||||||
|
Command used: bdf 2>&1
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=cut
|
|
@ -43,7 +43,8 @@ sub custom_usage_perfdata {
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->perfdata_add(
|
$self->{output}->perfdata_add(
|
||||||
label => $label, unit => 'B',
|
label => $label,
|
||||||
|
unit => 'B',
|
||||||
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
|
||||||
value => $value_perf,
|
value => $value_perf,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
|
||||||
|
@ -72,11 +73,12 @@ sub custom_usage_output {
|
||||||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||||
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
return sprintf(
|
||||||
|
"Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||||
$total_size_value . " " . $total_size_unit,
|
$total_size_value . " " . $total_size_unit,
|
||||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||||
return $msg;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_usage_calc {
|
sub custom_usage_calc {
|
||||||
|
@ -96,6 +98,12 @@ sub custom_usage_calc {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub prefix_disks_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return "Storage '" . $options{instance_value}->{display} . "' ";
|
||||||
|
}
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -115,53 +123,33 @@ sub set_counters {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub prefix_disks_output {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
return "Storage '" . $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);
|
||||||
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' },
|
'units:s' => { name => 'units', default => '%' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'free' => { name => 'free' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'name:s' => { name => 'name' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
'regexp' => { name => 'use_regexp' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'regexp-isensitive' => { name => 'use_regexpi' },
|
||||||
"sudo" => { name => 'sudo' },
|
'space-reservation:s' => { name => 'space_reservation' }
|
||||||
"command:s" => { name => 'command', default => 'bdf' },
|
|
||||||
"command-path:s" => { name => 'command_path' },
|
|
||||||
"command-options:s" => { name => 'command_options', default => ' 2>&1' },
|
|
||||||
"filter-fs:s" => { name => 'filter_fs', },
|
|
||||||
"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;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 => 'bdf',
|
||||||
options => $self->{option_results},
|
command_options => '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
|
no_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{disks} = {};
|
$self->{disks} = {};
|
||||||
my @lines = split /\n/, $stdout;
|
my @lines = split /\n/, $stdout;
|
||||||
# Header not needed
|
# Header not needed
|
||||||
|
@ -169,7 +157,7 @@ sub manage_selection {
|
||||||
while (my $line = shift @lines) {
|
while (my $line = shift @lines) {
|
||||||
# When the line is too long, the FS name is printed on a separated line
|
# When the line is too long, the FS name is printed on a separated line
|
||||||
if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
|
if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
|
||||||
$line .= " ".shift @lines;
|
$line .= " " . shift(@lines);
|
||||||
}
|
}
|
||||||
next if ($line !~ /^(\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+)/);
|
||||||
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);
|
||||||
|
@ -208,49 +196,10 @@ __END__
|
||||||
|
|
||||||
Check storage usages.
|
Check storage usages.
|
||||||
|
|
||||||
|
Command used: bdf 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: 'bdf').
|
|
||||||
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: ' 2>&1').
|
|
||||||
|
|
||||||
=item B<--warning-usage>
|
=item B<--warning-usage>
|
||||||
|
|
||||||
Threshold warning.
|
Threshold warning.
|
||||||
|
|
|
@ -22,19 +22,20 @@ package os::hpux::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) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '0.1';
|
$self->{modes} = {
|
||||||
%{$self->{modes}} = (
|
|
||||||
'inodes' => 'os::hpux::local::mode::inodes',
|
'inodes' => 'os::hpux::local::mode::inodes',
|
||||||
'list-storages' => 'os::hpux::local::mode::liststorages',
|
'list-storages' => 'os::hpux::local::mode::liststorages',
|
||||||
'storage' => 'os::hpux::local::mode::storage',
|
'storage' => 'os::hpux::local::mode::storage'
|
||||||
);
|
};
|
||||||
|
|
||||||
|
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue