mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 15:44:21 +02:00
wip ssh backend system + indent
This commit is contained in:
parent
54bdbbeb5e
commit
a7b5399d0e
@ -39,16 +39,15 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($options{noptions})) {
|
if (!defined($options{noptions})) {
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'hostname:s@' => { name => 'hostname' },
|
||||||
"hostname:s@" => { name => 'hostname' },
|
'port:s@' => { name => 'port' },
|
||||||
"port:s@" => { name => 'port' },
|
'timeout:s@' => { name => 'timeout' },
|
||||||
"timeout:s@" => { name => 'timeout' },
|
'ssh-username:s@' => { name => 'ssh_username' },
|
||||||
"ssh-username:s@" => { name => 'ssh_username' },
|
'ssh-password:s@' => { name => 'ssh_password' },
|
||||||
"ssh-password:s@" => { name => 'ssh_password' },
|
'ssh-dir:s@' => { name => 'ssh_dir' },
|
||||||
"ssh-dir:s@" => { name => 'ssh_dir' },
|
'ssh-identity:s@' => { name => 'ssh_identity' },
|
||||||
"ssh-identity:s@" => { name => 'ssh_identity' },
|
'ssh-skip-serverkey-issue' => { name => 'ssh_skip_serverkey_issue' },
|
||||||
"ssh-skip-serverkey-issue" => { name => 'ssh_skip_serverkey_issue' },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1);
|
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1);
|
||||||
|
127
centreon/plugins/backend/ssh/plink.pm
Normal file
127
centreon/plugins/backend/ssh/plink.pm
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#
|
||||||
|
# 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 centreon::plugins::backend::ssh::plink;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = {};
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
if (!defined($options{noptions}) || $options{noptions} != 1) {
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
'plink-command:s' => { name => 'plink_command', default => 'plink' },
|
||||||
|
'plink-path:s' => { name => 'plink_path' },
|
||||||
|
'plink-option:s@' => { name => 'plink_option' }
|
||||||
|
});
|
||||||
|
$options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND PLINK OPTIONS', once => 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output} = $options{output};
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{ssh_command} = defined($options{option_results}->{plink_command}) && $options{option_results}->{plink_command} ne '' ?
|
||||||
|
$options{option_results}->{plink_command} : 'plink';
|
||||||
|
$self->{ssh_path} = $options{option_results}->{sshcli_path};
|
||||||
|
$self->{ssh_option} = defined($options{option_results}->{plink_option}) ? $options{option_results}->{plink_option} : [];
|
||||||
|
$self->{ssh_port} = defined($options{option_results}->{ssh_port}) && $options{option_results}->{ssh_port} =~ /(\d+)/ ? $1 : 22;
|
||||||
|
$self->{ssh_priv_key} = $options{option_results}->{ssh_priv_key};
|
||||||
|
$self->{ssh_username} = $options{option_results}->{ssh_username};
|
||||||
|
$self->{ssh_password} = $options{option_results}->{ssh_password};
|
||||||
|
|
||||||
|
push @{$self->{ssh_option}}, '-batch';
|
||||||
|
push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne '');
|
||||||
|
push @{$self->{ssh_option}}, '-pw=' . $self->{ssh_password} if (defined($self->{ssh_password}) && $self->{ssh_password} ne '');
|
||||||
|
push @{$self->{ssh_option}}, '-P=' . $self->{ssh_port} if (defined($self->{ssh_port}) && $self->{ssh_port} ne '');
|
||||||
|
push @{$self->{ssh_option}}, '-i=' . $self->{ssh_priv_key} if (defined($self->{ssh_priv_key}) && $self->{ssh_priv_key} ne '');
|
||||||
|
}
|
||||||
|
|
||||||
|
sub execute {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($content, $exit_code) = centreon::plugins::misc::execute(
|
||||||
|
output => $self->{output},
|
||||||
|
sudo => $options{sudo},
|
||||||
|
command => $options{command},
|
||||||
|
command_path => $options{command_path},
|
||||||
|
command_options => $options{command_options},
|
||||||
|
options => {
|
||||||
|
remote => 1,
|
||||||
|
ssh_address => $options{hostname},
|
||||||
|
ssh_command => $self->{ssh_command},
|
||||||
|
ssh_path => $self->{ssh_path},
|
||||||
|
ssh_option => $self->{ssh_option},
|
||||||
|
ssh_pipe => $options{ssh_pipe},
|
||||||
|
timeout => $options{timeout}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# plink exit code is 0 even connection is abandoned
|
||||||
|
if ($content =~ /server.*?key fingerprint.*connection abandoned/msi) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'please connect with plink command to your host and accept the server host key');
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($content, $exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
plink backend.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
plink backend.
|
||||||
|
|
||||||
|
=head1 BACKEND PLINK OPTIONS
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--plink-command>
|
||||||
|
|
||||||
|
plink command (default: 'plink').
|
||||||
|
|
||||||
|
=item B<--plink-path>
|
||||||
|
|
||||||
|
plink command path (default: none)
|
||||||
|
|
||||||
|
=item B<--plink-option>
|
||||||
|
|
||||||
|
Specify plink options (example: --plink-option='-T').
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
B<sshcli>.
|
||||||
|
|
||||||
|
=cut
|
123
centreon/plugins/backend/ssh/sshcli.pm
Normal file
123
centreon/plugins/backend/ssh/sshcli.pm
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
#
|
||||||
|
# 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 centreon::plugins::backend::ssh::sshcli;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use centreon::plugins::misc;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = {};
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
if (!defined($options{noptions}) || $options{noptions} != 1) {
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
'sshcli-command:s' => { name => 'sshcli_command', default => 'ssh' },
|
||||||
|
'sshcli-path:s' => { name => 'sshcli_path' },
|
||||||
|
'sslcli-option:s@' => { name => 'sshcli_option' }
|
||||||
|
});
|
||||||
|
$options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND SSHCLI OPTIONS', once => 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{output} = $options{output};
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{ssh_command} = defined($options{option_results}->{sshcli_command}) && $options{option_results}->{sshcli_command} ne '' ?
|
||||||
|
$options{option_results}->{sshcli_command} : 'ssh';
|
||||||
|
$self->{ssh_path} = $options{option_results}->{sshcli_path};
|
||||||
|
$self->{ssh_option} = defined($options{option_results}->{sshcli_option}) ? $options{option_results}->{sshcli_option} : [];
|
||||||
|
$self->{ssh_port} = defined($options{option_results}->{ssh_port}) && $options{option_results}->{ssh_port} =~ /(\d+)/ ? $1 : 22;
|
||||||
|
$self->{ssh_priv_key} = $options{option_results}->{ssh_priv_key};
|
||||||
|
$self->{ssh_username} = $options{option_results}->{ssh_username};
|
||||||
|
if (defined($options{option_results}->{ssh_password}) && $options{option_results}->{ssh_password} ne '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'sshcli backend cannot use ssh password. please use backend plink or libssh');
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
push @{$self->{ssh_option}}, '-o=BatchMode yes';
|
||||||
|
push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne '');
|
||||||
|
push @{$self->{ssh_option}}, '-p=' . $self->{ssh_port} if (defined($self->{ssh_port}) && $self->{ssh_port} ne '');
|
||||||
|
push @{$self->{ssh_option}}, '-i=' . $self->{ssh_priv_key} if (defined($self->{ssh_priv_key}) && $self->{ssh_priv_key} ne '');
|
||||||
|
}
|
||||||
|
|
||||||
|
sub execute {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($content, $exit_code) = centreon::plugins::misc::execute(
|
||||||
|
output => $self->{output},
|
||||||
|
sudo => $options{sudo},
|
||||||
|
command => $options{command},
|
||||||
|
command_path => $options{command_path},
|
||||||
|
command_options => $options{command_options},
|
||||||
|
options => {
|
||||||
|
remote => 1,
|
||||||
|
ssh_address => $options{hostname},
|
||||||
|
ssh_command => $self->{ssh_command},
|
||||||
|
ssh_path => $self->{ssh_path},
|
||||||
|
ssh_option => $self->{ssh_option},
|
||||||
|
ssh_pipe => $options{ssh_pipe},
|
||||||
|
timeout => $options{timeout}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return ($content, $exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
ssh cli backend.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
ssh cli backend.
|
||||||
|
|
||||||
|
=head1 BACKEND SSHCLI OPTIONS
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--sshcli-command>
|
||||||
|
|
||||||
|
ssh command (default: 'ssh').
|
||||||
|
|
||||||
|
=item B<--sshcli-path>
|
||||||
|
|
||||||
|
ssh command path (default: none)
|
||||||
|
|
||||||
|
=item B<--sshcli-option>
|
||||||
|
|
||||||
|
Specify ssh cli options (example: --sshcli-option='-o=StrictHostKeyChecking=no').
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
B<sshcli>.
|
||||||
|
|
||||||
|
=cut
|
@ -44,10 +44,14 @@ sub windows_execute {
|
|||||||
$cmd .= $options{command} . ' ' if (defined($options{command}));
|
$cmd .= $options{command} . ' ' if (defined($options{command}));
|
||||||
$cmd .= $options{command_options} if (defined($options{command_options}));
|
$cmd .= $options{command_options} if (defined($options{command_options}));
|
||||||
|
|
||||||
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'Win32::Job',
|
centreon::plugins::misc::mymodule_load(
|
||||||
error_msg => "Cannot load module 'Win32::Job'.");
|
output => $options{output}, module => 'Win32::Job',
|
||||||
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'Time::HiRes',
|
error_msg => "Cannot load module 'Win32::Job'."
|
||||||
error_msg => "Cannot load module 'Time::HiRes'.");
|
);
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
|
output => $options{output}, module => 'Time::HiRes',
|
||||||
|
error_msg => "Cannot load module 'Time::HiRes'."
|
||||||
|
);
|
||||||
|
|
||||||
$| = 1;
|
$| = 1;
|
||||||
pipe FROM_CHILD, TO_PARENT or do {
|
pipe FROM_CHILD, TO_PARENT or do {
|
||||||
@ -135,9 +139,10 @@ sub unix_execute {
|
|||||||
$cmd .= $options{options}->{ssh_command} if (defined($options{options}->{ssh_command}));
|
$cmd .= $options{options}->{ssh_command} if (defined($options{options}->{ssh_command}));
|
||||||
|
|
||||||
foreach (@{$options{options}->{ssh_option}}) {
|
foreach (@{$options{options}->{ssh_option}}) {
|
||||||
my ($lvalue, $rvalue) = split /=/;
|
if (/^(.*?)(?:=(.*))?$/) {
|
||||||
push @$args, $lvalue if (defined($lvalue));
|
push @$args, $1 if (defined($1));
|
||||||
push @$args, $rvalue if (defined($rvalue));
|
push @$args, $2 if (defined($2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($options{options}->{ssh_address}) && $options{options}->{ssh_address} ne '') {
|
if (defined($options{options}->{ssh_address}) && $options{options}->{ssh_address} ne '') {
|
||||||
|
129
centreon/plugins/ssh.pm
Normal file
129
centreon/plugins/ssh.pm
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#
|
||||||
|
# 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 centreon::plugins::ssh;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
|
my $self = {};
|
||||||
|
bless $self, $class;
|
||||||
|
|
||||||
|
if (!defined($options{noptions}) || $options{noptions} != 1) {
|
||||||
|
$options{options}->add_options(arguments => {
|
||||||
|
'ssh-backend:s' => { name => 'ssh_backend', default => 'sshcli' },
|
||||||
|
'ssh-port:s' => { name => 'ssh_port' },
|
||||||
|
'ssh-priv-key:s' => { name => 'ssh_priv_key' },
|
||||||
|
'ssh-username:s' => { name => 'ssh_username' },
|
||||||
|
'ssh-password:s' => { name => 'ssh_password' }
|
||||||
|
});
|
||||||
|
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH GLOBAL OPTIONS');
|
||||||
|
}
|
||||||
|
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
|
output => $options{output},
|
||||||
|
module => 'centreon::plugins::backend::ssh::sshcli',
|
||||||
|
error_msg => "Cannot load module 'centreon::plugins::backend::ssh::sshcli'."
|
||||||
|
);
|
||||||
|
$self->{backend_sshcli} = centreon::plugins::backend::ssh::sshcli->new(%options);
|
||||||
|
|
||||||
|
centreon::plugins::misc::mymodule_load(
|
||||||
|
output => $options{output},
|
||||||
|
module => 'centreon::plugins::backend::ssh::plink',
|
||||||
|
error_msg => "Cannot load module 'centreon::plugins::backend::ssh::plink'."
|
||||||
|
);
|
||||||
|
$self->{backend_plink} = centreon::plugins::backend::ssh::plink->new(%options);
|
||||||
|
|
||||||
|
$self->{output} = $options{output};
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_options {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
$self->{ssh_backend} = $options{option_results}->{ssh_backend};
|
||||||
|
$self->{ssh_port} = defined($options{option_results}->{ssh_port}) && $options{option_results}->{ssh_port} =~ /(\d+)/ ? $1 : 22;
|
||||||
|
$self->{ssh_backend} = 'sshcli'
|
||||||
|
if (!defined($options{option_results}->{ssh_backend}) || $options{option_results}->{ssh_backend} eq '');
|
||||||
|
if (!defined($self->{'backend_' . $self->{ssh_backend}})) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'unknown ssh backend: ' . $self->{ssh_backend});
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
$self->{'backend_' . $self->{ssh_backend}}->check_options(%options);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_port {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $self->{ssh_port};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub execute {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $self->{'backend_' . $self->{ssh_backend}}->execute(%options);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
SSH abstraction layer.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
SSH abstraction layer for sscli, plink and libssh backends
|
||||||
|
|
||||||
|
=head1 SSH GLOBAL OPTIONS
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--ssh-backend>
|
||||||
|
|
||||||
|
Set the backend used (Default: 'sshcli')
|
||||||
|
Can be: sshcli, plink, libssh.
|
||||||
|
|
||||||
|
=item B<--ssh-username>
|
||||||
|
|
||||||
|
Connect with specified username.
|
||||||
|
|
||||||
|
=item B<--ssh-password>
|
||||||
|
|
||||||
|
Login with specified password. Cannot be used with sshcli backend.
|
||||||
|
|
||||||
|
=item B<--ssh-port>
|
||||||
|
|
||||||
|
Connect to specified port.
|
||||||
|
|
||||||
|
=item B<--ssh-priv-key>
|
||||||
|
|
||||||
|
Private key file for user authentication.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
B<ssh>.
|
||||||
|
|
||||||
|
=cut
|
@ -80,11 +80,16 @@ sub check_options {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Redis',
|
centreon::plugins::misc::mymodule_load(
|
||||||
error_msg => "Cannot load module 'Redis'.");
|
output => $self->{output},
|
||||||
|
module => 'Redis',
|
||||||
|
error_msg => "Cannot load module 'Redis'."
|
||||||
|
);
|
||||||
eval {
|
eval {
|
||||||
$self->{redis_cnx} = Redis->new(server => $options{option_results}->{redis_server},
|
$self->{redis_cnx} = Redis->new(
|
||||||
eval $self->{redis_attributes});
|
server => $options{option_results}->{redis_server},
|
||||||
|
eval $self->{redis_attributes}
|
||||||
|
);
|
||||||
if (defined($self->{redis_cnx}) &&
|
if (defined($self->{redis_cnx}) &&
|
||||||
defined($options{option_results}->{redis_db}) &&
|
defined($options{option_results}->{redis_db}) &&
|
||||||
$options{option_results}->{redis_db} ne ''
|
$options{option_results}->{redis_db} ne ''
|
||||||
@ -96,13 +101,19 @@ sub check_options {
|
|||||||
|
|
||||||
$self->{statefile_dir} = $options{option_results}->{statefile_dir};
|
$self->{statefile_dir} = $options{option_results}->{statefile_dir};
|
||||||
if ($self->{statefile_dir} ne $default_dir && defined($options{option_results}->{statefile_concat_cwd})) {
|
if ($self->{statefile_dir} ne $default_dir && defined($options{option_results}->{statefile_concat_cwd})) {
|
||||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Cwd',
|
centreon::plugins::misc::mymodule_load(
|
||||||
error_msg => "Cannot load module 'Cwd'.");
|
output => $self->{output},
|
||||||
|
module => 'Cwd',
|
||||||
|
error_msg => "Cannot load module 'Cwd'."
|
||||||
|
);
|
||||||
$self->{statefile_dir} = Cwd::cwd() . '/' . $self->{statefile_dir};
|
$self->{statefile_dir} = Cwd::cwd() . '/' . $self->{statefile_dir};
|
||||||
}
|
}
|
||||||
if (defined($options{option_results}->{statefile_storable})) {
|
if (defined($options{option_results}->{statefile_storable})) {
|
||||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Storable',
|
centreon::plugins::misc::mymodule_load(
|
||||||
error_msg => "Cannot load module 'Storable'.");
|
output => $self->{output},
|
||||||
|
module => 'Storable',
|
||||||
|
error_msg => "Cannot load module 'Storable'."
|
||||||
|
);
|
||||||
$self->{storable} = 1;
|
$self->{storable} = 1;
|
||||||
}
|
}
|
||||||
$self->{statefile_suffix} = $options{option_results}->{statefile_suffix};
|
$self->{statefile_suffix} = $options{option_results}->{statefile_suffix};
|
||||||
@ -227,15 +238,19 @@ sub write {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if ($self->{memcached_ok} == 1) {
|
if ($self->{memcached_ok} == 1) {
|
||||||
Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . '/' . $self->{statefile},
|
Memcached::libmemcached::memcached_set(
|
||||||
Data::Dumper->Dump([$options{data}], ['datas']), $self->{memexpiration});
|
$self->{memcached}, $self->{statefile_dir} . '/' . $self->{statefile},
|
||||||
|
Data::Dumper->Dump([$options{data}], ['datas']), $self->{memexpiration}
|
||||||
|
);
|
||||||
if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS$/i) {
|
if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS$/i) {
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (defined($self->{redis_cnx})) {
|
if (defined($self->{redis_cnx})) {
|
||||||
return if (defined($self->{redis_cnx}->set($self->{statefile_dir} . '/' . $self->{statefile}, Data::Dumper->Dump([$options{data}], ['datas']),
|
return if (defined($self->{redis_cnx}->set(
|
||||||
'EX', $self->{memexpiration})));
|
$self->{statefile_dir} . '/' . $self->{statefile}, Data::Dumper->Dump([$options{data}], ['datas']),
|
||||||
|
'EX', $self->{memexpiration}))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
open FILE, '>', $self->{statefile_dir} . '/' . $self->{statefile};
|
open FILE, '>', $self->{statefile_dir} . '/' . $self->{statefile};
|
||||||
if ($self->{storable} == 1) {
|
if ($self->{storable} == 1) {
|
||||||
|
190
storage/ibm/storwize/ssh/custom/api.pm
Normal file
190
storage/ibm/storwize/ssh/custom/api.pm
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
#
|
||||||
|
# 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 storage::ibm::storwize::ssh::custom::api;
|
||||||
|
|
||||||
|
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 => 30 },
|
||||||
|
'sudo' => { name => 'sudo' },
|
||||||
|
'command:s' => { name => 'command' },
|
||||||
|
'command-path:s' => { name => 'command_path' },
|
||||||
|
'command-options:s' => { name => 'command_options' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
$options{options}->add_help(package => __PACKAGE__, sections => 'STORWIZE 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 get_hasharray {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $result = [];
|
||||||
|
return $result if ($options{content} eq '');
|
||||||
|
my ($header, @lines) = split /\n/, $options{content};
|
||||||
|
my @header_names = split /$options{delim}/, $header;
|
||||||
|
|
||||||
|
for (my $i = 0; $i <= $#lines; $i++) {
|
||||||
|
my @content = split /$options{delim}/, $lines[$i];
|
||||||
|
my $data = {};
|
||||||
|
for (my $j = 0; $j <= $#header_names; $j++) {
|
||||||
|
$data->{$header_names[$j]} = $content[$j];
|
||||||
|
}
|
||||||
|
push @$result, $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub execute_command {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $content;
|
||||||
|
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
|
||||||
|
($content) = $self->{ssh}->execute(
|
||||||
|
hostname => $self->{option_results}->{hostname},
|
||||||
|
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} : undef,
|
||||||
|
timeout => $self->{option_results}->{timeout},
|
||||||
|
sudo => $self->{option_results}->{sudo}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') {
|
||||||
|
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command)');
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
($content) = centreon::plugins::misc::execute(
|
||||||
|
output => $self->{output},
|
||||||
|
options => { timeout => $self->{option_results}->{timeout} },
|
||||||
|
sudo => $self->{option_results}->{sudo},
|
||||||
|
command => $self->{option_results}->{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} : undef
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
storwize
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
storwize
|
||||||
|
|
||||||
|
=head1 STORWIZE OPTIONS
|
||||||
|
|
||||||
|
=over 8
|
||||||
|
|
||||||
|
=item B<--hostname>
|
||||||
|
|
||||||
|
Hostname to query.
|
||||||
|
|
||||||
|
=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. Used it you have output in a file.
|
||||||
|
|
||||||
|
=item B<--command-path>
|
||||||
|
|
||||||
|
Command path.
|
||||||
|
|
||||||
|
=item B<--command-options>
|
||||||
|
|
||||||
|
Command options.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
B<custom>.
|
||||||
|
|
||||||
|
=cut
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsarray==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsarray==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'array', instance => $_->{mdisk_id}));
|
next if ($self->check_filter(section => 'array', instance => $_->{mdisk_id}));
|
||||||
$self->{components}->{array}->{total}++;
|
$self->{components}->{array}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("array '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{mdisk_name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"array '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{mdisk_name},
|
||||||
|
$_->{status},
|
||||||
$_->{mdisk_id}
|
$_->{mdisk_id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'array', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'array', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Array '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{mdisk_name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Array '%s' status is '%s'",
|
||||||
|
$_->{mdisk_name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,28 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsdrive==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsdrive==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'drive', instance => $_->{id}));
|
next if ($self->check_filter(section => 'drive', instance => $_->{id}));
|
||||||
$self->{components}->{drive}->{total}++;
|
$self->{components}->{drive}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("drive '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
|
long_msg => sprintf(
|
||||||
|
"drive '%s' status is '%s' [instance: %s].",
|
||||||
$_->{id}, $_->{status},
|
$_->{id}, $_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'drive', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'drive', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Drive '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{id}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Drive '%s' status is '%s'",
|
||||||
|
$_->{id},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsenclosure==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsenclosure==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'enclosure', instance => $_->{id}));
|
next if ($self->check_filter(section => 'enclosure', instance => $_->{id}));
|
||||||
$self->{components}->{enclosure}->{total}++;
|
$self->{components}->{enclosure}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("enclosure '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{id}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"enclosure '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{id},
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Enclosure '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{id}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Enclosure '%s' status is '%s'",
|
||||||
|
$_->{id},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,21 +39,30 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsenclosurebattery==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsenclosurebattery==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
my $instance = $_->{enclosure_id} . '.' . $_->{battery_id};
|
my $instance = $_->{enclosure_id} . '.' . $_->{battery_id};
|
||||||
next if ($self->check_filter(section => 'enclosurebattery', instance => $instance));
|
next if ($self->check_filter(section => 'enclosurebattery', instance => $instance));
|
||||||
$self->{components}->{enclosurebattery}->{total}++;
|
$self->{components}->{enclosurebattery}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("enclosure battery '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$instance, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"enclosure battery '%s' status is '%s' [instance: %s].",
|
||||||
|
$instance,
|
||||||
|
$_->{status},
|
||||||
$instance
|
$instance
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'enclosurebattery', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'enclosurebattery', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Enclosure battery '%s' status is '%s'",
|
severity => $exit,
|
||||||
$instance, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Enclosure battery '%s' status is '%s'",
|
||||||
|
$instance,
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,21 +39,30 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsenclosurecanister==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsenclosurecanister==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
my $instance = $_->{enclosure_id} . '.' . $_->{canister_id};
|
my $instance = $_->{enclosure_id} . '.' . $_->{canister_id};
|
||||||
next if ($self->check_filter(section => 'enclosurecanister', instance => $instance));
|
next if ($self->check_filter(section => 'enclosurecanister', instance => $instance));
|
||||||
$self->{components}->{enclosurecanister}->{total}++;
|
$self->{components}->{enclosurecanister}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("enclosure canister '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$instance, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"enclosure canister '%s' status is '%s' [instance: %s].",
|
||||||
|
$instance,
|
||||||
|
$_->{status},
|
||||||
$instance
|
$instance
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'enclosurecanister', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'enclosurecanister', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Enclosure canister '%s' status is '%s'",
|
severity => $exit,
|
||||||
$instance, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Enclosure canister '%s' status is '%s'",
|
||||||
|
$instance,
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,21 +39,30 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsenclosurepsu==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsenclosurepsu==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
my $instance = $_->{enclosure_id} . '.' . $_->{PSU_id};
|
my $instance = $_->{enclosure_id} . '.' . $_->{PSU_id};
|
||||||
next if ($self->check_filter(section => 'enclosurepsu', instance => $instance));
|
next if ($self->check_filter(section => 'enclosurepsu', instance => $instance));
|
||||||
$self->{components}->{enclosurepsu}->{total}++;
|
$self->{components}->{enclosurepsu}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("enclosure power supply '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$instance, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"enclosure power supply '%s' status is '%s' [instance: %s].",
|
||||||
|
$instance,
|
||||||
|
$_->{status},
|
||||||
$instance
|
$instance
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'enclosurepsu', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'enclosurepsu', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Enclosure power supply '%s' status is '%s'",
|
severity => $exit,
|
||||||
$instance, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Enclosure power supply '%s' status is '%s'",
|
||||||
|
$instance,
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lshost==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lshost==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'host', instance => $_->{id}));
|
next if ($self->check_filter(section => 'host', instance => $_->{id}));
|
||||||
$self->{components}->{host}->{total}++;
|
$self->{components}->{host}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("host '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"host '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'host', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'host', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Host '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Host '%s' status is '%s'",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsmdisk==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsmdisk==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'mdisk', instance => $_->{id}));
|
next if ($self->check_filter(section => 'mdisk', instance => $_->{id}));
|
||||||
$self->{components}->{mdisk}->{total}++;
|
$self->{components}->{mdisk}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("mdisk '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"mdisk '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(section => 'mdisk', value => $_->{status});
|
my $exit = $self->get_severity(section => 'mdisk', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("MDisk '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"MDisk '%s' status is '%s'",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsnode==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsnode==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'node', instance => $_->{id}));
|
next if ($self->check_filter(section => 'node', instance => $_->{id}));
|
||||||
$self->{components}->{node}->{total}++;
|
$self->{components}->{node}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("node '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"node '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'node', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'node', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Node '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Node '%s' status is '%s'",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,21 +39,30 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsportfc==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsportfc==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'portfc', instance => $_->{id}));
|
next if ($self->check_filter(section => 'portfc', instance => $_->{id}));
|
||||||
$self->{components}->{portfc}->{total}++;
|
$self->{components}->{portfc}->{total}++;
|
||||||
|
|
||||||
my $name = $_->{node_name} . "." . $_->{WWPN};
|
my $name = $_->{node_name} . "." . $_->{WWPN};
|
||||||
$self->{output}->output_add(long_msg => sprintf("portfc '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$name, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"portfc '%s' status is '%s' [instance: %s].",
|
||||||
|
$name,
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(section => 'portfc', value => $_->{status});
|
my $exit = $self->get_severity(section => 'portfc', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("PortFC '%s' status is '%s'",
|
severity => $exit,
|
||||||
$name, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"PortFC '%s' status is '%s'",
|
||||||
|
$name,
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,21 +39,30 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsportsas==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsportsas==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'portsas', instance => $_->{id}));
|
next if ($self->check_filter(section => 'portsas', instance => $_->{id}));
|
||||||
$self->{components}->{portsas}->{total}++;
|
$self->{components}->{portsas}->{total}++;
|
||||||
|
|
||||||
my $name = $_->{node_name} . "." . $_->{WWPN};
|
my $name = $_->{node_name} . "." . $_->{WWPN};
|
||||||
$self->{output}->output_add(long_msg => sprintf("port sas '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$name, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"port sas '%s' status is '%s' [instance: %s].",
|
||||||
|
$name,
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(section => 'portsas', value => $_->{status});
|
my $exit = $self->get_severity(section => 'portsas', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Port sas '%s' status is '%s'",
|
severity => $exit,
|
||||||
$name, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Port sas '%s' status is '%s'",
|
||||||
|
$name,
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsquorum==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsquorum==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'quorum', instance => $_->{quorum_index}));
|
next if ($self->check_filter(section => 'quorum', instance => $_->{quorum_index}));
|
||||||
$self->{components}->{quorum}->{total}++;
|
$self->{components}->{quorum}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("quorum '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{controller_name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"quorum '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{controller_name},
|
||||||
|
$_->{status},
|
||||||
$_->{quorum_index}
|
$_->{quorum_index}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'quorum', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'quorum', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Quorum '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{controller_name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Quorum '%s' status is '%s'",
|
||||||
|
$_->{controller_name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,19 +39,27 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lssystemstats==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lssystemstats==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => '\s+');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => '\s+');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'systemstats', instance => $_->{stat_name}));
|
next if ($self->check_filter(section => 'systemstats', instance => $_->{stat_name}));
|
||||||
$self->{components}->{systemstats}->{total}++;
|
$self->{components}->{systemstats}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("system stat '%s' value is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{stat_name}, $_->{stat_current},
|
long_msg => sprintf(
|
||||||
|
"system stat '%s' value is '%s' [instance: %s].",
|
||||||
|
$_->{stat_name},
|
||||||
|
$_->{stat_current},
|
||||||
$_->{stat_name}
|
$_->{stat_name}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'systemstats', instance => $_->{stat_name}, value => $_->{stat_current});
|
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'systemstats', instance => $_->{stat_name}, value => $_->{stat_current});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("System stat '%s' value is '%s'", $_->{stat_name}, $_->{stat_current}));
|
severity => $exit,
|
||||||
|
short_msg => sprintf(
|
||||||
|
"System stat '%s' value is '%s'", $_->{stat_name}, $_->{stat_current}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$self->{output}->perfdata_add(
|
$self->{output}->perfdata_add(
|
||||||
label => "sstat",
|
label => "sstat",
|
||||||
|
@ -39,20 +39,29 @@ sub check {
|
|||||||
return if ($self->{results} !~ /==========lsvdisk==.*?\n(.*?)==============/msi);
|
return if ($self->{results} !~ /==========lsvdisk==.*?\n(.*?)==============/msi);
|
||||||
my $content = $1;
|
my $content = $1;
|
||||||
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
next if ($self->check_filter(section => 'vdisk', instance => $_->{id}));
|
next if ($self->check_filter(section => 'vdisk', instance => $_->{id}));
|
||||||
$self->{components}->{vdisk}->{total}++;
|
$self->{components}->{vdisk}->{total}++;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => sprintf("vdisk '%s' status is '%s' [instance: %s].",
|
$self->{output}->output_add(
|
||||||
$_->{name}, $_->{status},
|
long_msg => sprintf(
|
||||||
|
"vdisk '%s' status is '%s' [instance: %s].",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status},
|
||||||
$_->{id}
|
$_->{id}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
my $exit = $self->get_severity(label => 'default', section => 'vdisk', value => $_->{status});
|
my $exit = $self->get_severity(label => 'default', section => 'vdisk', value => $_->{status});
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Vdisk '%s' status is '%s'",
|
severity => $exit,
|
||||||
$_->{name}, $_->{status}));
|
short_msg => sprintf(
|
||||||
|
"Vdisk '%s' status is '%s'",
|
||||||
|
$_->{name},
|
||||||
|
$_->{status}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,16 +36,7 @@ sub new {
|
|||||||
'critical:s' => { name => 'critical', },
|
'critical:s' => { name => 'critical', },
|
||||||
'filter-event-id:s' => { name => 'filter_event_id' },
|
'filter-event-id:s' => { name => 'filter_event_id' },
|
||||||
'filter-message:s' => { name => 'filter_message' },
|
'filter-message:s' => { name => 'filter_message' },
|
||||||
'retention:s' => { name => 'retention' },
|
'retention:s' => { name => 'retention' }
|
||||||
'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 },
|
|
||||||
'sudo' => { name => 'sudo' },
|
|
||||||
'command:s' => { name => 'command' },
|
|
||||||
'command-path:s' => { name => 'command_path' },
|
|
||||||
'command-options:s' => { name => 'command_options' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -63,9 +54,6 @@ sub check_options {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
|
|
||||||
$self->{option_results}->{remote} = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $last_timestamp = '';
|
my $last_timestamp = '';
|
||||||
if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} =~ /^\d+$/) {
|
if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} =~ /^\d+$/) {
|
||||||
@ -77,37 +65,10 @@ sub check_options {
|
|||||||
$self->{ls_command} = "svcinfo lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :";
|
$self->{ls_command} = "svcinfo lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_hasharray {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
my $result = [];
|
|
||||||
return $result if ($options{content} eq '');
|
|
||||||
my ($header, @lines) = split /\n/, $options{content};
|
|
||||||
my @header_names = split /$options{delim}/, $header;
|
|
||||||
|
|
||||||
for (my $i = 0; $i <= $#lines; $i++) {
|
|
||||||
my @content = split /$options{delim}/, $lines[$i];
|
|
||||||
my $data = {};
|
|
||||||
for (my $j = 0; $j <= $#header_names; $j++) {
|
|
||||||
$data->{$header_names[$j]} = $content[$j];
|
|
||||||
}
|
|
||||||
push @$result, $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $content = centreon::plugins::misc::execute(
|
my $content = $options{custom}->execute_command(command => $self->{ls_command});
|
||||||
output => $self->{output},
|
|
||||||
options => $self->{option_results},
|
|
||||||
sudo => $self->{option_results}->{sudo},
|
|
||||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ls_command} . " ; exit ;",
|
|
||||||
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} : undef
|
|
||||||
);
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
my $result = $self->get_hasharray(content => $content, delim => ':');
|
||||||
|
|
||||||
my ($num_eventlog_checked, $num_errors) = (0, 0);
|
my ($num_eventlog_checked, $num_errors) = (0, 0);
|
||||||
@ -182,42 +143,6 @@ Filter on event message.
|
|||||||
|
|
||||||
Get eventlog of X last seconds. For the last minutes: --retention=60
|
Get eventlog of X last seconds. For the last minutes: --retention=60
|
||||||
|
|
||||||
=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<--sudo>
|
|
||||||
|
|
||||||
Use 'sudo' to execute the command.
|
|
||||||
|
|
||||||
=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.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -65,28 +65,17 @@ sub set_system {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$self->{components_path} = 'storage::ibm::storwize::ssh::mode::components';
|
$self->{components_path} = 'storage::ibm::storwize::ssh::mode::components';
|
||||||
$self->{components_module} = ['array', 'drive', 'enclosure', 'enclosurebattery', 'enclosurecanister',
|
$self->{components_module} = [
|
||||||
'enclosurepsu', 'host', 'portfc', 'portsas', 'vdisk', 'node', 'quorum', 'mdisk', 'systemstats'];
|
'array', 'drive', 'enclosure', 'enclosurebattery', 'enclosurecanister',
|
||||||
|
'enclosurepsu', 'host', 'portfc', 'portsas', 'vdisk', 'node', 'quorum', 'mdisk', 'systemstats'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ssh_execute {
|
sub ssh_execute {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{results} = centreon::plugins::misc::execute(output => $self->{output},
|
($self->{results}) = $options{custom}->execute_command(command => $self->{ssh_commands});
|
||||||
options => $self->{option_results},
|
$self->{custom} = $options{custom};
|
||||||
sudo => $self->{option_results}->{sudo},
|
|
||||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands} . " exit ;",
|
|
||||||
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} : undef);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 new {
|
sub new {
|
||||||
@ -94,43 +83,13 @@ sub new {
|
|||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$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 },
|
|
||||||
"sudo" => { name => 'sudo' },
|
|
||||||
"command:s" => { name => 'command' },
|
|
||||||
"command-path:s" => { name => 'command_path' },
|
|
||||||
"command-options:s" => { name => 'command_options' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{ssh_commands} = '';
|
$self->{ssh_commands} = '';
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_hasharray {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
my $result = [];
|
|
||||||
return $result if ($options{content} eq '');
|
|
||||||
my ($header, @lines) = split /\n/, $options{content};
|
|
||||||
my @header_names = split /$options{delim}/, $header;
|
|
||||||
|
|
||||||
for (my $i = 0; $i <= $#lines; $i++) {
|
|
||||||
my @content = split /$options{delim}/, $lines[$i];
|
|
||||||
my $data = {};
|
|
||||||
for (my $j = 0; $j <= $#header_names; $j++) {
|
|
||||||
$data->{$header_names[$j]} = $content[$j];
|
|
||||||
}
|
|
||||||
push @$result, $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
@ -173,42 +132,6 @@ Example: --warning='systemstats,cpu_pc,30'
|
|||||||
Set critical threshold for temperatures (syntax: type,regexp,threshold)
|
Set critical threshold for temperatures (syntax: type,regexp,threshold)
|
||||||
Example: --critical='systemstats,cpu_pc,40'
|
Example: --critical='systemstats,cpu_pc,40'
|
||||||
|
|
||||||
=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<--sudo>
|
|
||||||
|
|
||||||
Use 'sudo' to execute the command.
|
|
||||||
|
|
||||||
=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.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
|
|||||||
sub custom_status_output {
|
sub custom_status_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = 'status : ' . $self->{result_values}->{status};
|
return 'status : ' . $self->{result_values}->{status};
|
||||||
return $msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_status_calc {
|
sub custom_status_calc {
|
||||||
@ -87,11 +86,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 {
|
||||||
@ -140,20 +140,11 @@ sub new {
|
|||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
"filter-name:s" => { name => 'filter_name' },
|
'filter-name:s' => { name => 'filter_name' },
|
||||||
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /degraded/i' },
|
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /degraded/i' },
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /offline/i' },
|
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /offline/i' },
|
||||||
"units:s" => { name => 'units', default => '%' },
|
'units:s' => { name => 'units', default => '%' },
|
||||||
"free" => { name => 'free' },
|
'free' => { name => 'free' },
|
||||||
"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 },
|
|
||||||
"sudo" => { name => 'sudo' },
|
|
||||||
"command:s" => { name => 'command' },
|
|
||||||
"command-path:s" => { name => 'command_path' },
|
|
||||||
"command-options:s" => { name => 'command_options' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -163,9 +154,6 @@ sub check_options {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
|
|
||||||
$self->{option_results}->{remote} = 1;
|
|
||||||
}
|
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,14 +166,9 @@ sub prefix_pool_output {
|
|||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($content) = $options{custom}->execute_command(command => 'lsmdiskgrp -delim : -bytes');
|
||||||
$self->{pool} = {};
|
$self->{pool} = {};
|
||||||
my $content = centreon::plugins::misc::execute(output => $self->{output},
|
my $result = $options{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
options => $self->{option_results},
|
|
||||||
sudo => $self->{option_results}->{sudo},
|
|
||||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : "lsmdiskgrp -delim : -bytes ; exit ;",
|
|
||||||
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} : undef);
|
|
||||||
my $result = $self->get_hasharray(content => $content, delim => ':');
|
|
||||||
foreach (@$result) {
|
foreach (@$result) {
|
||||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
|
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
|
||||||
@ -193,38 +176,20 @@ sub manage_selection {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{pool}->{$_->{id}} = { display => $_->{name},
|
$self->{pool}->{$_->{id}} = {
|
||||||
|
display => $_->{name},
|
||||||
status => $_->{status},
|
status => $_->{status},
|
||||||
total => $_->{used_capacity} + $_->{free_capacity}, used => $_->{used_capacity}
|
total => $_->{used_capacity} + $_->{free_capacity},
|
||||||
|
used => $_->{used_capacity}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scalar(keys %{$self->{pool}}) <= 0) {
|
if (scalar(keys %{$self->{pool}}) <= 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "No pool found.");
|
$self->{output}->add_option_msg(short_msg => 'No pool found.');
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_hasharray {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
my $result = [];
|
|
||||||
return $result if ($options{content} eq '');
|
|
||||||
my ($header, @lines) = split /\n/, $options{content};
|
|
||||||
my @header_names = split /$options{delim}/, $header;
|
|
||||||
|
|
||||||
for (my $i = 0; $i <= $#lines; $i++) {
|
|
||||||
my @content = split /$options{delim}/, $lines[$i];
|
|
||||||
my $data = {};
|
|
||||||
for (my $j = 0; $j <= $#header_names; $j++) {
|
|
||||||
$data->{$header_names[$j]} = $content[$j];
|
|
||||||
}
|
|
||||||
push @$result, $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
@ -254,14 +219,9 @@ Can used special variables like: %{status}, %{display}
|
|||||||
Set critical threshold for status (Default: '%{status} =~ /offline/i').
|
Set critical threshold for status (Default: '%{status} =~ /offline/i').
|
||||||
Can used special variables like: %{status}, %{display}
|
Can used special variables like: %{status}, %{display}
|
||||||
|
|
||||||
=item B<--warning-*>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Threshold warning.
|
Thresholds.
|
||||||
Can be: 'usage'.
|
|
||||||
|
|
||||||
=item B<--critical-*>
|
|
||||||
|
|
||||||
Threshold critical.
|
|
||||||
Can be: 'usage'.
|
Can be: 'usage'.
|
||||||
|
|
||||||
=item B<--units>
|
=item B<--units>
|
||||||
@ -272,42 +232,6 @@ Units of thresholds (Default: '%') ('%', 'B').
|
|||||||
|
|
||||||
Thresholds are on free space left.
|
Thresholds are on free space left.
|
||||||
|
|
||||||
=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<--sudo>
|
|
||||||
|
|
||||||
Use 'sudo' to execute the command.
|
|
||||||
|
|
||||||
=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.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -22,7 +22,7 @@ package storage::ibm::storwize::ssh::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) = @_;
|
||||||
@ -35,6 +35,7 @@ sub new {
|
|||||||
'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog',
|
'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog',
|
||||||
'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage',
|
'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage',
|
||||||
);
|
);
|
||||||
|
$self->{custom_modes}{api} = 'storage::ibm::storwize::ssh::custom::api';
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user