security - add method to block command override batch 2 (#4054)

This commit is contained in:
qgarnier 2022-11-16 14:30:15 +00:00 committed by GitHub
parent 057a0a43f4
commit dbab4c8b41
41 changed files with 783 additions and 1193 deletions

View File

@ -69,7 +69,7 @@ sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'update', type => 0, message_separator => ' - ' }, { name => 'update', type => 0, message_separator => ' - ' }
]; ];
$self->{maps_counters}->{update} = [ $self->{maps_counters}->{update} = [
@ -101,23 +101,13 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' },
'nameservers:s@' => { name => 'nameservers' }, 'nameservers:s@' => { name => 'nameservers' },
'maindb-file:s' => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' }, 'maindb-file:s' => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' },
'dailydb-file:s' => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' } 'dailydb-file:s' => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' }
}); });
return $self; return $self;
} }
@ -125,14 +115,8 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command( $self->{option_results}->{maindb_file} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{maindb_file});
output => $self->{output}, $self->{option_results}->{dailydb_file} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{dailydb_file});
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{clamav_command} = 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file};
} }
sub get_clamav_last_update { sub get_clamav_last_update {
@ -180,7 +164,7 @@ sub get_clamav_current_signature_info {
second => 0, second => 0,
time_zone => $6, time_zone => $6,
); );
$self->{'current_' . $options{label} . 'db_timediff'} = time() - $dt->epoch; $self->{'current_' . $options{label} . 'db_timediff'} = time() - $dt->epoch();
} }
} }
@ -188,14 +172,11 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->get_clamav_last_update(); $self->get_clamav_last_update();
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file}
sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{clamav_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
); );
#==== CLAMD === #==== CLAMD ===
#ClamAV 0.99.2/21723/Mon Jun 13 14:53:00 2016 #ClamAV 0.99.2/21723/Mon Jun 13 14:53:00 2016
#==== DAILY ==== #==== DAILY ====
@ -245,6 +226,8 @@ __END__
Check antivirus update status. Check antivirus update status.
Command used: 'clamd -V ; sigtool --info %(dailydb-file) ; sigtool --info %(maindb-file)'
=over 8 =over 8
=item B<--nameservers> =item B<--nameservers>
@ -252,46 +235,6 @@ Check antivirus update status.
Set nameserver to query (can be multiple). Set nameserver to query (can be multiple).
The system configuration is used by default. The system configuration is used by default.
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information. Used it you have output in a file.
=item B<--command-path>
Command path.
=item B<--command-options>
Command options (Default: '-report -most_columns').
=item B<--maindb-file> =item B<--maindb-file>
Antivirus main.cvd file (Default: '/var/lib/clamav/main.cvd'). Antivirus main.cvd file (Default: '/var/lib/clamav/main.cvd').

View File

@ -22,18 +22,19 @@ package apps::antivirus::clamav::local::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1';
$self->{modes} = { $self->{modes} = {
'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus', 'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus',
}; };
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self; return $self;
} }

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -61,6 +61,9 @@ 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();
} }
$self->{option_results}->{apchost} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apchost});
$self->{option_results}->{apcport} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{apcport});
} }
sub run { sub run {

View File

@ -42,6 +42,8 @@ sub new {
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
$self->{option_results}->{host_pattern} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{host_pattern});
} }
sub run { sub run {

View File

@ -31,18 +31,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' }, 'filter-name:s' => { name => 'filter_name' }
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options' },
"filter-name:s" => { name => 'filter_name' }
}); });
return $self; return $self;
@ -51,20 +41,6 @@ sub new {
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'vtconfig'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-l'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
$self->{option_results}->{command_path} = '/quadstorvtl/bin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
} }
sub run { sub run {
@ -76,8 +52,10 @@ sub run {
$self->{output}->output_add(long_msg => "'" . $_ . "' [type = " . $self->{vtl}->{$_}->{type} . "]"); $self->{output}->output_add(long_msg => "'" . $_ . "' [type = " . $self->{vtl}->{$_}->{type} . "]");
} }
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => 'List VTL:'); severity => 'OK',
short_msg => 'List VTL:'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
@ -93,21 +71,21 @@ sub disco_show {
$self->manage_selection(%options); $self->manage_selection(%options);
foreach (sort keys %{$self->{vtl}}) { foreach (sort keys %{$self->{vtl}}) {
$self->{output}->add_disco_entry(name => $_, $self->{output}->add_disco_entry(
active => $self->{vtl}->{$_}->{type} name => $_,
); active => $self->{vtl}->{$_}->{type}
);
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'vtconfig',
sudo => $self->{option_results}->{sudo}, command_options => '-l',
command => $self->{option_results}->{command}, command_path => '/quadstorvtl/bin'
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options});
#Name DevType Type #Name DevType Type
#BV00002 VTL IBM IBM System Storage TS3100 #BV00002 VTL IBM IBM System Storage TS3100
@ -136,49 +114,10 @@ __END__
List VTL. List VTL.
Command used: '/quadstorvtl/bin/vtconfig -l'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'vtconfig').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/quadstorvtl/bin').
=item B<--command-options>
Command options (Default: '-l').
=item B<--filter-name> =item B<--filter-name>
Filter vtl name (can be a regexp). Filter vtl name (can be a regexp).

View File

@ -25,21 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
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 {
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;
} }
sub custom_usage_perfdata { sub custom_usage_perfdata {
@ -88,10 +79,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%%)", my $msg = sprintf(
$total_size_value . " " . $total_size_unit, "Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $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 $msg;
} }
@ -123,12 +116,11 @@ sub set_counters {
]; ];
$self->{maps_counters}->{disk} = [ $self->{maps_counters}->{disk} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{status} !~ /active/i', set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'usage', set => { { label => 'usage', set => {
@ -136,7 +128,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold')
} }
}, },
]; ];
@ -159,8 +151,6 @@ sub new {
"command-path:s" => { name => 'command_path' }, "command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options' }, "command-options:s" => { name => 'command_options' },
"filter-name:s" => { name => 'filter_name' }, "filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' },
"units:s" => { name => 'units', default => '%' }, "units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' }, "free" => { name => 'free' },
}); });
@ -168,37 +158,13 @@ sub new {
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'bdconfig'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-l -c'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
$self->{option_results}->{command_path} = '/quadstorvtl/bin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'bdconfig',
options => $self->{option_results}, command_options => '-l -c',
sudo => $self->{option_results}->{sudo}, command_path => '/quadstorvtl/bin'
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
); );
$self->{disk} = {}; $self->{disk} = {};
@ -241,49 +207,10 @@ __END__
Check vtl disk usage. Check vtl disk usage.
Command used: '/quadstorvtl/bin/bdconfig -l -c'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'bdconfig').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/quadstorvtl/bin').
=item B<--command-options>
Command options (Default: '-l -c').
=item B<--filter-name> =item B<--filter-name>
Filter tape name. Filter tape name.

View File

@ -104,9 +104,9 @@ sub set_counters {
closure_custom_calc => $self->can('custom_frozen_calc'), closure_custom_calc => $self->can('custom_frozen_calc'),
closure_custom_output => $self->can('custom_frozen_output'), closure_custom_output => $self->can('custom_frozen_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_frozen_threshold'), closure_custom_threshold_check => $self->can('custom_frozen_threshold')
} }
}, }
]; ];
} }
@ -115,55 +115,23 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {});
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' }
});
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'impexp'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-l'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
$self->{option_results}->{command_path} = '/quadstorvtl/bin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{cache_name} = 'quadstor_' . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' . $self->{cache_name} = 'quadstor_' . $self->{mode} . '_' . $options{custom}->get_identifier() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my ($stdout) = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'impexp',
options => $self->{option_results}, command_options => '-l',
sudo => $self->{option_results}->{sudo}, command_path => '/quadstorvtl/bin'
command => $self->{option_results}->{command}, );
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
$self->{jobs}->{global} = { job => {} }; $self->{jobs}->{global} = { job => {} };
#JobID Type Source State Transfer Elapsed #JobID Type Source State Transfer Elapsed
#252 Import 701831L2 Error 36.00 GB 572 #252 Import 701831L2 Error 36.00 GB 572
@ -171,7 +139,7 @@ sub manage_selection {
#254 Export 701850L2 Completed 16.05 GB 1072 #254 Export 701850L2 Completed 16.05 GB 1072
#255 Export 701854L2 Completed 6.31 GB 142 #255 Export 701854L2 Completed 6.31 GB 142
my $current_time = time(); my $current_time = time();
my @lines = split /\n/, $stdout; my @lines = split(/\n/, $stdout);
shift @lines; shift @lines;
foreach (@lines) { foreach (@lines) {
next if (! /^(\d+)\s+\S+\s+(\S+)\s+(\S+)\s+([0-9\.]+)\s+\S+\s+(\d+)/); next if (! /^(\d+)\s+\S+\s+(\S+)\s+(\S+)\s+([0-9\.]+)\s+\S+\s+(\d+)/);
@ -202,49 +170,10 @@ __END__
Check job status. Check job status.
Command used: '/quadstorvtl/bin/impexp -l'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'impexp').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/quadstorvtl/bin').
=item B<--command-options>
Command options (Default: '-l').
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: none) Set warning threshold for status (Default: none)

View File

@ -25,21 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
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 {
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;
} }
sub custom_usage_perfdata { sub custom_usage_perfdata {
@ -88,10 +79,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%%)", my $msg = sprintf(
$total_size_value . " " . $total_size_unit, "Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $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 $msg;
} }
@ -109,6 +102,12 @@ sub custom_usage_calc {
return 0; return 0;
} }
sub prefix_tape_output {
my ($self, %options) = @_;
return "Tape '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -122,20 +121,18 @@ sub set_counters {
key_values => [ { name => 'count' } ], key_values => [ { name => 'count' } ],
output_template => 'Number of tapes : %s', output_template => 'Number of tapes : %s',
perfdatas => [ perfdatas => [
{ label => 'count', value => 'count', template => '%s', { label => 'count', template => '%s', unit => 'tapes', min => 0 }
unit => 'tapes', min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{tape} = [ $self->{maps_counters}->{tape} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{status} !~ /active/i', set => {
key_values => [ { name => 'status' }, { name => 'display' } ], key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'usage', set => { { label => 'usage', set => {
@ -143,9 +140,9 @@ sub set_counters {
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold')
} }
}, }
]; ];
} }
@ -154,23 +151,11 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' }, 'vtl-name:s' => { name => 'vtl_name' },
'remote' => { name => 'remote' }, 'filter-name:s' => { name => 'filter_name' },
'ssh-option:s@' => { name => 'ssh_option' }, 'units:s' => { name => 'units', default => '%' },
'ssh-path:s' => { name => 'ssh_path' }, 'free' => { name => 'free' }
'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' },
'vtl-name:s' => { name => 'vtl_name' },
'filter-name:s' => { name => 'filter_name' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /active/i' },
'units:s' => { name => 'units', default => '%' },
'free' => { name => 'free' },
}); });
return $self; return $self;
@ -185,40 +170,16 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
centreon::plugins::misc::check_security_command( $self->{option_results}->{vtl_name} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{vtl_name});
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'vcconfig'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-l -v %{vtl_name}'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
$self->{option_results}->{command_path} = '/quadstorvtl/bin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
$self->{option_results}->{command_options} =~ s/%\{vtl_name\}/$self->{option_results}->{vtl_name}/;
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_tape_output {
my ($self, %options) = @_;
return "Tape '" . $options{instance_value}->{display} . "' ";
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'vcconfig',
options => $self->{option_results}, command_options => '-l -v ' . $self->{option_results}->{vtl_name},
sudo => $self->{option_results}->{sudo}, command_path => '/quadstorvtl/bin'
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
); );
$self->{global}->{count} = 0; $self->{global}->{count} = 0;
@ -249,7 +210,7 @@ sub manage_selection {
display => $name, display => $name,
total => $size * 1024 * 1024 * 1024, total => $size * 1024 * 1024 * 1024,
used_prct => $used_prct, used_prct => $used_prct,
status => $status, status => $status
}; };
$self->{global}->{count}++; $self->{global}->{count}++;
} }
@ -268,49 +229,10 @@ __END__
Check vtl tape usage. Check vtl tape usage.
Command used: '/quadstorvtl/bin/vcconfig -l -v %(vtl-name)'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'vcconfig').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/quadstorvtl/bin').
=item B<--command-options>
Command options (Default: '-l -v %{vtl_name}').
=item B<--vtl-name> =item B<--vtl-name>
Set VTL name (Required). Set VTL name (Required).
@ -337,14 +259,9 @@ Can used special variables like: %{status}, %{display}
Set critical threshold for status (Default: '%{status} !~ /active/i'). Set critical threshold for status (Default: '%{status} !~ /active/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: 'count', 'usage'.
=item B<--critical-*>
Threshold critical.
Can be: 'count', 'usage'. Can be: 'count', 'usage'.
=back =back

View File

@ -22,20 +22,21 @@ package apps::backup::quadstor::local::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = (
'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl',
'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage',
'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus',
'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage',
); };
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self; return $self;
} }

View File

@ -20,55 +20,27 @@
package apps::backup::tsm::local::custom::api; package apps::backup::tsm::local::custom::api;
use base qw(centreon::plugins::script_custom::cli);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = {}; my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; 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 => {
$options{options}->add_options(arguments => { 'tsm-hostname:s' => { name => 'tsm_hostname' },
'tsm-hostname:s' => { name => 'tsm_hostname' }, 'tsm-username:s' => { name => 'tsm_username' },
'tsm-username:s' => { name => 'tsm_username' }, 'tsm-password:s' => { name => 'tsm_password' }
'tsm-password:s' => { name => 'tsm_password' }, });
'ssh-hostname:s' => { name => 'ssh_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 => 45 },
'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 => 'TSM CLI OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'TSM CLI OPTIONS', once => 1);
$self->{output} = $options{output};
return $self; return $self;
} }
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -84,36 +56,10 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to set tsm-password option."); $self->{output}->add_option_msg(short_msg => "Need to set tsm-password option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'dsmadmc'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_path} = '/opt/tivoli/tsm/client/ba/bin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
return 0; return 0;
} }
sub tsm_build_options {
my ($self, %options) = @_;
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
if (defined($self->{option_results}->{ssh_hostname}) && $self->{option_results}->{ssh_hostname} ne '') {
$self->{option_results}->{hostname} = $self->{option_results}->{ssh_hostname};
$self->{option_results}->{remote} = 1;
}
$self->{option_results}->{command_options} =
"-comma -dataonly=yes -SERVER=\"$self->{option_results}->{tsm_hostname}\" -ID=\"$self->{option_results}->{tsm_username}\" -PASSWORD=\"$self->{option_results}->{tsm_password}\" -TAB \"$options{query}\"";
}
sub get_tsm_id { sub get_tsm_id {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -122,27 +68,26 @@ sub get_tsm_id {
sub execute_command { sub execute_command {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->tsm_build_options(%options); my $command = 'dsmadmc';
my ($response, $exit_code) = centreon::plugins::misc::execute( my $command_options = "-comma -dataonly=yes -SERVER=\"$self->{option_results}->{tsm_hostname}\" -ID=\"$self->{option_results}->{tsm_username}\" -PASSWORD=\"$self->{option_results}->{tsm_password}\" -TAB \"$options{query}\"";;
output => $self->{output},
options => $self->{option_results}, my ($stdout, $exit_code) = $self->SUPER::execute_command(
sudo => $self->{option_results}->{sudo}, %options,
command => $self->{option_results}->{command}, command => $command,
command_path => $self->{option_results}->{command_path}, command_options => $command_options,
command_options => $self->{option_results}->{command_options},
no_quit => 1 no_quit => 1
); );
# 11 is for: ANR2034E SELECT: No match found using this criteria. # 11 is for: ANR2034E SELECT: No match found using this criteria.
if ($exit_code != 0 && $exit_code != 11) { if ($exit_code != 0 && $exit_code != 11) {
$self->{output}->output_add(long_msg => $response); $self->{output}->output_add(long_msg => $stdout);
$self->{output}->add_option_msg(short_msg => "Execution command issue (details)."); $self->{output}->add_option_msg(short_msg => "Execution command issue (details).");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{output}->output_add(long_msg => $response, debug => 1); $self->{output}->output_add(long_msg => $stdout, debug => 1);
return $response; return $stdout;
} }
1; 1;
@ -173,42 +118,6 @@ TSM username (Required).
TSM password (Required). TSM password (Required).
=item B<--ssh-hostname>
Specify SSH hostname.
=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: 45).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Specify command (default: 'dsmadmc').
=item B<--command-path>
Specify path (default: '/opt/tivoli/tsm/client/ba/bin')
=item B<--command-options>
Command options.
=back =back
=head1 DESCRIPTION =head1 DESCRIPTION

View File

@ -29,7 +29,6 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0';
$self->{modes} = { $self->{modes} = {
'actlog' => 'apps::backup::tsm::local::mode::actlog', 'actlog' => 'apps::backup::tsm::local::mode::actlog',
'drives' => 'apps::backup::tsm::local::mode::drives', 'drives' => 'apps::backup::tsm::local::mode::drives',
@ -38,7 +37,7 @@ sub new {
'volumes' => 'apps::backup::tsm::local::mode::volumes', 'volumes' => 'apps::backup::tsm::local::mode::volumes',
}; };
$self->{custom_modes}{api} = 'apps::backup::tsm::local::custom::api'; $self->{custom_modes}->{api} = 'apps::backup::tsm::local::custom::api';
return $self; return $self;
} }

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc; use centreon::plugins::ssh;
use JSON; use JSON;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
@ -43,7 +43,6 @@ sub custom_status_output {
return $msg; return $msg;
} }
sub prefix_endpoint_output { sub prefix_endpoint_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -103,15 +102,13 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'broker-stats-file:s@' => { name => 'broker_stats_file' }, 'broker-stats-file:s@' => { name => 'broker_stats_file' },
'hostname:s' => { name => 'hostname' }, 'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 }, 'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' }, 'sudo' => { name => 'sudo' },
'filter-name:s' => { name => 'filter_name' } 'filter-name:s' => { name => 'filter_name' }
}); });
$self->{ssh} = centreon::plugins::ssh->new(%options);
return $self; return $self;
} }
@ -123,6 +120,34 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option."); $self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
}
sub execute_command {
my ($self, %options) = @_;
my ($stdout, $exit_code);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout, $exit_code) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
sudo => $self->{option_results}->{sudo},
command => $options{command},
command_options => $options{command_options},
timeout => $self->{option_results}->{timeout}
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
sudo => $self->{option_results}->{sudo},
options => { timeout => $self->{option_results}->{timeout} },
command => $options{command},
command_options => $options{command_options}
);
}
return ($stdout, $exit_code);
} }
sub manage_selection { sub manage_selection {
@ -130,10 +155,7 @@ sub manage_selection {
$self->{endpoint} = {}; $self->{endpoint} = {};
foreach my $config (@{$self->{option_results}->{broker_stats_file}}) { foreach my $config (@{$self->{option_results}->{broker_stats_file}}) {
my ($stdout) = centreon::plugins::misc::execute( my ($stdout) = $self->execute_command(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => 'cat', command => 'cat',
command_options => $config command_options => $config
); );
@ -195,25 +217,9 @@ Check Centreon Broker statistics files.
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname> =item B<--hostname>
Hostname to query (need --remote). Hostname to query in ssh.
=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> =item B<--timeout>
@ -231,14 +237,9 @@ Specify the centreon-broker json stats file (Required). Can be multiple.
Filter endpoint name. Filter endpoint name.
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
=item B<--critical-*>
Threshold critical.
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'. Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
=item B<--warning-status> =item B<--warning-status>

View File

@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc; use centreon::plugins::misc;
sub custom_hosts_execution_time_output { sub custom_hosts_execution_time_output {
@ -141,9 +142,9 @@ sub set_counters {
{ name => 'services_active_checked', type => 0, skipped_code => { -10 => 1 } }, { name => 'services_active_checked', type => 0, skipped_code => { -10 => 1 } },
{ name => 'services_active_latency', type => 0, skipped_code => { -10 => 1 } }, { name => 'services_active_latency', type => 0, skipped_code => { -10 => 1 } },
{ name => 'services_status', type => 0, skipped_code => { -10 => 1 } }, { name => 'services_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'commands_buffer', type => 0, skipped_code => { -10 => 1 } }, { name => 'commands_buffer', type => 0, skipped_code => { -10 => 1 } }
], ]
}, }
]; ];
foreach my $type ('hosts', 'services') { foreach my $type ('hosts', 'services') {
@ -204,8 +205,8 @@ sub set_counters {
threshold_use => $_->[0] , threshold_use => $_->[0] ,
closure_custom_output => $self->can('custom_' . $type . '_latency_output'), closure_custom_output => $self->can('custom_' . $type . '_latency_output'),
perfdatas => [ perfdatas => [
{ value => $_->[0] , template => '%.3f', min => 0, unit => 's' }, { value => $_->[0] , template => '%.3f', min => 0, unit => 's' }
], ]
} }
} }
; ;
@ -286,14 +287,12 @@ sub new {
'command-path:s' => { name => 'command_path' }, 'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' }, 'command-options:s' => { name => 'command_options' },
'hostname:s' => { name => 'hostname' }, 'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 }, 'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' } 'sudo' => { name => 'sudo' }
}); });
$self->{ssh} = centreon::plugins::ssh->new(%options);
return $self; return $self;
} }
@ -314,22 +313,49 @@ sub check_options {
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
$self->{option_results}->{command_path} = '/usr/sbin' $self->{option_results}->{command_path} = '/usr/sbin'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
}
sub execute_command {
my ($self, %options) = @_;
my ($stdout, $exit_code);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
($stdout, $exit_code) = $self->{ssh}->execute(
hostname => $self->{option_results}->{hostname},
sudo => $self->{option_results}->{sudo},
command => $options{command},
command_options => $options{command_options},
command_path => $options{command_path},
timeout => $self->{option_results}->{timeout}
);
} else {
($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
sudo => $self->{option_results}->{sudo},
options => { timeout => $self->{option_results}->{timeout} },
command => $options{command},
command_path => $options{command_path},
command_options => $options{command_options}
);
}
return ($stdout, $exit_code);
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute( my ($stdout) = $self->execute_command(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command}, command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} command_options => $self->{option_results}->{command_options}
); );
$self->{stats} = {}; $self->{stats} = {};
if ($stdout =~ /^Active\s+Host\s+Execution\s+Time\s*:\s*(\S+)\s*\/\s*(\S+)\s*\/\s*(\S+)/mi) { if ($stdout =~ /^Active\s+Host\s+Execution\s+Time\s*:\s*(\S+)\s*\/\s*(\S+)\s*\/\s*(\S+)/mi) {
$self->{stats}->{0} = { hosts_active_execution_time => { min => $1, max => $2, avg => $3 } }; $self->{stats}->{0} = { hosts_active_execution_time => { min => $1, max => $2, avg => $3 } };
} }
@ -371,40 +397,26 @@ __END__
Check centengine statistics. Check centengine statistics.
Command used: '/usr/sbin/centenginestats '2>&1
=over 8 =over 8
=item B<--command> =item B<--command>
Command to get information (Default: 'centenginestats'). Command to get information.
Can be changed if you have output in a file. Can be changed if you have output in a file.
=item B<--command-path> =item B<--command-path>
Command path (Default: '/usr/sbin'). Command path.
=item B<--command-options> =item B<--command-options>
Command options (Default: '2>&1'). Command options.
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname> =item B<--hostname>
Hostname to query (need --remote). Hostname to query in ssh.
=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> =item B<--timeout>

View File

@ -55,23 +55,23 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "oid-trap:s" => { name => 'oid_trap', default => '.1.3.6.1.4.1.50000.1.1' },
"oid-trap:s" => { name => 'oid_trap', default => '.1.3.6.1.4.1.50000.1.1' }, "oid-hostname:s" => { name => 'oid_hostname', default => '.1.3.6.1.4.1.50000.2.1' },
"oid-hostname:s" => { name => 'oid_hostname', default => '.1.3.6.1.4.1.50000.2.1' }, "oid-start:s" => { name => 'oid_start', default => '.1.3.6.1.4.1.50000.2.2' },
"oid-start:s" => { name => 'oid_start', default => '.1.3.6.1.4.1.50000.2.2' }, "oid-end:s" => { name => 'oid_end', default => '.1.3.6.1.4.1.50000.2.4' },
"oid-end:s" => { name => 'oid_end', default => '.1.3.6.1.4.1.50000.2.4' }, "oid-author:s" => { name => 'oid_author', default => '.1.3.6.1.4.1.50000.2.5' },
"oid-author:s" => { name => 'oid_author', default => '.1.3.6.1.4.1.50000.2.5' }, "oid-comment:s" => { name => 'oid_comment', default => '.1.3.6.1.4.1.50000.2.6' },
"oid-comment:s" => { name => 'oid_comment', default => '.1.3.6.1.4.1.50000.2.6' }, "oid-duration:s" => { name => 'oid_duration', default => '.1.3.6.1.4.1.50000.2.7' },
"oid-duration:s" => { name => 'oid_duration', default => '.1.3.6.1.4.1.50000.2.7' }, "centreon-server:s" => { name => 'centreon_server' },
"centreon-server:s" => { name => 'centreon_server' }, "author:s" => { name => 'author', default => 'system reboot' },
"author:s" => { name => 'author', default => 'system reboot' }, "comment:s" => { name => 'comment', default => 'the system reboots.' },
"comment:s" => { name => 'comment', default => 'the system reboots.' }, "duration:s" => { name => 'duration', default => 300 },
"duration:s" => { name => 'duration', default => 300 }, "wait:s" => { name => 'wait' },
"wait:s" => { name => 'wait' }, "snmptrap-command:s" => { name => 'snmptrap_command', default => 'snmptrap' },
"snmptrap-command:s" => { name => 'snmptrap_command', default => 'snmptrap' }, "display-options" => { name => 'display_options' }
"display-options" => { name => 'display_options' }, });
});
return $self; return $self;
} }

View File

@ -32,23 +32,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'command-extra-options:s' => { name => 'command_extra_options' },
"remote" => { name => 'remote' }, 'timeout:s' => { name => 'timeout', default => 50 },
"hostname:s" => { name => 'hostname' }, 'directory:s' => { name => 'directory' },
"ssh-option:s@" => { name => 'ssh_option' }, 'scenario:s' => { name => 'scenario' },
"ssh-path:s" => { name => 'ssh_path' }, 'warning:s' => { name => 'warning' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, 'critical:s' => { name => 'critical' }
"sudo" => { name => 'sudo' }, });
"command:s" => { name => 'command', default => 'jmeter' },
"command-path:s" => { name => 'command_path' },
"command-extra-options:s" => { name => 'command_extra_options' },
"timeout:s" => { name => 'timeout', default => 50 },
"directory:s" => { name => 'directory' },
"scenario:s" => { name => 'scenario' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
return $self; return $self;
} }
@ -68,13 +60,21 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Please specify a scenario name."); $self->{output}->add_option_msg(short_msg => "Please specify a scenario name.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!defined($self->{option_results}->{directory})) {
$self->{output}->add_option_msg(short_msg => "Please specify a directory.");
$self->{output}->option_exit();
}
$self->{option_results}->{directory} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{directory});
$self->{option_results}->{scenario} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{scenario});
$self->{option_results}->{command_extra_options} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{command_extra_options});
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.jmx'; my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.jmx';
my $command_options .= '-t ' . $filename; my $command_options = '-t ' . $filename;
# Temporary write result on stderr # Temporary write result on stderr
$command_options .= ' -l /dev/stderr'; $command_options .= ' -l /dev/stderr';
@ -92,12 +92,10 @@ sub run {
# Redirect result on stdout and default stdout to trash # Redirect result on stdout and default stdout to trash
$command_options .= ' 2>&1 >/dev/null'; $command_options .= ' 2>&1 >/dev/null';
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = $options{custom}->execute_command(
options => $self->{option_results}, command => 'jmeter',
sudo => $self->{option_results}->{sudo}, command_options => $command_options
command => $self->{option_results}->{command}, );
command_path => $self->{option_results}->{command_path},
command_options => $command_options);
my $p = XML::Parser->new(NoLWP => 1); my $p = XML::Parser->new(NoLWP => 1);
my $xp = XML::XPath->new(parser => $p, xml => $stdout); my $xp = XML::XPath->new(parser => $p, xml => $stdout);
@ -170,29 +168,41 @@ sub run {
my $timeelapsed = ($timing1 - $timing0) / 1000; my $timeelapsed = ($timing1 - $timing0) / 1000;
my $availability = sprintf("%d", $stepOk * 100 / $step); my $availability = sprintf("%d", $stepOk * 100 / $step);
my $exit2 = $self->{perfdata}->threshold_check(value => $timeelapsed, my $exit2 = $self->{perfdata}->threshold_check(
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); value => $timeelapsed,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
if (!defined($first_failed_label)) { if (!defined($first_failed_label)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed)); severity => $exit,
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed)
);
} else { } else {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $first_failed_label)); severity => $exit,
short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $first_failed_label)
);
} }
$self->{output}->perfdata_add(label => "time", unit => 's', $self->{output}->perfdata_add(
value => sprintf('%.3f', $timeelapsed), label => "time", unit => 's',
min => 0, value => sprintf('%.3f', $timeelapsed),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), min => 0,
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
$self->{output}->perfdata_add(label => "steps", critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')
value => sprintf('%d', $stepOk), );
min => 0, $self->{output}->perfdata_add(
max => $step); label => "steps",
$self->{output}->perfdata_add(label => "availability", unit => '%', value => sprintf('%d', $stepOk),
value => sprintf('%d', $availability), min => 0,
min => 0, max => $step
max => 100); );
$self->{output}->perfdata_add(
label => "availability", unit => '%',
value => sprintf('%d', $availability),
min => 0,
max => 100
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
@ -204,49 +214,15 @@ __END__
=head1 MODE =head1 MODE
Check scenario execution Check scenario execution.
Command used: 'jmeter -t %(directory)/%(scenario).jmx -l /dev/stderr -j /dev/null -n -J jmeter.save.saveservice.output_format=xml %(command-extra-options) 2>&1 >/dev/null'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none).
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (default: 'jmeter').
=item B<--command-path>
Command path (default: none).
=item B<--command-extra-options> =item B<--command-extra-options>
Command extra options (default: none). Command extra options.
=item B<--timeout>
Timeout in seconds for the command (default: 50).
=item B<--directory> =item B<--directory>

View File

@ -22,17 +22,18 @@ package apps::jmeter::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{modes} = {
%{$self->{modes}} = ( 'scenario' => 'apps::jmeter::mode::scenario'
'scenario' => 'apps::jmeter::mode::scenario', };
);
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self; return $self;
} }

View File

@ -31,7 +31,7 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'domain:s' => { name => 'domain' }, 'domain:s' => { name => 'domain' },
'workstation:s' => { name => 'workstation' }, 'workstation:s' => { name => 'workstation' },
@ -44,6 +44,9 @@ sub new {
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
$self->{option_results}->{domain} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{domain});
$self->{option_results}->{workstation} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{workstation});
} }
sub netdom { sub netdom {
@ -57,19 +60,25 @@ sub netdom {
$netdom_cmd .= ' ' . Win32::NodeName(); $netdom_cmd .= ' ' . Win32::NodeName();
} }
my ($stdout, $exit_code) = centreon::plugins::misc::windows_execute(output => $self->{output}, my ($stdout, $exit_code) = centreon::plugins::misc::windows_execute(
timeout => $self->{option_results}->{timeout}, output => $self->{output},
command => $netdom_cmd, timeout => $self->{option_results}->{timeout},
command_path => undef, command => $netdom_cmd,
command_options => undef, command_path => undef,
no_quit => 1); command_options => undef,
no_quit => 1
);
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => 'Secure channel has been verified.'); severity => 'OK',
short_msg => 'Secure channel has been verified.'
);
if ($exit_code != 0) { if ($exit_code != 0) {
$self->{output}->output_add(long_msg => $stdout); $self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->output_add(
short_msg => 'Secure channel had a problem (see additional info).'); severity => 'CRITICAL',
short_msg => 'Secure channel had a problem (see additional info).'
);
} }
} }

View File

@ -96,6 +96,10 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{server} = centreon::plugins::misc::sanitize_command_param(value => $self->{server});
$self->{port} = centreon::plugins::misc::sanitize_command_param(value => $self->{port});
$self->{cacert} = centreon::plugins::misc::sanitize_command_param(value => $self->{cacert});
return 0; return 0;
} }

View File

@ -22,6 +22,7 @@ package centreon::common::emc::navisphere::custom::custom;
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::ssh;
use centreon::plugins::misc; use centreon::plugins::misc;
sub new { sub new {
@ -37,32 +38,30 @@ sub new {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit(); $options{output}->option_exit();
} }
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'remote' => { name => 'remote' },
'ssh-address:s' => { name => 'ssh_address' }, 'ssh-address:s' => { name => 'ssh_address' },
'ssh-option:s@' => { name => 'ssh_option' }, 'navicli-command:s' => { name => 'navicli_command' },
'ssh-path:s' => { name => 'ssh_path' }, 'navicli-path:s' => { name => 'navicli_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'naviseccli-command:s' => { name => 'naviseccli_command' },
'navicli-command:s' => { name => 'navicli_command', default => 'navicli' }, 'naviseccli-path:s' => { name => 'naviseccli_path' },
'navicli-path:s' => { name => 'navicli_path', default => '/opt/Navisphere/bin' }, 'sudo' => { name => 'sudo' },
'naviseccli-command:s' => { name => 'naviseccli_command', default => 'naviseccli' }, 'special-arg:s' => { name => 'special_arg' },
'naviseccli-path:s' => { name => 'naviseccli_path', default => '/opt/Navisphere/bin' }, 'hostname:s' => { name => 'hostname' },
'sudo:s' => { name => 'sudo', }, 'secfilepath:s' => { name => 'secfilepath' },
'special-arg:s@' => { name => 'special_arg' }, 'username:s' => { name => 'username' },
'hostname:s@' => { name => 'hostname' }, 'password:s' => { name => 'password' },
'secfilepath:s@' => { name => 'secfilepath' }, 'scope:s' => { name => 'scope' },
'username:s@' => { name => 'username' }, 'timeout:s' => { name => 'timeout' }
'password:s@' => { name => 'password' },
'scope:s@' => { name => 'scope' },
'timeout:s@' => { name => 'timeout' }
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'NAVISPHERE OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'NAVISPHERE OPTIONS', once => 1);
$self->{ssh} = centreon::plugins::ssh->new(%options);
$self->{output} = $options{output}; $self->{output} = $options{output};
# 1 means we use a file to read # 1 means we use a file to read
$self->{no_navicmd} = 0; $self->{no_navicmd} = 0;
$self->{secure} = 0; $self->{secure} = 0;
@ -78,6 +77,60 @@ sub set_options {
sub set_defaults {} sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
# return 1 = ok still hostname
# return 0 = no hostname left
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{secfilepath} = (defined($self->{option_results}->{secfilepath})) ? $self->{option_results}->{secfilepath} : undef;
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
$self->{scope} = (defined($self->{option_results}->{scope})) ? $self->{option_results}->{scope} : 0;
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
$self->{special_arg} = (defined($self->{option_results}->{special_arg})) ? $self->{option_results}->{special_arg} : undef;
$self->{sudo} = $self->{option_results}->{sudo};
if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.');
$self->{output}->option_exit();
}
$self->{hostname} = centreon::plugins::misc::sanitize_command_param(value => $self->{hostname});
$self->{scope} = centreon::plugins::misc::sanitize_command_param(value => $self->{scope});
$self->{special_arg} = centreon::plugins::misc::sanitize_command_param(value => $self->{special_arg});
$self->{timeout} = centreon::plugins::misc::sanitize_command_param(value => $self->{timeout});
$self->{secfilepath} = centreon::plugins::misc::sanitize_command_param(value => $self->{secfilepath});
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{navicli_command},
command_path => $self->{option_results}->{navicli_path}
);
$self->{option_results}->{navicli_command} = 'navicli'
if (!defined($self->{option_results}->{navicli_command}) || $self->{option_results}->{navicli_command} eq '');
$self->{option_results}->{navicli_path} = '/opt/Navisphere/bin'
if (!defined($self->{option_results}->{navicli_path}) || $self->{option_results}->{navicli_path} eq '');
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{naviseccli_command},
command_path => $self->{option_results}->{naviseccli_path}
);
$self->{option_results}->{navicli_command} = 'naviseccli'
if (!defined($self->{option_results}->{naviseccli_command}) || $self->{option_results}->{naviseccli_command} eq '');
$self->{option_results}->{navicli_path} = '/opt/Navisphere/bin'
if (!defined($self->{option_results}->{naviseccli_path}) || $self->{option_results}->{naviseccli_path} eq '');
if (defined($self->{option_results}->{ssh_address}) && $self->{option_results}->{ssh_address} ne '') {
$self->{ssh}->check_options(option_results => $self->{option_results});
}
$self->build_command();
return 0;
}
sub build_command { sub build_command {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -85,14 +138,14 @@ sub build_command {
$self->{output}->add_option_msg(short_msg => "Wrong scope option '" . $self->{scope} . "'."); $self->{output}->add_option_msg(short_msg => "Wrong scope option '" . $self->{scope} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{cmd} = $self->{option_results}->{navicli_path} . '/' . $self->{option_results}->{navicli_command}; $self->{cmd} = $self->{option_results}->{navicli_path} . '/' . $self->{option_results}->{navicli_command};
if (defined($self->{username}) || defined($self->{secfilepath})) { if (defined($self->{username}) || defined($self->{secfilepath})) {
$self->{cmd} = $self->{option_results}->{naviseccli_path} . '/' . $self->{option_results}->{naviseccli_command}; $self->{cmd} = $self->{option_results}->{naviseccli_path} . '/' . $self->{option_results}->{naviseccli_command};
$self->{secure} = 1; $self->{secure} = 1;
} }
if (defined($self->{secfilepath})) { if (defined($self->{secfilepath})) {
if (!(-x $self->{secfilepath} && -e $self->{secfilepath} . "/SecuredCLISecurityFile.xml" && -e $self->{secfilepath} . "/SecuredCLIXMLEncrypted.key")) { if (!(-x $self->{secfilepath} && -e $self->{secfilepath} . "/SecuredCLISecurityFile.xml" && -e $self->{secfilepath} . "/SecuredCLIXMLEncrypted.key")) {
$self->{output}->add_option_msg(short_msg => 'The secfilepath ' . $self->{secfilepath} . ' does not exist or SecuredCLI files are not created.'); $self->{output}->add_option_msg(short_msg => 'The secfilepath ' . $self->{secfilepath} . ' does not exist or SecuredCLI files are not created.');
@ -104,12 +157,12 @@ sub build_command {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }
if (! -e $self->{cmd}) { if (! -e $self->{cmd}) {
$self->{output}->add_option_msg(short_msg => "Command '" . $self->{cmd} . "' not exist or executable."); $self->{output}->add_option_msg(short_msg => "Command '" . $self->{cmd} . "' not exist or executable.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (defined($self->{special_arg}) && $self->{special_arg} ne '') { if (defined($self->{special_arg}) && $self->{special_arg} ne '') {
$self->{cmd} .= ' ' . $self->{special_arg}; $self->{cmd} .= ' ' . $self->{special_arg};
$self->{no_navicmd} = 1; $self->{no_navicmd} = 1;
@ -117,12 +170,12 @@ sub build_command {
$self->{secure} = 1; $self->{secure} = 1;
return ; return ;
} }
if (!defined($self->{hostname})) { if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); $self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (defined($self->{secfilepath})) { if (defined($self->{secfilepath})) {
$self->{cmd} .= " -Secfilepath '" . $self->{secfilepath} . "'"; $self->{cmd} .= " -Secfilepath '" . $self->{secfilepath} . "'";
} elsif (defined($self->{username})) { } elsif (defined($self->{username})) {
@ -132,35 +185,9 @@ sub build_command {
$self->{cmd} .= ' -h ' . $self->{hostname}; $self->{cmd} .= ' -h ' . $self->{hostname};
} }
sub check_options {
my ($self, %options) = @_;
# return 1 = ok still hostname
# return 0 = no hostname left
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef;
$self->{secfilepath} = (defined($self->{option_results}->{secfilepath})) ? shift(@{$self->{option_results}->{secfilepath}}) : undef;
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
$self->{scope} = (defined($self->{option_results}->{scope})) ? shift(@{$self->{option_results}->{scope}}) : 0;
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 30;
$self->{special_arg} = (defined($self->{option_results}->{special_arg})) ? shift(@{$self->{option_results}->{special_arg}}) : undef;
$self->{sudo} = $self->{option_results}->{sudo};
$self->build_command();
if (!defined($self->{hostname}) ||
scalar(@{$self->{option_results}->{hostname}}) == 0) {
return 0;
}
return 1;
}
##############
# Specific methods
##############
sub execute_command { sub execute_command {
my ($self, %options) = @_; my ($self, %options) = @_;
if ($self->{no_navicmd} == 0) { if ($self->{no_navicmd} == 0) {
$self->{cmd} .= ' ' . $options{cmd}; $self->{cmd} .= ' ' . $options{cmd};
} }
@ -168,17 +195,25 @@ sub execute_command {
$self->{output}->add_option_msg(short_msg => "Mode only works with naviseccli."); $self->{output}->add_option_msg(short_msg => "Mode only works with naviseccli.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
# Need to set timeout over command. my ($stdout, $exit_code);
$self->{option_results}->{timeout} = $self->{timeout} + 5; if (defined($self->{option_results}->{ssh_address}) && $self->{option_results}->{ssh_address} ne '') {
return centreon::plugins::misc::execute( ($stdout, $exit_code) = $self->{ssh}->execute(
output => $self->{output}, hostname => $self->{option_results}->{ssh_address},
options => $self->{option_results}, sudo => $self->{sudo},
sudo => $self->{sudo}, command => $self->{cmd},
command => $self->{cmd}, timeout => $self->{timeout} + 5
command_path => undef, );
command_options => undef } else {
); ($stdout, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
sudo => $self->{sudo},
options => { timeout => $self->{timeout} + 5 },
command => $self->{cmd}
);
}
return ($stdout, $exit_code);
} }
1; 1;
@ -197,26 +232,10 @@ my navisphere manage
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--ssh-address> =item B<--ssh-address>
Specify ssh address target (default: use hostname option) Specify ssh address target (default: use hostname option)
=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<--navicli-path> =item B<--navicli-path>
Specify navicli path (default: '/opt/Navisphere/bin') Specify navicli path (default: '/opt/Navisphere/bin')

View File

@ -50,8 +50,7 @@ sub check_options {
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
if (defined($self->{option_results}->{command_options})) { if (defined($self->{option_results}->{command_options})) {
# we remove illegal characters $self->{option_results}->{command_options} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{command_options});
$self->{option_results}->{command_options} =~ s/[`;!&]//g;
} }
return 0; return 0;

View File

@ -28,10 +28,6 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = {}; my $self = {};
bless $self, $class; bless $self, $class;
# $options{options} = options object
# $options{output} = output object
# $options{exit_value} = integer
# $options{noptions} = integer
if (!defined($options{output})) { if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n"; print "Class Custom: Need to specify 'output' argument.\n";
@ -41,139 +37,131 @@ sub new {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit(); $options{output}->option_exit();
} }
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"smcli-command:s" => { name => 'smcli_command', default => 'SMcli' }, 'smcli-command:s' => { name => 'smcli_command' },
"smcli-path:s" => { name => 'smcli_path', }, 'smcli-path:s' => { name => 'smcli_path' },
"sudo:s" => { name => 'sudo', }, 'sudo' => { name => 'sudo', },
"extra-options:s@" => { name => 'extra_options' }, 'extra-options:s' => { name => 'extra_options' },
"special-arg:s@" => { name => 'special_arg' }, 'special-arg:s' => { name => 'special_arg' },
"hostname:s@" => { name => 'hostname' }, 'hostname:s' => { name => 'hostname' },
"hostname2:s@" => { name => 'hostname2' }, 'hostname2:s' => { name => 'hostname2' },
"password:s@" => { name => 'password' }, 'password:s' => { name => 'password' },
"timeout:s@" => { name => 'timeout' }, 'timeout:s' => { name => 'timeout' }
"show-output:s" => { name => 'show_output' },
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'SMCLI OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'SMCLI OPTIONS', once => 1);
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{custommode_name} = $options{custommode_name}; $self->{custommode_name} = $options{custommode_name};
# 1 means we use a file to read # 1 means we use a file to read
$self->{no_smclicmd} = 0; $self->{no_smclicmd} = 0;
return $self; return $self;
} }
# Method to manage multiples # Method to manage multiples
sub set_options { sub set_options {
my ($self, %options) = @_; my ($self, %options) = @_;
# options{options_result}
$self->{option_results} = $options{option_results}; $self->{option_results} = $options{option_results};
} }
# Method to manage multiples sub set_defaults {}
sub set_defaults {
sub default_command {
my ($self, %options) = @_; my ($self, %options) = @_;
# options{default}
return 'SMcli';
# Manage default value }
foreach (keys %{$options{default}}) {
if ($_ eq $self->{custommode_name}) { sub default_command_path {
if (ref($options{default}->{$_}) eq 'ARRAY') { my ($self, %options) = @_;
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) { return '/opt/IBM_DS/client';
if (!defined($self->{option_results}->{$opt}[$i])) { }
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
} sub check_options {
} my ($self, %options) = @_;
}
} $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{hostname2} = (defined($self->{option_results}->{hostname2})) ? $self->{option_results}->{hostname2} : undef;
if (ref($options{default}->{$_}) eq 'HASH') { $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
foreach my $opt (keys %{$options{default}->{$_}}) { $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
if (!defined($self->{option_results}->{$opt})) { $self->{extra_options} = (defined($self->{option_results}->{extra_options})) ? $self->{option_results}->{extra_options} : '-quick -S';
$self->{option_results}->{$opt} = $options{default}->{$_}->{$opt}; $self->{special_arg} = (defined($self->{option_results}->{special_arg})) ? $self->{option_results}->{special_arg} : undef;
} $self->{sudo} = $self->{option_results}->{sudo};
}
} if ($self->{hostname} eq '') {
} $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.');
} $self->{output}->option_exit();
}
$self->{extra_options} = centreon::plugins::misc::sanitize_command_param(value => $self->{extra_options});
$self->{special_arg} = centreon::plugins::misc::sanitize_command_param(value => $self->{special_arg});
$self->{hostname} = centreon::plugins::misc::sanitize_command_param(value => $self->{hostname});
$self->{hostname2} = centreon::plugins::misc::sanitize_command_param(value => $self->{hostname2});
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{smcli_command},
command_path => $self->{option_results}->{smcli_path}
);
$self->{option_results}->{smcli_command} = $self->default_command()
if (!defined($self->{option_results}->{smcli_command}) || $self->{option_results}->{smcli_command} eq '');
$self->{option_results}->{smcli_path} = $self->default_command_path()
if (!defined($self->{option_results}->{smcli_path}) || $self->{option_results}->{smcli_path} eq '');
$self->build_command();
return 0;
} }
sub build_command { sub build_command {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{cmd} = ''; $self->{cmd} = '';
$self->{cmd} .= $self->{option_results}->{smcli_path} . '/' if (defined($self->{option_results}->{smcli_path})); $self->{cmd} .= $self->{option_results}->{smcli_path} . '/' if (defined($self->{option_results}->{smcli_path}));
$self->{cmd} .= $self->{option_results}->{smcli_command}; $self->{cmd} .= $self->{option_results}->{smcli_command};
if (defined($self->{special_arg}) && $self->{special_arg} ne '') { if (defined($self->{special_arg}) && $self->{special_arg} ne '') {
$self->{cmd} .= ' ' . $self->{special_arg}; $self->{cmd} .= ' ' . $self->{special_arg};
$self->{no_smclicmd} = 1; $self->{no_smclicmd} = 1;
# It's ok if we use a file. # It's ok if we use a file.
return ; return ;
} }
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
$self->{output}->option_exit();
}
$self->{cmd} .= " " . $self->{hostname}; $self->{cmd} .= " " . $self->{hostname};
$self->{cmd} .= " " . $self->{hostname2} if (defined($self->{hostname2})); $self->{cmd} .= " " . $self->{hostname2} if (defined($self->{hostname2}));
$self->{cmd} .= " -p '" . $self->{password} . "'" if (defined($self->{password})); $self->{cmd} .= " -p '" . $self->{password} . "'" if (defined($self->{password}));
$self->{cmd} .= " " . $self->{extra_options} if (defined($self->{extra_options})); $self->{cmd} .= " " . $self->{extra_options} if (defined($self->{extra_options}));
} }
sub check_options {
my ($self, %options) = @_;
# return 1 = ok still hostname
# return 0 = no hostname left
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef;
$self->{hostname2} = (defined($self->{option_results}->{hostname2})) ? shift(@{$self->{option_results}->{hostname2}}) : undef;
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 30;
$self->{extra_options} = (defined($self->{option_results}->{extra_options})) ? shift(@{$self->{option_results}->{extra_options}}) : '-quick -S';
$self->{special_arg} = (defined($self->{option_results}->{special_arg})) ? shift(@{$self->{option_results}->{special_arg}}) : undef;
$self->{sudo} = $self->{option_results}->{sudo};
$self->build_command();
if (!defined($self->{hostname}) ||
scalar(@{$self->{option_results}->{hostname}}) == 0) {
return 0;
}
return 1;
}
##############
# Specific methods
##############
sub execute_command { sub execute_command {
my ($self, %options) = @_; my ($self, %options) = @_;
if ($self->{no_smclicmd} == 0) { if ($self->{no_smclicmd} == 0) {
$self->{cmd} .= " -c '" . $options{cmd} . "'"; $self->{cmd} .= " -c '" . $options{cmd} . "'";
} }
# Need to set timeout over command.
$self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{timeout} = $self->{timeout};
my ($response, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, my ($response, $exit_code) = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
sudo => $self->{sudo}, options => $self->{option_results},
command => $self->{cmd}, sudo => $self->{sudo},
command_path => undef, command => $self->{cmd},
command_options => undef, command_path => undef,
no_quit => 1 command_options => undef,
); no_quit => 1
);
if ($exit_code != 0) { if ($exit_code != 0) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(
short_msg => "Command execution error (verbose mode for more details)"); severity => 'UNKNOWN',
short_msg => "Command execution error (verbose mode for more details)"
);
$self->{output}->output_add(long_msg => $response); $self->{output}->output_add(long_msg => $response);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -31,7 +31,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"storage-command:s" => { name => 'storage_command', }, 'storage-command:s' => { name => 'storage_command' }
}); });
return $self; return $self;
@ -49,13 +49,17 @@ sub run {
my $response = $smcli->execute_command(cmd => $self->{option_results}->{storage_command}); my $response = $smcli->execute_command(cmd => $self->{option_results}->{storage_command});
# IBM smcli: Storage Subsystem health status = optimal. # IBM smcli: Storage Subsystem health status = optimal.
# Dell smcli: Storage array health status = optimal. # Dell smcli: Storage array health status = optimal.
my $match_ok_regexp = 'health status.*optimal'; my $match_ok_regexp = 'health status.*optimal';
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => sprintf("storage health status is optimal")); severity => 'OK',
short_msg => sprintf("storage health status is optimal")
);
if ($response !~ /$match_ok_regexp/msi) { if ($response !~ /$match_ok_regexp/msi) {
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->output_add(
short_msg => sprintf("Some failures have been found (verbose mode for more details)")); severity => 'CRITICAL',
short_msg => sprintf("Some failures have been found (verbose mode for more details)")
);
$self->{output}->output_add(long_msg => $response); $self->{output}->output_add(long_msg => $response);
} }

View File

@ -632,6 +632,22 @@ sub slurp_file {
return $content; return $content;
} }
sub sanitize_command_param {
my (%options) = @_;
return if (!defined($options{value}));
$options{value} =~ s/[`;!&|]//g;
return $options{value};
}
my $security_file = '/etc/centreon-plugins/security.json';
my $whitelist_file = '/etc/centreon-plugins/whitelist.json';
if ($^O eq 'MSWin32') {
$security_file = 'C:/Program Files/centreon-plugins/security.json';
$whitelist_file = 'C:/Program Files/centreon-plugins/whitelist.json';
}
sub check_security_command { sub check_security_command {
my (%options) = @_; my (%options) = @_;
@ -641,11 +657,6 @@ sub check_security_command {
(defined($options{command_path}) && $options{command_path} ne '')) (defined($options{command_path}) && $options{command_path} ne ''))
); );
my $security_file = '/etc/centreon-plugins/security.json';
if ($^O eq 'MSWin32') {
$security_file = 'C:/Program Files/centreon-plugins/security.json';
}
return 0 if (! -r "$security_file" || -z "$security_file"); return 0 if (! -r "$security_file" || -z "$security_file");
my $content = slurp_file(output => $options{output}, file => $security_file); my $content = slurp_file(output => $options{output}, file => $security_file);
@ -667,6 +678,65 @@ sub check_security_command {
return 0; return 0;
} }
sub check_security_whitelist {
my (%options) = @_;
my $command = $options{command};
$command = $options{command_path} . '/' . $options{command} if (defined($options{command_path}) && $options{command_path} ne '');
$command .= ' ' . $options{command_options} if (defined($options{command_options}) && $options{command_options} ne '');
return 0 if (! -r "$security_file" || -z "$security_file");
my $content = slurp_file(output => $options{output}, file => $security_file);
my $security;
eval {
$security = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$options{output}->add_option_msg(short_msg => 'Cannot decode security file content');
$options{output}->option_exit();
}
return 0 if (!defined($security->{whitelist_enabled}) || $security->{whitelist_enabled} !~ /^(?:1|true)$/i);
if (! -r "$whitelist_file") {
$options{output}->add_option_msg(short_msg => 'Cannot read whitelist security file content');
$options{output}->option_exit();
}
if (-z "$whitelist_file") {
$options{output}->add_option_msg(short_msg => 'Cannot execute command (security)');
$options{output}->option_exit();
}
$content = slurp_file(output => $options{output}, file => $whitelist_file);
my $whitelist;
eval {
$whitelist = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$options{output}->add_option_msg(short_msg => 'Cannot decode whitelist security file content');
$options{output}->option_exit();
}
my $matched = 0;
foreach (@$whitelist) {
if ($command =~ /$_/) {
$matched = 1;
last;
}
}
if ($matched == 0) {
$options{output}->add_option_msg(short_msg => 'Cannot execute command (security)');
$options{output}->option_exit();
}
return 0;
}
1; 1;
__END__ __END__

View File

@ -100,7 +100,6 @@ sub get_identifier {
sub execute_command { sub execute_command {
my ($self, %options) = @_; my ($self, %options) = @_;
my $timeout = $self->{timeout}; my $timeout = $self->{timeout};
if (!defined($timeout)) { if (!defined($timeout)) {
$timeout = defined($options{timeout}) ? $options{timeout} : 45; $timeout = defined($options{timeout}) ? $options{timeout} : 45;
@ -157,7 +156,7 @@ my ssh
=item B<--hostname> =item B<--hostname>
Hostname to query. Hostname to query in ssh.
=item B<--timeout> =item B<--timeout>

View File

@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::hardware);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub set_system { sub set_system {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -46,14 +45,10 @@ sub set_system {
sub cmd_execute { sub cmd_execute {
my ($self, %options) = @_; my ($self, %options) = @_;
($self->{stdout}) = centreon::plugins::misc::execute( my ($stdout) = $options{custom}->execute_command(
output => $self->{output}, command => 'ctconf',
options => $self->{option_results}, command_options => '-v'
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
); );
$self->{stdout} =~ s/\r//msg; $self->{stdout} =~ s/\r//msg;
@ -63,9 +58,19 @@ sub cmd_execute {
$fm_status = $1 if ($self->{stdout} =~ /^FM Status\s+:\s+(.*?)\s*\n/msi); $fm_status = $1 if ($self->{stdout} =~ /^FM Status\s+:\s+(.*?)\s*\n/msi);
$transport_mode = $1 if ($self->{stdout} =~ /^Transport Mode\s+:\s+(.*?)\s*\n/msi); $transport_mode = $1 if ($self->{stdout} =~ /^Transport Mode\s+:\s+(.*?)\s*\n/msi);
$security_mode = $1 if ($self->{stdout} =~ /^Security Mode\s+:\s+(.*?)\s*\n/msi); $security_mode = $1 if ($self->{stdout} =~ /^Security Mode\s+:\s+(.*?)\s*\n/msi);
$self->{output}->output_add(long_msg => sprintf("model: %s, firmware version: %s", $model, $firmware)); $self->{output}->output_add(
$self->{output}->output_add(long_msg => sprintf("fm status: '%s', transport mode: '%s', security mode: '%s'", long_msg => sprintf(
$fm_status, $transport_mode, $security_mode)); "model: %s, firmware version: %s",
$model,
$firmware
)
);
$self->{output}->output_add(
long_msg => sprintf(
"fm status: '%s', transport mode: '%s', security mode: '%s'",
$fm_status, $transport_mode, $security_mode
)
);
} }
sub display { sub display {
@ -82,39 +87,11 @@ 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' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options' }
});
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'ctconf'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_options} = '-v'
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
}
1; 1;
__END__ __END__
@ -123,11 +100,13 @@ __END__
Check HSM hardware status. Check HSM hardware status.
Command used: 'ctconf -v'
=over 8 =over 8
=item B<--component> =item B<--component>
Which component to check (Default: '.*'). Which component to check.
Can be: 'hwstatus', 'temperature', 'memory'. Can be: 'hwstatus', 'temperature', 'memory'.
=item B<--filter> =item B<--filter>
@ -150,48 +129,6 @@ Example: --warning='temperature,.*,50'
Set critical threshold for 'temperature', 'memory' (syntax: type,regexp,threshold) Set critical threshold for 'temperature', 'memory' (syntax: type,regexp,threshold)
Example: --critical='temperature,.*,60' Example: --critical='temperature,.*,60'
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52").
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'ctconf').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '').
=item B<--command-options>
Command options (Default: '-v').
=back =back
=cut =cut

View File

@ -22,17 +22,18 @@ package hardware::devices::safenet::hsm::protecttoolkit::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = ( 'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware'
'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware', };
);
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self; return $self;
} }

View File

@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub prefix_device_output { sub prefix_device_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -44,38 +43,38 @@ sub set_counters {
key_values => [ { name => 'humidity' }, { name => 'display' } ], key_values => [ { name => 'humidity' }, { name => 'display' } ],
output_template => 'Humidity: %.2f%%', output_template => 'Humidity: %.2f%%',
perfdatas => [ perfdatas => [
{ label => 'humidity', value => 'humidity', template => '%.2f', { label => 'humidity', template => '%.2f',
unit => '%', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => '%', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
}, }
}, },
{ label => 'temperature', set => { { label => 'temperature', set => {
key_values => [ { name => 'temperature' }, { name => 'dewpoint' }, { name => 'display' } ], key_values => [ { name => 'temperature' }, { name => 'dewpoint' }, { name => 'display' } ],
output_template => 'Temperature: %.2f C', output_template => 'Temperature: %.2f C',
perfdatas => [ perfdatas => [
{ label => 'temperature', value => 'temperature', template => '%.2f', { label => 'temperature', template => '%.2f',
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
}, }
}, },
{ label => 'dew-point', set => { { label => 'dew-point', set => {
key_values => [ { name => 'dewpoint' }, { name => 'display' } ], key_values => [ { name => 'dewpoint' }, { name => 'display' } ],
output_template => 'Dew Point : %.2f C', output_template => 'Dew Point : %.2f C',
perfdatas => [ perfdatas => [
{ label => 'dew_point', value => 'dewpoint', template => '%.2f', { label => 'dew_point', template => '%.2f',
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'delta', set => { { label => 'delta', set => {
key_values => [ { name => 'delta' }, { name => 'display' } ], key_values => [ { name => 'delta' }, { name => 'display' } ],
output_template => 'Delta (Temp - Dew) : %.2f C', output_template => 'Delta (Temp - Dew) : %.2f C',
perfdatas => [ perfdatas => [
{ label => 'delta', value => 'delta', template => '%.2f', { label => 'delta', template => '%.2f',
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -85,51 +84,21 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"remote" => { name => 'remote' }, 'filter-drive:s' => { name => 'filter_drive', default => '.*' }
"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-drive:s" => { name => 'filter_drive', default => '.*' }
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
centreon::plugins::misc::check_security_command(
output => $self->{output},
command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options},
command_path => $self->{option_results}->{command_path}
);
$self->{option_results}->{command} = 'tempered'
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
$self->{option_results}->{command_path} = '/opt/PCsensor/TEMPered/utils/'
if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq '');
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{drive} = {}; my ($stdout) = $options{custom}->execute_command(
my $stdout = centreon::plugins::misc::execute( command => 'tempered',
output => $self->{output}, command_path => '/opt/PCsensor/TEMPered/utils'
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
); );
$self->{drive} = {};
foreach (split(/\n/, $stdout)) { foreach (split(/\n/, $stdout)) {
next if !/(\/dev\/[a-z0-9]+).*temperature\s(\d*\.?\d+).*relative\shumidity\s(\d*\.?\d+).*dew\spoint\s(\d*\.?\d+)/; next if !/(\/dev\/[a-z0-9]+).*temperature\s(\d*\.?\d+).*relative\shumidity\s(\d*\.?\d+).*dew\spoint\s(\d*\.?\d+)/;
my ($drive, $temp, $hum, $dew) = ($1, $2, $3, $4); my ($drive, $temp, $hum, $dew) = ($1, $2, $3, $4);
@ -149,60 +118,19 @@ __END__
=head1 MODE =head1 MODE
Check metrics from TemPerHum sensors Check metrics from TemPerHum sensors.
Command used: '/opt/PCsensor/TEMPered/utils/tempered'
=over 8 =over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'tempered').
Can be changed if you have output in a file.
=item B<--command-path>
Command path (Default: '/usr/sbin').
=item B<--command-options>
Command options (Default: '-u').
=item B<--filter-drive> =item B<--filter-drive>
Filter by drive name (e.g --filter-drive raw4) Filter by drive name (e.g --filter-drive raw4)
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold Warning
Can be: 'temperature', 'humidity', 'dew-point', 'delta'
=item B<--critical-*> Thresholds.
Threshold Critical
Can be: 'temperature', 'humidity', 'dew-point', 'delta' Can be: 'temperature', 'humidity', 'dew-point', 'delta'
=back =back

View File

@ -22,15 +22,17 @@ package hardware::sensors::temperhum::local::plugin;
use strict; use strict;
use warnings; use warnings;
use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
$self->{version} = '0.1';
%{$self->{modes}} = ( $self->{modes} = {
'environment' => 'hardware::sensors::temperhum::local::mode::environment', 'environment' => 'hardware::sensors::temperhum::local::mode::environment'
); };
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
return $self;} return $self;}
1; 1;
@ -39,6 +41,6 @@ __END__
=head1 PLUGIN DESCRIPTION =head1 PLUGIN DESCRIPTION
Check temperature, humidity and dew point for TemPerHum Sensors (the plugin can use SSH). Check temperature, humidity and dew point for TemPerHum Sensors (the plugin can use SSH).
=cut =cut

View File

@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
@ -50,20 +51,40 @@ sub check_options {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{manage_returns} = {}; $self->{expressions} = [];
foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) { foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
next if (!($entry =~ /(.*?),(.*?),(.*)/)); next if (!($entry =~ /(.*?),(.*?),(.*)/));
next if (!$self->{output}->is_litteral_status(status => $2)); next if (!$self->{output}->is_litteral_status(status => $2));
if ($1 ne '') { my ($expr, $rv, $msg) = ($1, $2, $3);
$self->{manage_returns}->{$1} = {return => $2, msg => $3};
if ($expr ne '') {
if ($expr =~ /^\s*([0-9]+)\s*$/) {
push @{$self->{expressions}}, { test => "%(code) == $1", rv => $rv, msg => $msg };
} else {
push @{$self->{expressions}}, { test => $expr, rv => $rv, msg => $msg };
}
} else { } else {
$self->{manage_returns}->{default} = {return => $2, msg => $3}; $self->{expression_default} = { rv => $rv, msg => $msg };
} }
} }
if ($self->{option_results}->{manage_returns} eq '' || scalar(keys %{$self->{manage_returns}}) == 0) {
$self->{output}->add_option_msg(short_msg => "Need to specify manage-returns option correctly."); if ($self->{option_results}->{manage_returns} eq '' ||
$self->{output}->option_exit(); (scalar(@{$self->{expressions}}) == 0 && !defined($self->{expression_default}))) {
$self->{output}->add_option_msg(short_msg => "Need to specify manage-returns option correctly.");
$self->{output}->option_exit();
} }
for (my $i = 0; $i < scalar(@{$self->{expressions}}); $i++) {
$self->{expressions}->[$i]->{test} =~ s/%\{(.*?)\}/\$values->{$1}/g;
$self->{expressions}->[$i]->{test} =~ s/%\((.*?)\)/\$values->{$1}/g;
}
centreon::plugins::misc::check_security_whitelist(
output => $self->{output},
command => $self->{option_results}->{exec_command},
command_path => $self->{option_results}->{exec_command_path},
command_options => $self->{option_results}->{exec_command_options}
);
} }
sub run { sub run {
@ -79,24 +100,32 @@ sub run {
my $long_msg = $stdout; my $long_msg = $stdout;
$long_msg =~ s/\|/~/mg; $long_msg =~ s/\|/~/mg;
$self->{output}->output_add(long_msg => $long_msg); $self->{output}->output_add(long_msg => $long_msg);
if (defined($self->{manage_returns}->{$exit_code})) { my $matched = 0;
my $values = { code => $exit_code, output => $stdout };
foreach (@{$self->{expressions}}) {
if ($self->{output}->test_eval(test => $_->{test}, values => $values)) {
$self->{output}->output_add(
severity => $_->{rv},
short_msg => $_->{msg}
);
$matched = 1;
last;
}
}
if ($matched == 0 && defined($self->{expression_default})) {
$self->{output}->output_add( $self->{output}->output_add(
severity => $self->{manage_returns}->{$exit_code}->{return}, severity => $self->{expression_default}->{rv},
short_msg => $self->{manage_returns}->{$exit_code}->{msg} short_msg => $self->{expression_default}->{msg}
); );
} elsif (defined($self->{manage_returns}->{default})) { } elsif ($matched == 0) {
$self->{output}->output_add( $self->{output}->output_add(
severity => $self->{manage_returns}->{default}->{return}, severity => 'UNKNOWN',
short_msg => $self->{manage_returns}->{default}->{msg} short_msg => "Command exit code ($exit_code)"
);
} else {
$self->{output}->output_add(
severity => 'UNKNWON',
short_msg => 'Exit code from command'
); );
} }
if (defined($exit_code)) { if (defined($exit_code)) {
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
nlabel => 'command.exit.code.count', nlabel => 'command.exit.code.count',
@ -121,7 +150,7 @@ Check command returns.
=item B<--manage-returns> =item B<--manage-returns>
Set action according command exit code. Set action according command exit code.
Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem Example: %(code) == 0,OK,File xxx exist#%(code) == 1,CRITICAL,File xxx not exist#,UNKNOWN,Command problem
=item B<--separator> =item B<--separator>

View File

@ -24,13 +24,14 @@ use base qw(centreon::plugins::mode);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'exec-command:s' => { name => 'exec_command' }, 'exec-command:s' => { name => 'exec_command' },
'exec-command-path:s' => { name => 'exec_command_path' }, 'exec-command-path:s' => { name => 'exec_command_path' },
'exec-command-options:s' => { name => 'exec_command_options' }, 'exec-command-options:s' => { name => 'exec_command_options' },
@ -77,6 +78,13 @@ sub check_options {
$self->{expressions}->[$i]->{test} =~ s/%\{(.*?)\}/\$values->{$1}/g; $self->{expressions}->[$i]->{test} =~ s/%\{(.*?)\}/\$values->{$1}/g;
$self->{expressions}->[$i]->{test} =~ s/%\((.*?)\)/\$values->{$1}/g; $self->{expressions}->[$i]->{test} =~ s/%\((.*?)\)/\$values->{$1}/g;
} }
centreon::plugins::misc::check_security_whitelist(
output => $self->{output},
command => $self->{option_results}->{exec_command},
command_path => $self->{option_results}->{exec_command_path},
command_options => $self->{option_results}->{exec_command_options}
);
} }
sub run { sub run {
@ -92,7 +100,7 @@ sub run {
my $long_msg = $stdout; my $long_msg = $stdout;
$long_msg =~ s/\|/~/mg; $long_msg =~ s/\|/~/mg;
$self->{output}->output_add(long_msg => $long_msg); $self->{output}->output_add(long_msg => $long_msg);
my $matched = 0; my $matched = 0;
my $values = { code => $exit_code, output => $stdout }; my $values = { code => $exit_code, output => $stdout };
foreach (@{$self->{expressions}}) { foreach (@{$self->{expressions}}) {

View File

@ -0,0 +1,42 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::dell::MD3000::cli::custom::cli;
use base qw(centreon::common::smcli::custom::custom);
use strict;
use warnings;
sub default_command {
my ($self, %options) = @_;
return 'SMcli';
}
sub default_command_path {
my ($self, %options) = @_;
return '/opt/dell/mdstoragemanager/client';
}
1;
__END__

View File

@ -25,27 +25,21 @@ use warnings;
use base qw(centreon::plugins::script_custom); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = ( 'health-status' => 'centreon::common::smcli::mode::healthstatus'
'health-status' => 'centreon::common::smcli::mode::healthstatus', };
);
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom'; $self->{custom_modes}->{smcli} = 'storage::dell::MD3000::cli::custom::cli';
$self->{default} = { $self->{default} = {
'health-status' => { 'health-status' => {
storage_command => 'show storageArray healthstatus;', storage_command => 'show storageArray healthstatus;',
} }
}; };
$self->{customdefault} = {
'smcli' => {
smcli_path => '/opt/dell/mdstoragemanager/client',
}
};
return $self; return $self;
} }

View File

@ -26,27 +26,20 @@ use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = ( 'health-status' => 'centreon::common::smcli::mode::healthstatus'
'health-status' => 'centreon::common::smcli::mode::healthstatus', };
); $self->{custom_modes}->{smcli} = 'centreon::common::smcli::custom::custom';
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom';
$self->{default} = { $self->{default} = {
'health-status' => { 'health-status' => {
storage_command => 'show storageSubsystem healthstatus;', storage_command => 'show storageSubsystem healthstatus;',
} }
}; };
$self->{customdefault} = {
'smcli' => {
smcli_path => '/opt/IBM_DS/client',
}
};
return $self; return $self;
} }

View File

@ -25,27 +25,20 @@ use warnings;
use base qw(centreon::plugins::script_custom); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = ( 'health-status' => 'centreon::common::smcli::mode::healthstatus'
'health-status' => 'centreon::common::smcli::mode::healthstatus', };
); $self->{custom_modes}->{smcli} = 'centreon::common::smcli::custom::custom';
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom';
$self->{default} = { $self->{default} = {
'health-status' => { 'health-status' => {
storage_command => 'show storageSubsystem healthstatus;', storage_command => 'show storageSubsystem healthstatus;',
} }
}; };
$self->{customdefault} = {
'smcli' => {
smcli_path => '/opt/IBM_DS/client',
}
};
return $self; return $self;
} }

View File

@ -25,28 +25,21 @@ use warnings;
use base qw(centreon::plugins::script_custom); use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{modes} = {
%{$self->{modes}} = (
'health-status' => 'centreon::common::smcli::mode::healthstatus', 'health-status' => 'centreon::common::smcli::mode::healthstatus',
); };
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom'; $self->{custom_modes}->{smcli} = 'centreon::common::smcli::custom::custom';
$self->{default} = { $self->{default} = {
'health-status' => { 'health-status' => {
storage_command => 'show storageSubsystem healthstatus;', storage_command => 'show storageSubsystem healthstatus;',
} }
}; };
$self->{customdefault} = {
'smcli' => {
smcli_path => '/opt/IBM_DS/client',
}
};
return $self; return $self;
} }