(plugin) storage::fujitsu::eternus::dx::ssh - use ssh backends (#3967)

* (plugin) storage::fujitsu::eternus::dx::ssh - use ssh backends

* wip
This commit is contained in:
qgarnier 2022-10-07 14:46:13 +02:00 committed by GitHub
parent 659f053768
commit a23791d3f5
8 changed files with 105 additions and 398 deletions

View File

@ -110,7 +110,8 @@ sub execute_command {
command_path => defined($self->{option_results}->{command_path}) && $self->{option_results}->{command_path} ne '' ? $self->{option_results}->{command_path} : $options{command_path},
command_options => $command_options,
timeout => $timeout,
no_quit => $options{no_quit}
no_quit => $options{no_quit},
ssh_pipe => $options{ssh_pipe}
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(

View File

@ -58,40 +58,21 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"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 },
"command:s" => { name => 'command', default => 'show' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => 'performance -type cm' },
"filter-name:s" => { name => 'filter_name' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
}
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "performance -type cm\n",
ssh_pipe => 1
);
# Can have 4 columns also.
#Location Busy Rate(%) Copy Residual Quantity(MB)
@ -131,41 +112,10 @@ __END__
Check CPUs usage.
Command used: show performance -type cm
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'performance -type cm').
=item B<--filter-name>
Filter by name (regexp can be used).

View File

@ -42,7 +42,7 @@ my $thresholds = {
['Broken', 'CRITICAL'],
['Not Exist', 'CRITICAL'],
['Unknown', 'UNKNOWN']
],
]
};
sub new {
@ -51,17 +51,9 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"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 },
"command:s" => { name => 'command', default => 'show' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => 'disks' },
"filter:s@" => { name => 'filter' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"no-component:s" => { name => 'no_component' }
'filter:s@' => { name => 'filter' },
'threshold-overload:s@' => { name => 'threshold_overload' },
'no-component:s' => { name => 'no_component' }
});
$self->{no_components} = undef;
@ -72,10 +64,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
$self->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
@ -110,12 +98,11 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "disks\n",
ssh_pipe => 1
);
#Location Status Size Type Speed(rpm) Usage Health(%)
#------------- ----------------------------- ------- ------------------- ---------- ------------------- ---------
@ -136,17 +123,23 @@ sub run {
$self->{output}->output_add(long_msg => sprintf("Physical Disk '%s' status is '%s'", $disk_name, $disk_status));
my $exit = $self->get_severity(section => 'disk', value => $disk_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Physical Disk '%s' status is '%s'.", $disk_name, $disk_status));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf("Physical Disk '%s' status is '%s'.", $disk_name, $disk_status)
);
}
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %d physical disks are ok.", $total_components));
$self->{output}->output_add(
severity => 'OK',
short_msg => sprintf("All %d physical disks are ok.", $total_components)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No components are checked.');
$self->{output}->output_add(
severity => $self->{no_components},
short_msg => 'No components are checked.'
);
}
$self->{output}->display();
@ -201,41 +194,10 @@ __END__
Check Physical disks.
Command used: show disks
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'disks').
=item B<--filter>
Exclude some parts (comma seperated list)

View File

@ -85,39 +85,19 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"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 },
"command:s" => { name => 'command', default => 'show' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => 'performance -type port' },
"filter-name:s" => { name => 'filter_name' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
}
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "performance -type port\n",
ssh_pipe => 1
);
#Location IOPS(IOPS) Throughput(MB/s)
@ -159,41 +139,10 @@ __END__
Check Port statistics.
Command used: show performance -type port
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'performance -type port').
=item B<--filter-name>
Filter by name (regexp can be used).

View File

@ -45,14 +45,6 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'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 },
'command:s' => { name => 'command', default => 'show' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => 'enclosure-status -type all' },
'filter:s@' => { name => 'filter' },
'threshold-overload:s@' => { name => 'threshold_overload' },
'no-component:s' => { name => 'no_component' }
@ -66,10 +58,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
$self->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
@ -104,13 +92,10 @@ sub check_options {
sub run {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "enclosure-status -type all\n",
ssh_pipe => 1
);
#Controller Enclosure #0 Information
@ -242,41 +227,10 @@ __END__
Check power supplies.
Command used: show enclosure-status -type all
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'enclosure-status -type all').
=item B<--filter>
Exclude some parts (comma seperated list)

View File

@ -32,13 +32,6 @@ sub custom_threshold_output {
return $self->{instance_mode}->get_severity(section => 'rg', value => $self->{result_values}->{status});
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
return 0;
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
@ -86,6 +79,12 @@ sub custom_usage_calc {
return 0;
}
sub prefix_rg_output {
my ($self, %options) = @_;
return "Raid Group '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
@ -96,7 +95,6 @@ sub set_counters {
$self->{maps_counters}->{rg} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' } ],
closure_custom_calc => $self->can('custom_status_calc'),
output_template => 'Status : %s', output_error_template => 'Status : %s',
output_use => 'status',
closure_custom_perfdata => sub { return 0; },
@ -114,29 +112,15 @@ sub set_counters {
];
}
sub prefix_rg_output {
my ($self, %options) = @_;
return "Raid Group '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"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 },
"command:s" => { name => 'command', default => 'show' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => 'raid-groups -csv' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"filter-name:s" => { name => 'filter_name' },
"filter-level:s" => { name => 'filter_level' },
'threshold-overload:s@' => { name => 'threshold_overload' },
'filter-name:s' => { name => 'filter_name' },
'filter-level:s' => { name => 'filter_level' }
});
return $self;
@ -146,10 +130,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
@ -169,13 +149,10 @@ sub check_options {
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "raid-groups -csv\n",
ssh_pipe => 1
);
#[RAID Group No.],[RAID Group Name],[RAID Level],[Assigned CM],[Status],[Total Capacity(MB)],[Free Capacity(MB)]
@ -215,8 +192,8 @@ sub manage_selection {
my $thresholds = {
rg => [
['Available', 'OK'],
['Spare in Use', 'WARNING'],
],
['Spare in Use', 'WARNING']
]
};
sub get_severity {
@ -249,41 +226,10 @@ __END__
Check raid groups.
Command used: show raid-groups -csv
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'raid-groups -csv').
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)

View File

@ -89,7 +89,7 @@ sub set_counters {
key_values => [ { name => 'write_response_time' }, { name => 'display' } ],
output_template => 'Write Response Time : %d ms',
perfdatas => [
{ label => 'write_response_time', value => 'write_response_time', template => '%d',
{ label => 'write_response_time', template => '%d',
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' },
],
}
@ -139,39 +139,19 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'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 },
'command:s' => { name => 'command', default => 'show' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => ' performance -type host-io' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
}
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
ssh_pipe => 1,
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
my ($stdout) = $options{custom}->execute_command(
command => 'show',
command_options => "performance -type host-io\n",
ssh_pipe => 1
);
#Volume IOPS(IOPS) Throughput(MB/s) Response Time(msec.) Processing Time(msec.) Cache Hit Rate(%)
@ -201,6 +181,8 @@ sub manage_selection {
next;
}
next if (/----|Name/i);
next if (/^CLI>/);
my $value = centreon::plugins::misc::trim($_);
my @matches = split(/\s+/, $value);
@ -237,57 +219,19 @@ __END__
=head1 MODE
Check Volume statistics.
Check volume statistics.
Command used: show performance -type host-io
=over 8
=item B<--hostname>
Hostname to query.
=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<--command>
Command to get information (Default: 'show').
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: 'performance -type host-io').
=item B<--filter-name>
Filter by name (regexp can be used).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'read-iops', 'write-iops', 'read-traffic', 'write-traffic',
'read-response-time', 'write-response-time', 'read-processing-time', 'write-processing-time',
'read-cache-hit-rate', 'write-cache-hit-rate'.
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'read-iops', 'write-iops', 'read-traffic', 'write-traffic',
'read-response-time', 'write-response-time', 'read-processing-time', 'write-processing-time',
'read-cache-hit-rate', 'write-cache-hit-rate'.

View File

@ -22,22 +22,23 @@ package storage::fujitsu::eternus::dx::ssh::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
$self->{modes} = {
'cpu' => 'storage::fujitsu::eternus::dx::ssh::mode::cpu',
'physicaldisk' => 'storage::fujitsu::eternus::dx::ssh::mode::physicaldisk',
'port-stats' => 'storage::fujitsu::eternus::dx::ssh::mode::portstats',
'psu' => 'storage::fujitsu::eternus::dx::ssh::mode::psu',
'raid-groups' => 'storage::fujitsu::eternus::dx::ssh::mode::raidgroups',
'volume-stats' => 'storage::fujitsu::eternus::dx::ssh::mode::volumestats',
'cpu' => 'storage::fujitsu::eternus::dx::ssh::mode::cpu',
'port-stats' => 'storage::fujitsu::eternus::dx::ssh::mode::portstats',
);
'volume-stats' => 'storage::fujitsu::eternus::dx::ssh::mode::volumestats'
};
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self;
}