wip ssh backend system + indent

This commit is contained in:
garnier-quentin 2020-02-19 11:52:30 +01:00
parent 54bdbbeb5e
commit a7b5399d0e
26 changed files with 980 additions and 495 deletions

View File

@ -37,19 +37,18 @@ sub new {
$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' },
"port:s@" => { name => 'port' },
"timeout:s@" => { name => 'timeout' },
"ssh-username:s@" => { name => 'ssh_username' },
"ssh-password:s@" => { name => 'ssh_password' },
"ssh-dir:s@" => { name => 'ssh_dir' },
"ssh-identity:s@" => { name => 'ssh_identity' },
"ssh-skip-serverkey-issue" => { name => 'ssh_skip_serverkey_issue' },
});
$options{options}->add_options(arguments => {
'hostname:s@' => { name => 'hostname' },
'port:s@' => { name => 'port' },
'timeout:s@' => { name => 'timeout' },
'ssh-username:s@' => { name => 'ssh_username' },
'ssh-password:s@' => { name => 'ssh_password' },
'ssh-dir:s@' => { name => 'ssh_dir' },
'ssh-identity:s@' => { name => 'ssh_identity' },
'ssh-skip-serverkey-issue' => { name => 'ssh_skip_serverkey_issue' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1);
@ -68,7 +67,7 @@ sub set_options {
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
@ -111,7 +110,7 @@ sub login {
my $result = { status => 0, message => 'authentification succeeded' };
$self->{ssh} = Libssh::Session->new();
foreach (['hostname', 'host'], ['port', 'port'], ['timeout', 'timeout'], ['ssh_username', 'user'],
['ssh_dir', 'sshdir'], ['ssh_identity', 'identity']) {
next if (!defined($self->{$_->[0]}) || $self->{$_->[0]} eq '');
@ -122,25 +121,25 @@ sub login {
return $result;
}
}
if ($self->{ssh}->connect(SkipKeyProblem => $self->{ssh_skip_serverkey_issue}) != SSH_OK) {
$result->{message} = $self->{ssh}->error();
$result->{status} = 1;
return $result;
}
if ($self->{ssh}->auth_publickey_auto() != SSH_AUTH_SUCCESS) {
if (defined($self->{ssh_username}) && $self->{ssh_username} ne '' &&
defined($self->{ssh_password}) && $self->{ssh_password} ne '' &&
$self->{ssh}->auth_password(password => $self->{ssh_password}) == SSH_AUTH_SUCCESS) {
return $result;
}
my $msg_error = $self->{ssh}->error(GetErrorSession => 1);
$result->{message} = sprintf("auth issue: %s", defined($msg_error) && $msg_error ne '' ? $msg_error : 'pubkey issue');
$result->{status} = 1;
}
return $result;
}

View 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

View 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

View File

@ -39,16 +39,20 @@ sub windows_execute {
my $result;
my ($stdout, $pid, $ended) = ('');
my ($exit_code, $cmd);
$cmd = $options{command_path} . '/' if (defined($options{command_path}));
$cmd .= $options{command} . ' ' if (defined($options{command}));
$cmd .= $options{command_options} if (defined($options{command_options}));
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'Win32::Job',
error_msg => "Cannot load module 'Win32::Job'.");
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'Time::HiRes',
error_msg => "Cannot load module 'Time::HiRes'.");
centreon::plugins::misc::mymodule_load(
output => $options{output}, module => 'Win32::Job',
error_msg => "Cannot load module 'Win32::Job'."
);
centreon::plugins::misc::mymodule_load(
output => $options{output}, module => 'Time::HiRes',
error_msg => "Cannot load module 'Time::HiRes'."
);
$| = 1;
pipe FROM_CHILD, TO_PARENT or do {
$options{output}->add_option_msg(short_msg => "Internal error: can't create pipe from child to parent: $!");
@ -91,10 +95,10 @@ sub windows_execute {
},
0.1
);
$result = $job->status;
close FROM_CHILD;
if ($ended == 0) {
$options{output}->add_option_msg(short_msg => 'Command too long to execute (timeout)...');
$options{output}->option_exit();
@ -104,13 +108,13 @@ sub windows_execute {
if (defined($options{no_quit}) && $options{no_quit} == 1) {
return ($stdout, $result->{$pid}->{exitcode});
}
if ($result->{$pid}->{exitcode} != 0) {
$stdout =~ s/\n/ - /g;
$options{output}->add_option_msg(short_msg => "Command error: $stdout");
$options{output}->option_exit();
}
return ($stdout, $result->{$pid}->{exitcode});
}
@ -124,7 +128,7 @@ sub unix_execute {
$redirect_stderr = $options{redirect_stderr} if (defined($options{redirect_stderr}));
my $wait_exit = 1;
$wait_exit = $options{wait_exit} if (defined($options{wait_exit}));
# Build command line
# Can choose which command is done remotely (can filter and use local file)
if (defined($options{options}->{remote}) &&
@ -133,19 +137,20 @@ sub unix_execute {
$cmd = $options{options}->{ssh_path} . '/' if (defined($options{options}->{ssh_path}));
$cmd .= $options{options}->{ssh_command} if (defined($options{options}->{ssh_command}));
foreach (@{$options{options}->{ssh_option}}) {
my ($lvalue, $rvalue) = split /=/;
push @$args, $lvalue if (defined($lvalue));
push @$args, $rvalue if (defined($rvalue));
if (/^(.*?)(?:=(.*))?$/) {
push @$args, $1 if (defined($1));
push @$args, $2 if (defined($2));
}
}
if (defined($options{options}->{ssh_address}) && $options{options}->{ssh_address} ne '') {
push @$args, $options{options}->{ssh_address};
} else {
push @$args, $options{options}->{hostname};
}
$sub_cmd = 'sudo ' if (defined($options{sudo}));
$sub_cmd .= $options{command_path} . '/' if (defined($options{command_path}));
$sub_cmd .= $options{command} . ' ' if (defined($options{command}));
@ -173,7 +178,7 @@ sub unix_execute {
$cmd .= $options{command_path} . '/' if (defined($options{command_path}));
$cmd .= $options{command} . ' ' if (defined($options{command}));
$cmd .= $options{command_options} if (defined($options{command_options}));
($lerror, $stdout, $exit_code) = backtick(
command => $cmd,
timeout => $options{options}->{timeout},
@ -187,23 +192,23 @@ sub unix_execute {
print $stdout;
exit $exit_code;
}
$stdout =~ s/\r//g;
if ($lerror <= -1000) {
$options{output}->add_option_msg(short_msg => $stdout);
$options{output}->option_exit();
}
if (defined($options{no_quit}) && $options{no_quit} == 1) {
return ($stdout, $exit_code);
}
if ($exit_code != 0 && (!defined($options{no_errors}) || !defined($options{no_errors}->{$exit_code}))) {
$stdout =~ s/\n/ - /g;
$options{output}->add_option_msg(short_msg => "Command error: $stdout");
$options{output}->option_exit();
}
return $stdout;
}
@ -211,7 +216,7 @@ sub mymodule_load {
my (%options) = @_;
my $file;
($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . '.pm')) =~ s{::}{/}g;
eval {
local $SIG{__DIE__} = 'IGNORE';
require $file;
@ -239,7 +244,7 @@ sub backtick {
my @output;
my $pid;
my $return_code;
my $sig_do;
if ($arg{wait_exit} == 0) {
$sig_do = 'IGNORE';

129
centreon/plugins/ssh.pm Normal file
View 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

View File

@ -80,11 +80,16 @@ sub check_options {
}
}
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Redis',
error_msg => "Cannot load module 'Redis'.");
centreon::plugins::misc::mymodule_load(
output => $self->{output},
module => 'Redis',
error_msg => "Cannot load module 'Redis'."
);
eval {
$self->{redis_cnx} = Redis->new(server => $options{option_results}->{redis_server},
eval $self->{redis_attributes});
$self->{redis_cnx} = Redis->new(
server => $options{option_results}->{redis_server},
eval $self->{redis_attributes}
);
if (defined($self->{redis_cnx}) &&
defined($options{option_results}->{redis_db}) &&
$options{option_results}->{redis_db} ne ''
@ -96,13 +101,19 @@ sub check_options {
$self->{statefile_dir} = $options{option_results}->{statefile_dir};
if ($self->{statefile_dir} ne $default_dir && defined($options{option_results}->{statefile_concat_cwd})) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Cwd',
error_msg => "Cannot load module 'Cwd'.");
centreon::plugins::misc::mymodule_load(
output => $self->{output},
module => 'Cwd',
error_msg => "Cannot load module 'Cwd'."
);
$self->{statefile_dir} = Cwd::cwd() . '/' . $self->{statefile_dir};
}
if (defined($options{option_results}->{statefile_storable})) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Storable',
error_msg => "Cannot load module 'Storable'.");
centreon::plugins::misc::mymodule_load(
output => $self->{output},
module => 'Storable',
error_msg => "Cannot load module 'Storable'."
);
$self->{storable} = 1;
}
$self->{statefile_suffix} = $options{option_results}->{statefile_suffix};
@ -111,7 +122,7 @@ sub check_options {
sub error {
my ($self) = shift;
if (@_) {
$self->{error} = $_[0];
}
@ -140,7 +151,7 @@ sub read {
return 0;
}
}
if (defined($self->{redis_cnx})) {
my $val = $self->{redis_cnx}->get($self->{statefile_dir} . "/" . $self->{statefile});
if (defined($val)) {
@ -152,7 +163,7 @@ sub read {
return 0;
}
if (! -e $self->{statefile_dir} . '/' . $self->{statefile}) {
if (! -w $self->{statefile_dir} || ! -x $self->{statefile_dir}) {
$self->error(1);
@ -173,7 +184,7 @@ sub read {
# Empty file. Not a problem. Maybe plugin not manage not values
return 0;
}
if ($self->{storable} == 1) {
open FILE, $self->{statefile_dir} . '/' . $self->{statefile};
eval {
@ -227,15 +238,19 @@ sub write {
my ($self, %options) = @_;
if ($self->{memcached_ok} == 1) {
Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . '/' . $self->{statefile},
Data::Dumper->Dump([$options{data}], ['datas']), $self->{memexpiration});
Memcached::libmemcached::memcached_set(
$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) {
return ;
}
}
if (defined($self->{redis_cnx})) {
return if (defined($self->{redis_cnx}->set($self->{statefile_dir} . '/' . $self->{statefile}, Data::Dumper->Dump([$options{data}], ['datas']),
'EX', $self->{memexpiration})));
return if (defined($self->{redis_cnx}->set(
$self->{statefile_dir} . '/' . $self->{statefile}, Data::Dumper->Dump([$options{data}], ['datas']),
'EX', $self->{memexpiration}))
);
}
open FILE, '>', $self->{statefile_dir} . '/' . $self->{statefile};
if ($self->{storable} == 1) {

View File

@ -35,7 +35,7 @@ sub new {
'storage-usage' => 'storage::hp::eva::cli::mode::storageusage',
);
$self->{custom_modes}{api} = 'storage::hp::eva::cli::custom::api';
return $self;
}

View 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

View File

@ -25,13 +25,13 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsarray=========="; lsarray -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking arrays");
$self->{components}->{array} = {name => 'arrays', total => 0, skip => 0};
return if ($self->check_filter(section => 'array'));
@ -39,22 +39,31 @@ sub check {
return if ($self->{results} !~ /==========lsarray==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'array', instance => $_->{mdisk_id}));
$self->{components}->{array}->{total}++;
$self->{output}->output_add(long_msg => sprintf("array '%s' status is '%s' [instance: %s].",
$_->{mdisk_name}, $_->{status},
$_->{mdisk_id}
));
$self->{output}->output_add(
long_msg => sprintf(
"array '%s' status is '%s' [instance: %s].",
$_->{mdisk_name},
$_->{status},
$_->{mdisk_id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'array', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Array '%s' status is '%s'",
$_->{mdisk_name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Array '%s' status is '%s'",
$_->{mdisk_name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,36 +25,44 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsdrive=========="; lsdrive -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking drives");
$self->{components}->{drive} = {name => 'drives', total => 0, skip => 0};
return if ($self->check_filter(section => 'drive'));
return if ($self->{results} !~ /==========lsdrive==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'drive', instance => $_->{id}));
$self->{components}->{drive}->{total}++;
$self->{output}->output_add(long_msg => sprintf("drive '%s' status is '%s' [instance: %s].",
$_->{id}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"drive '%s' status is '%s' [instance: %s].",
$_->{id}, $_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'drive', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Drive '%s' status is '%s'",
$_->{id}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Drive '%s' status is '%s'",
$_->{id},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,36 +25,45 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsenclosure=========="; lsenclosure -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking enclosures");
$self->{components}->{enclosure} = {name => 'enclosures', total => 0, skip => 0};
return if ($self->check_filter(section => 'enclosure'));
return if ($self->{results} !~ /==========lsenclosure==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'enclosure', instance => $_->{id}));
$self->{components}->{enclosure}->{total}++;
$self->{output}->output_add(long_msg => sprintf("enclosure '%s' status is '%s' [instance: %s].",
$_->{id}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"enclosure '%s' status is '%s' [instance: %s].",
$_->{id},
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Enclosure '%s' status is '%s'",
$_->{id}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Enclosure '%s' status is '%s'",
$_->{id},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,37 +25,46 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsenclosurebattery=========="; lsenclosurebattery -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking enclosure batteries");
$self->{components}->{enclosurebattery} = {name => 'enclosure batteries', total => 0, skip => 0};
return if ($self->check_filter(section => 'enclosurebattery'));
return if ($self->{results} !~ /==========lsenclosurebattery==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
my $instance = $_->{enclosure_id} . '.' . $_->{battery_id};
next if ($self->check_filter(section => 'enclosurebattery', instance => $instance));
$self->{components}->{enclosurebattery}->{total}++;
$self->{output}->output_add(long_msg => sprintf("enclosure battery '%s' status is '%s' [instance: %s].",
$instance, $_->{status},
$instance
));
$self->{output}->output_add(
long_msg => sprintf(
"enclosure battery '%s' status is '%s' [instance: %s].",
$instance,
$_->{status},
$instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'enclosurebattery', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Enclosure battery '%s' status is '%s'",
$instance, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Enclosure battery '%s' status is '%s'",
$instance,
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,37 +25,46 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsenclosurecanister=========="; lsenclosurecanister -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking enclosure canisters");
$self->{components}->{enclosurecanister} = {name => 'enclosure canisters', total => 0, skip => 0};
return if ($self->check_filter(section => 'enclosurecanister'));
return if ($self->{results} !~ /==========lsenclosurecanister==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
my $instance = $_->{enclosure_id} . '.' . $_->{canister_id};
next if ($self->check_filter(section => 'enclosurecanister', instance => $instance));
$self->{components}->{enclosurecanister}->{total}++;
$self->{output}->output_add(long_msg => sprintf("enclosure canister '%s' status is '%s' [instance: %s].",
$instance, $_->{status},
$instance
));
$self->{output}->output_add(
long_msg => sprintf(
"enclosure canister '%s' status is '%s' [instance: %s].",
$instance,
$_->{status},
$instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'enclosurecanister', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Enclosure canister '%s' status is '%s'",
$instance, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Enclosure canister '%s' status is '%s'",
$instance,
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,37 +25,46 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsenclosurepsu=========="; lsenclosurepsu -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking enclosure psus");
$self->{components}->{enclosurepsu} = {name => 'enclosure psus', total => 0, skip => 0};
return if ($self->check_filter(section => 'enclosurepsu'));
return if ($self->{results} !~ /==========lsenclosurepsu==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
my $instance = $_->{enclosure_id} . '.' . $_->{PSU_id};
next if ($self->check_filter(section => 'enclosurepsu', instance => $instance));
$self->{components}->{enclosurepsu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("enclosure power supply '%s' status is '%s' [instance: %s].",
$instance, $_->{status},
$instance
));
$self->{output}->output_add(
long_msg => sprintf(
"enclosure power supply '%s' status is '%s' [instance: %s].",
$instance,
$_->{status},
$instance
)
);
my $exit = $self->get_severity(label => 'default', section => 'enclosurepsu', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Enclosure power supply '%s' status is '%s'",
$instance, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Enclosure power supply '%s' status is '%s'",
$instance,
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,36 +25,45 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lshost=========="; lshost -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking hosts");
$self->{components}->{host} = {name => 'hosts', total => 0, skip => 0};
return if ($self->check_filter(section => 'host'));
return if ($self->{results} !~ /==========lshost==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'host', instance => $_->{id}));
$self->{components}->{host}->{total}++;
$self->{output}->output_add(long_msg => sprintf("host '%s' status is '%s' [instance: %s].",
$_->{name}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"host '%s' status is '%s' [instance: %s].",
$_->{name},
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'host', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Host '%s' status is '%s'",
$_->{name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Host '%s' status is '%s'",
$_->{name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,7 +25,7 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsmdisk=========="; lsmdisk -delim : ; echo "===============";';
}
@ -38,23 +38,32 @@ sub check {
return if ($self->{results} !~ /==========lsmdisk==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'mdisk', instance => $_->{id}));
$self->{components}->{mdisk}->{total}++;
$self->{output}->output_add(long_msg => sprintf("mdisk '%s' status is '%s' [instance: %s].",
$_->{name}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"mdisk '%s' status is '%s' [instance: %s].",
$_->{name},
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(section => 'mdisk', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("MDisk '%s' status is '%s'",
$_->{name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"MDisk '%s' status is '%s'",
$_->{name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,36 +25,45 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsnode=========="; lsnode -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking nodes");
$self->{components}->{node} = {name => 'nodes', total => 0, skip => 0};
return if ($self->check_filter(section => 'node'));
return if ($self->{results} !~ /==========lsnode==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'node', instance => $_->{id}));
$self->{components}->{node}->{total}++;
$self->{output}->output_add(long_msg => sprintf("node '%s' status is '%s' [instance: %s].",
$_->{name}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"node '%s' status is '%s' [instance: %s].",
$_->{name},
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'node', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Node '%s' status is '%s'",
$_->{name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Node '%s' status is '%s'",
$_->{name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -38,24 +38,33 @@ sub check {
return if ($self->{results} !~ /==========lsportfc==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'portfc', instance => $_->{id}));
$self->{components}->{portfc}->{total}++;
my $name = $_->{node_name} . "." . $_->{WWPN};
$self->{output}->output_add(long_msg => sprintf("portfc '%s' status is '%s' [instance: %s].",
$name, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"portfc '%s' status is '%s' [instance: %s].",
$name,
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(section => 'portfc', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("PortFC '%s' status is '%s'",
$name, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"PortFC '%s' status is '%s'",
$name,
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -38,24 +38,33 @@ sub check {
return if ($self->{results} !~ /==========lsportsas==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'portsas', instance => $_->{id}));
$self->{components}->{portsas}->{total}++;
my $name = $_->{node_name} . "." . $_->{WWPN};
$self->{output}->output_add(long_msg => sprintf("port sas '%s' status is '%s' [instance: %s].",
$name, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"port sas '%s' status is '%s' [instance: %s].",
$name,
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(section => 'portsas', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Port sas '%s' status is '%s'",
$name, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Port sas '%s' status is '%s'",
$name,
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,36 +25,45 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsquorum=========="; lsquorum -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking quorums");
$self->{components}->{quorum} = {name => 'quorums', total => 0, skip => 0};
return if ($self->check_filter(section => 'quorum'));
return if ($self->{results} !~ /==========lsquorum==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'quorum', instance => $_->{quorum_index}));
$self->{components}->{quorum}->{total}++;
$self->{output}->output_add(long_msg => sprintf("quorum '%s' status is '%s' [instance: %s].",
$_->{controller_name}, $_->{status},
$_->{quorum_index}
));
$self->{output}->output_add(
long_msg => sprintf(
"quorum '%s' status is '%s' [instance: %s].",
$_->{controller_name},
$_->{status},
$_->{quorum_index}
)
);
my $exit = $self->get_severity(label => 'default', section => 'quorum', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Quorum '%s' status is '%s'",
$_->{controller_name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Quorum '%s' status is '%s'",
$_->{controller_name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -25,7 +25,7 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lssystemstats=========="; lssystemstats ; echo "===============";';
}
@ -38,20 +38,28 @@ sub check {
return if ($self->{results} !~ /==========lssystemstats==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => '\s+');
my $result = $self->{custom}->get_hasharray(content => $content, delim => '\s+');
foreach (@$result) {
next if ($self->check_filter(section => 'systemstats', instance => $_->{stat_name}));
$self->{components}->{systemstats}->{total}++;
$self->{output}->output_add(long_msg => sprintf("system stat '%s' value is '%s' [instance: %s].",
$_->{stat_name}, $_->{stat_current},
$_->{stat_name}
));
$self->{output}->output_add(
long_msg => sprintf(
"system stat '%s' value is '%s' [instance: %s].",
$_->{stat_name},
$_->{stat_current},
$_->{stat_name}
)
);
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)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("System stat '%s' value is '%s'", $_->{stat_name}, $_->{stat_current}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"System stat '%s' value is '%s'", $_->{stat_name}, $_->{stat_current}
)
);
}
$self->{output}->perfdata_add(
label => "sstat",

View File

@ -25,36 +25,45 @@ use warnings;
sub load {
my ($self) = @_;
$self->{ssh_commands} .= 'echo "==========lsvdisk=========="; lsvdisk -delim : ; echo "===============";';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking vdisks");
$self->{components}->{vdisk} = {name => 'vdisks', total => 0, skip => 0};
return if ($self->check_filter(section => 'vdisk'));
return if ($self->{results} !~ /==========lsvdisk==.*?\n(.*?)==============/msi);
my $content = $1;
my $result = $self->get_hasharray(content => $content, delim => ':');
my $result = $self->{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
next if ($self->check_filter(section => 'vdisk', instance => $_->{id}));
$self->{components}->{vdisk}->{total}++;
$self->{output}->output_add(long_msg => sprintf("vdisk '%s' status is '%s' [instance: %s].",
$_->{name}, $_->{status},
$_->{id}
));
$self->{output}->output_add(
long_msg => sprintf(
"vdisk '%s' status is '%s' [instance: %s].",
$_->{name},
$_->{status},
$_->{id}
)
);
my $exit = $self->get_severity(label => 'default', section => 'vdisk', value => $_->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Vdisk '%s' status is '%s'",
$_->{name}, $_->{status}));
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Vdisk '%s' status is '%s'",
$_->{name},
$_->{status}
)
);
}
}
}
1;
1;

View File

@ -36,16 +36,7 @@ sub new {
'critical:s' => { name => 'critical', },
'filter-event-id:s' => { name => 'filter_event_id' },
'filter-message:s' => { name => 'filter_message' },
'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' },
'retention:s' => { name => 'retention' }
});
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}->option_exit();
}
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
my $last_timestamp = '';
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 :";
}
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 {
my ($self, %options) = @_;
my $content = centreon::plugins::misc::execute(
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 $content = $options{custom}->execute_command(command => $self->{ls_command});
my $result = $self->get_hasharray(content => $content, delim => ':');
my ($num_eventlog_checked, $num_errors) = (0, 0);
@ -133,7 +94,7 @@ sub run {
);
$num_errors++;
}
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked));
my $exit = $self->{perfdata}->threshold_check(value => $num_errors, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(
@ -147,7 +108,7 @@ sub run {
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0
);
$self->{output}->display();
$self->{output}->exit();
}
@ -182,42 +143,6 @@ Filter on event message.
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
=cut

View File

@ -65,72 +65,31 @@ sub set_system {
};
$self->{components_path} = 'storage::ibm::storwize::ssh::mode::components';
$self->{components_module} = ['array', 'drive', 'enclosure', 'enclosurebattery', 'enclosurecanister',
'enclosurepsu', 'host', 'portfc', 'portsas', 'vdisk', 'node', 'quorum', 'mdisk', 'systemstats'];
$self->{components_module} = [
'array', 'drive', 'enclosure', 'enclosurebattery', 'enclosurecanister',
'enclosurepsu', 'host', 'portfc', 'portsas', 'vdisk', 'node', 'quorum', 'mdisk', 'systemstats'
];
}
sub ssh_execute {
my ($self, %options) = @_;
$self->{results} = centreon::plugins::misc::execute(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->{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;
}
($self->{results}) = $options{custom}->execute_command(command => $self->{ssh_commands});
$self->{custom} = $options{custom};
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
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 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options' },
});
$options{options}->add_options(arguments => {
});
$self->{ssh_commands} = '';
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;
__END__
@ -173,42 +132,6 @@ Example: --warning='systemstats,cpu_pc,30'
Set critical threshold for temperatures (syntax: type,regexp,threshold)
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
=cut

View File

@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
return 'status : ' . $self->{result_values}->{status};
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
@ -43,7 +42,7 @@ sub custom_status_calc {
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if (defined($self->{instance_mode}->{option_results}->{free})) {
@ -69,7 +68,7 @@ sub custom_usage_perfdata {
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free}));
@ -83,15 +82,16 @@ sub custom_usage_threshold {
sub custom_usage_output {
my ($self, %options) = @_;
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_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%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
return sprintf(
'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
}
sub custom_usage_calc {
@ -103,17 +103,17 @@ sub custom_usage_calc {
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' }
];
$self->{maps_counters}->{pool} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
@ -140,22 +140,13 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /degraded/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /offline/i' },
"units:s" => { name => 'units', default => '%' },
"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' },
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /degraded/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /offline/i' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
});
return $self;
}
@ -163,29 +154,21 @@ 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->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_pool_output {
my ($self, %options) = @_;
return "Pool '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
my ($content) = $options{custom}->execute_command(command => 'lsmdiskgrp -delim : -bytes');
$self->{pool} = {};
my $content = centreon::plugins::misc::execute(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} : "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 => ':');
my $result = $options{custom}->get_hasharray(content => $content, delim => ':');
foreach (@$result) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
@ -193,38 +176,20 @@ sub manage_selection {
next;
}
$self->{pool}->{$_->{id}} = { display => $_->{name},
status => $_->{status},
total => $_->{used_capacity} + $_->{free_capacity}, used => $_->{used_capacity}
};
$self->{pool}->{$_->{id}} = {
display => $_->{name},
status => $_->{status},
total => $_->{used_capacity} + $_->{free_capacity},
used => $_->{used_capacity}
};
}
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();
}
}
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;
__END__
@ -254,14 +219,9 @@ Can used special variables like: %{status}, %{display}
Set critical threshold for status (Default: '%{status} =~ /offline/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'usage'.
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'usage'.
=item B<--units>
@ -272,42 +232,6 @@ Units of thresholds (Default: '%') ('%', 'B').
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
=cut

View File

@ -22,7 +22,7 @@ package storage::ibm::storwize::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) = @_;
@ -35,6 +35,7 @@ sub new {
'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog',
'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage',
);
$self->{custom_modes}{api} = 'storage::ibm::storwize::ssh::custom::api';
return $self;
}