security - add method to block command override batch 2 (#4054)
This commit is contained in:
parent
057a0a43f4
commit
dbab4c8b41
|
@ -69,7 +69,7 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'update', type => 0, message_separator => ' - ' },
|
||||
{ name => 'update', type => 0, message_separator => ' - ' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{update} = [
|
||||
|
@ -101,23 +101,13 @@ sub new {
|
|||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'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' },
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'nameservers:s@' => { name => 'nameservers' },
|
||||
'maindb-file:s' => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' },
|
||||
'dailydb-file:s' => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' }
|
||||
});
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -125,14 +115,8 @@ 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->{clamav_command} = 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file};
|
||||
$self->{option_results}->{maindb_file} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{maindb_file});
|
||||
$self->{option_results}->{dailydb_file} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{dailydb_file});
|
||||
}
|
||||
|
||||
sub get_clamav_last_update {
|
||||
|
@ -180,7 +164,7 @@ sub get_clamav_current_signature_info {
|
|||
second => 0,
|
||||
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) = @_;
|
||||
|
||||
$self->get_clamav_last_update();
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{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
|
||||
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file}
|
||||
);
|
||||
|
||||
#==== CLAMD ===
|
||||
#ClamAV 0.99.2/21723/Mon Jun 13 14:53:00 2016
|
||||
#==== DAILY ====
|
||||
|
@ -245,6 +226,8 @@ __END__
|
|||
|
||||
Check antivirus update status.
|
||||
|
||||
Command used: 'clamd -V ; sigtool --info %(dailydb-file) ; sigtool --info %(maindb-file)'
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--nameservers>
|
||||
|
@ -252,46 +235,6 @@ Check antivirus update status.
|
|||
Set nameserver to query (can be multiple).
|
||||
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>
|
||||
|
||||
Antivirus main.cvd file (Default: '/var/lib/clamav/main.cvd').
|
||||
|
|
|
@ -22,18 +22,19 @@ package apps::antivirus::clamav::local::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
$self->{modes} = {
|
||||
'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus',
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -61,6 +61,9 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$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 {
|
||||
|
|
|
@ -42,6 +42,8 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
$self->{option_results}->{host_pattern} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{host_pattern});
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
|
|
@ -31,18 +31,8 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$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' },
|
||||
"filter-name:s" => { name => 'filter_name' }
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -51,20 +41,6 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %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 {
|
||||
|
@ -76,8 +52,10 @@ sub run {
|
|||
$self->{output}->output_add(long_msg => "'" . $_ . "' [type = " . $self->{vtl}->{$_}->{type} . "]");
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List VTL:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List VTL:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -93,21 +71,21 @@ sub disco_show {
|
|||
|
||||
$self->manage_selection(%options);
|
||||
foreach (sort keys %{$self->{vtl}}) {
|
||||
$self->{output}->add_disco_entry(name => $_,
|
||||
active => $self->{vtl}->{$_}->{type}
|
||||
);
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $_,
|
||||
active => $self->{vtl}->{$_}->{type}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
|
||||
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});
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'vtconfig',
|
||||
command_options => '-l',
|
||||
command_path => '/quadstorvtl/bin'
|
||||
);
|
||||
|
||||
#Name DevType Type
|
||||
#BV00002 VTL IBM IBM System Storage TS3100
|
||||
|
@ -136,49 +114,10 @@ __END__
|
|||
|
||||
List VTL.
|
||||
|
||||
Command used: '/quadstorvtl/bin/vtconfig -l'
|
||||
|
||||
=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>
|
||||
|
||||
Filter vtl name (can be a regexp).
|
||||
|
|
|
@ -25,21 +25,12 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = '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;
|
||||
return 'status : ' . $self->{result_values}->{status};
|
||||
}
|
||||
|
||||
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_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
my $msg = sprintf(
|
||||
"Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
@ -123,12 +116,11 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$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' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'usage', set => {
|
||||
|
@ -136,7 +128,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
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-options:s" => { name => 'command_options' },
|
||||
"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' },
|
||||
});
|
||||
|
@ -168,37 +158,13 @@ sub new {
|
|||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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}
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'bdconfig',
|
||||
command_options => '-l -c',
|
||||
command_path => '/quadstorvtl/bin'
|
||||
);
|
||||
|
||||
$self->{disk} = {};
|
||||
|
@ -241,49 +207,10 @@ __END__
|
|||
|
||||
Check vtl disk usage.
|
||||
|
||||
Command used: '/quadstorvtl/bin/bdconfig -l -c'
|
||||
|
||||
=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>
|
||||
|
||||
Filter tape name.
|
||||
|
|
|
@ -104,9 +104,9 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_frozen_calc'),
|
||||
closure_custom_output => $self->can('custom_frozen_output'),
|
||||
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);
|
||||
bless $self, $class;
|
||||
|
||||
$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' }
|
||||
});
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
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 {
|
||||
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'));
|
||||
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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}
|
||||
);
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'impexp',
|
||||
command_options => '-l',
|
||||
command_path => '/quadstorvtl/bin'
|
||||
);
|
||||
|
||||
$self->{jobs}->{global} = { job => {} };
|
||||
#JobID Type Source State Transfer Elapsed
|
||||
#252 Import 701831L2 Error 36.00 GB 572
|
||||
|
@ -171,7 +139,7 @@ sub manage_selection {
|
|||
#254 Export 701850L2 Completed 16.05 GB 1072
|
||||
#255 Export 701854L2 Completed 6.31 GB 142
|
||||
my $current_time = time();
|
||||
my @lines = split /\n/, $stdout;
|
||||
my @lines = split(/\n/, $stdout);
|
||||
shift @lines;
|
||||
foreach (@lines) {
|
||||
next if (! /^(\d+)\s+\S+\s+(\S+)\s+(\S+)\s+([0-9\.]+)\s+\S+\s+(\d+)/);
|
||||
|
@ -202,49 +170,10 @@ __END__
|
|||
|
||||
Check job status.
|
||||
|
||||
Command used: '/quadstorvtl/bin/impexp -l'
|
||||
|
||||
=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>
|
||||
|
||||
Set warning threshold for status (Default: none)
|
||||
|
|
|
@ -25,21 +25,12 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = '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;
|
||||
return 'status : ' . $self->{result_values}->{status};
|
||||
}
|
||||
|
||||
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_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
my $msg = sprintf(
|
||||
"Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
@ -109,6 +102,12 @@ sub custom_usage_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_tape_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Tape '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -122,20 +121,18 @@ sub set_counters {
|
|||
key_values => [ { name => 'count' } ],
|
||||
output_template => 'Number of tapes : %s',
|
||||
perfdatas => [
|
||||
{ label => 'count', value => 'count', template => '%s',
|
||||
unit => 'tapes', min => 0 },
|
||||
],
|
||||
{ label => 'count', template => '%s', unit => 'tapes', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$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' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'usage', set => {
|
||||
|
@ -143,9 +140,9 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
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);
|
||||
bless $self, $class;
|
||||
|
||||
$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' },
|
||||
'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' },
|
||||
$options{options}->add_options(arguments => {
|
||||
'vtl-name:s' => { name => 'vtl_name' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -185,40 +170,16 @@ sub check_options {
|
|||
$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} = '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} . "' ";
|
||||
$self->{option_results}->{vtl_name} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{vtl_name});
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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}
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'vcconfig',
|
||||
command_options => '-l -v ' . $self->{option_results}->{vtl_name},
|
||||
command_path => '/quadstorvtl/bin'
|
||||
);
|
||||
|
||||
$self->{global}->{count} = 0;
|
||||
|
@ -249,7 +210,7 @@ sub manage_selection {
|
|||
display => $name,
|
||||
total => $size * 1024 * 1024 * 1024,
|
||||
used_prct => $used_prct,
|
||||
status => $status,
|
||||
status => $status
|
||||
};
|
||||
$self->{global}->{count}++;
|
||||
}
|
||||
|
@ -268,49 +229,10 @@ __END__
|
|||
|
||||
Check vtl tape usage.
|
||||
|
||||
Command used: '/quadstorvtl/bin/vcconfig -l -v %(vtl-name)'
|
||||
|
||||
=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>
|
||||
|
||||
Set VTL name (Required).
|
||||
|
@ -337,14 +259,9 @@ Can used special variables like: %{status}, %{display}
|
|||
Set critical threshold for status (Default: '%{status} !~ /active/i').
|
||||
Can used special variables like: %{status}, %{display}
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'count', 'usage'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Thresholds.
|
||||
Can be: 'count', 'usage'.
|
||||
|
||||
=back
|
||||
|
|
|
@ -22,20 +22,21 @@ package apps::backup::quadstor::local::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
$self->{modes} = {
|
||||
'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl',
|
||||
'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage',
|
||||
'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus',
|
||||
'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage',
|
||||
);
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
|
@ -20,55 +20,27 @@
|
|||
|
||||
package apps::backup::tsm::local::custom::api;
|
||||
|
||||
use base qw(centreon::plugins::script_custom::cli);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
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 => {
|
||||
'tsm-hostname:s' => { name => 'tsm_hostname' },
|
||||
'tsm-username:s' => { name => 'tsm_username' },
|
||||
'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_options(arguments => {
|
||||
'tsm-hostname:s' => { name => 'tsm_hostname' },
|
||||
'tsm-username:s' => { name => 'tsm_username' },
|
||||
'tsm-password:s' => { name => 'tsm_password' }
|
||||
});
|
||||
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'TSM CLI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
sub set_defaults {}
|
||||
|
||||
sub check_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}->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;
|
||||
}
|
||||
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -122,27 +68,26 @@ sub get_tsm_id {
|
|||
|
||||
sub execute_command {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->tsm_build_options(%options);
|
||||
my ($response, $exit_code) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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},
|
||||
|
||||
my $command = 'dsmadmc';
|
||||
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}\"";;
|
||||
|
||||
my ($stdout, $exit_code) = $self->SUPER::execute_command(
|
||||
%options,
|
||||
command => $command,
|
||||
command_options => $command_options,
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
|
||||
# 11 is for: ANR2034E SELECT: No match found using this criteria.
|
||||
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}->option_exit();
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => $response, debug => 1);
|
||||
return $response;
|
||||
|
||||
$self->{output}->output_add(long_msg => $stdout, debug => 1);
|
||||
return $stdout;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -173,42 +118,6 @@ TSM username (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
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
|
@ -29,7 +29,6 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{modes} = {
|
||||
'actlog' => 'apps::backup::tsm::local::mode::actlog',
|
||||
'drives' => 'apps::backup::tsm::local::mode::drives',
|
||||
|
@ -38,7 +37,7 @@ sub new {
|
|||
'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;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::ssh;
|
||||
use JSON;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
|
@ -43,7 +43,6 @@ sub custom_status_output {
|
|||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
sub prefix_endpoint_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -103,15 +102,13 @@ sub new {
|
|||
$options{options}->add_options(arguments => {
|
||||
'broker-stats-file:s@' => { name => 'broker_stats_file' },
|
||||
'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' },
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
$self->{ssh} = centreon::plugins::ssh->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -123,6 +120,34 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option.");
|
||||
$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 {
|
||||
|
@ -130,10 +155,7 @@ sub manage_selection {
|
|||
|
||||
$self->{endpoint} = {};
|
||||
foreach my $config (@{$self->{option_results}->{broker_stats_file}}) {
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
my ($stdout) = $self->execute_command(
|
||||
command => 'cat',
|
||||
command_options => $config
|
||||
);
|
||||
|
@ -195,25 +217,9 @@ Check Centreon Broker statistics files.
|
|||
|
||||
=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'.
|
||||
Hostname to query in ssh.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
|
@ -231,14 +237,9 @@ Specify the centreon-broker json stats file (Required). Can be multiple.
|
|||
|
||||
Filter endpoint name.
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Thresholds.
|
||||
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
|
||||
|
||||
=item B<--warning-status>
|
||||
|
|
|
@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::ssh;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
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_latency', 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') {
|
||||
|
@ -204,8 +205,8 @@ sub set_counters {
|
|||
threshold_use => $_->[0] ,
|
||||
closure_custom_output => $self->can('custom_' . $type . '_latency_output'),
|
||||
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-options:s' => { name => 'command_options' },
|
||||
'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' }
|
||||
});
|
||||
|
||||
$self->{ssh} = centreon::plugins::ssh->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -314,22 +313,49 @@ sub check_options {
|
|||
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq '');
|
||||
$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}->{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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($stdout) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
my ($stdout) = $self->execute_command(
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options}
|
||||
);
|
||||
|
||||
$self->{stats} = {};
|
||||
|
||||
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 } };
|
||||
}
|
||||
|
@ -371,40 +397,26 @@ __END__
|
|||
|
||||
Check centengine statistics.
|
||||
|
||||
Command used: '/usr/sbin/centenginestats '2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'centenginestats').
|
||||
Command to get information.
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: '/usr/sbin').
|
||||
Command path.
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '2>&1').
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
Execute command remotely in 'ssh'.
|
||||
Command options.
|
||||
|
||||
=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'.
|
||||
Hostname to query in ssh.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
|
|
|
@ -55,23 +55,23 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"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-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-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-duration:s" => { name => 'oid_duration', default => '.1.3.6.1.4.1.50000.2.7' },
|
||||
"centreon-server:s" => { name => 'centreon_server' },
|
||||
"author:s" => { name => 'author', default => 'system reboot' },
|
||||
"comment:s" => { name => 'comment', default => 'the system reboots.' },
|
||||
"duration:s" => { name => 'duration', default => 300 },
|
||||
"wait:s" => { name => 'wait' },
|
||||
"snmptrap-command:s" => { name => 'snmptrap_command', default => 'snmptrap' },
|
||||
"display-options" => { name => 'display_options' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
"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-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-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-duration:s" => { name => 'oid_duration', default => '.1.3.6.1.4.1.50000.2.7' },
|
||||
"centreon-server:s" => { name => 'centreon_server' },
|
||||
"author:s" => { name => 'author', default => 'system reboot' },
|
||||
"comment:s" => { name => 'comment', default => 'the system reboots.' },
|
||||
"duration:s" => { name => 'duration', default => 300 },
|
||||
"wait:s" => { name => 'wait' },
|
||||
"snmptrap-command:s" => { name => 'snmptrap_command', default => 'snmptrap' },
|
||||
"display-options" => { name => 'display_options' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,23 +32,15 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"remote" => { name => 'remote' },
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"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' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'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;
|
||||
}
|
||||
|
||||
|
@ -68,13 +60,21 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Please specify a scenario name.");
|
||||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
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
|
||||
$command_options .= ' -l /dev/stderr';
|
||||
|
@ -92,12 +92,10 @@ sub run {
|
|||
# Redirect result on stdout and default stdout to trash
|
||||
$command_options .= ' 2>&1 >/dev/null';
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $command_options);
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'jmeter',
|
||||
command_options => $command_options
|
||||
);
|
||||
|
||||
my $p = XML::Parser->new(NoLWP => 1);
|
||||
my $xp = XML::XPath->new(parser => $p, xml => $stdout);
|
||||
|
@ -170,29 +168,41 @@ sub run {
|
|||
my $timeelapsed = ($timing1 - $timing0) / 1000;
|
||||
my $availability = sprintf("%d", $stepOk * 100 / $step);
|
||||
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(
|
||||
value => $timeelapsed,
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
|
||||
);
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
if (!defined($first_failed_label)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed));
|
||||
$self->{output}->output_add(
|
||||
severity => $exit,
|
||||
short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed)
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $first_failed_label));
|
||||
$self->{output}->output_add(
|
||||
severity => $exit,
|
||||
short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $first_failed_label)
|
||||
);
|
||||
}
|
||||
$self->{output}->perfdata_add(label => "time", unit => 's',
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
min => 0,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
$self->{output}->perfdata_add(label => "steps",
|
||||
value => sprintf('%d', $stepOk),
|
||||
min => 0,
|
||||
max => $step);
|
||||
$self->{output}->perfdata_add(label => "availability", unit => '%',
|
||||
value => sprintf('%d', $availability),
|
||||
min => 0,
|
||||
max => 100);
|
||||
$self->{output}->perfdata_add(
|
||||
label => "time", unit => 's',
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
min => 0,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => "steps",
|
||||
value => sprintf('%d', $stepOk),
|
||||
min => 0,
|
||||
max => $step
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => "availability", unit => '%',
|
||||
value => sprintf('%d', $availability),
|
||||
min => 0,
|
||||
max => 100
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
@ -204,49 +214,15 @@ __END__
|
|||
|
||||
=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
|
||||
|
||||
=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>
|
||||
|
||||
Command extra options (default: none).
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Timeout in seconds for the command (default: 50).
|
||||
Command extra options.
|
||||
|
||||
=item B<--directory>
|
||||
|
||||
|
|
|
@ -22,17 +22,18 @@ package apps::jmeter::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'scenario' => 'apps::jmeter::mode::scenario',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'scenario' => 'apps::jmeter::mode::scenario'
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ sub new {
|
|||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'domain:s' => { name => 'domain' },
|
||||
'workstation:s' => { name => 'workstation' },
|
||||
|
@ -44,6 +44,9 @@ sub new {
|
|||
sub check_options {
|
||||
my ($self, %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 {
|
||||
|
@ -57,19 +60,25 @@ sub netdom {
|
|||
$netdom_cmd .= ' ' . Win32::NodeName();
|
||||
}
|
||||
|
||||
my ($stdout, $exit_code) = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $netdom_cmd,
|
||||
command_path => undef,
|
||||
command_options => undef,
|
||||
no_quit => 1);
|
||||
my ($stdout, $exit_code) = centreon::plugins::misc::windows_execute(
|
||||
output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $netdom_cmd,
|
||||
command_path => undef,
|
||||
command_options => undef,
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'Secure channel has been verified.');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'Secure channel has been verified.'
|
||||
);
|
||||
if ($exit_code != 0) {
|
||||
$self->{output}->output_add(long_msg => $stdout);
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => 'Secure channel had a problem (see additional info).');
|
||||
$self->{output}->output_add(
|
||||
severity => 'CRITICAL',
|
||||
short_msg => 'Secure channel had a problem (see additional info).'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,10 @@ sub check_options {
|
|||
$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;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package centreon::common::emc::navisphere::custom::custom;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::ssh;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
|
@ -37,32 +38,30 @@ sub new {
|
|||
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
|
||||
$options{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'remote' => { name => 'remote' },
|
||||
'ssh-address:s' => { name => 'ssh_address' },
|
||||
'ssh-option:s@' => { name => 'ssh_option' },
|
||||
'ssh-path:s' => { name => 'ssh_path' },
|
||||
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
|
||||
'navicli-command:s' => { name => 'navicli_command', default => 'navicli' },
|
||||
'navicli-path:s' => { name => 'navicli_path', default => '/opt/Navisphere/bin' },
|
||||
'naviseccli-command:s' => { name => 'naviseccli_command', default => 'naviseccli' },
|
||||
'naviseccli-path:s' => { name => 'naviseccli_path', default => '/opt/Navisphere/bin' },
|
||||
'sudo:s' => { name => 'sudo', },
|
||||
'special-arg:s@' => { name => 'special_arg' },
|
||||
'hostname:s@' => { name => 'hostname' },
|
||||
'secfilepath:s@' => { name => 'secfilepath' },
|
||||
'username:s@' => { name => 'username' },
|
||||
'password:s@' => { name => 'password' },
|
||||
'scope:s@' => { name => 'scope' },
|
||||
'timeout:s@' => { name => 'timeout' }
|
||||
'navicli-command:s' => { name => 'navicli_command' },
|
||||
'navicli-path:s' => { name => 'navicli_path' },
|
||||
'naviseccli-command:s' => { name => 'naviseccli_command' },
|
||||
'naviseccli-path:s' => { name => 'naviseccli_path' },
|
||||
'sudo' => { name => 'sudo' },
|
||||
'special-arg:s' => { name => 'special_arg' },
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'secfilepath:s' => { name => 'secfilepath' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'scope:s' => { name => 'scope' },
|
||||
'timeout:s' => { name => 'timeout' }
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'NAVISPHERE OPTIONS', once => 1);
|
||||
|
||||
$self->{ssh} = centreon::plugins::ssh->new(%options);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
|
||||
|
||||
# 1 means we use a file to read
|
||||
$self->{no_navicmd} = 0;
|
||||
$self->{secure} = 0;
|
||||
|
@ -78,6 +77,60 @@ sub set_options {
|
|||
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -85,14 +138,14 @@ sub build_command {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong scope option '" . $self->{scope} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
$self->{cmd} = $self->{option_results}->{navicli_path} . '/' . $self->{option_results}->{navicli_command};
|
||||
|
||||
|
||||
if (defined($self->{username}) || defined($self->{secfilepath})) {
|
||||
$self->{cmd} = $self->{option_results}->{naviseccli_path} . '/' . $self->{option_results}->{naviseccli_command};
|
||||
$self->{secure} = 1;
|
||||
}
|
||||
|
||||
|
||||
if (defined($self->{secfilepath})) {
|
||||
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.');
|
||||
|
@ -104,12 +157,12 @@ sub build_command {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! -e $self->{cmd}) {
|
||||
$self->{output}->add_option_msg(short_msg => "Command '" . $self->{cmd} . "' not exist or executable.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
if (defined($self->{special_arg}) && $self->{special_arg} ne '') {
|
||||
$self->{cmd} .= ' ' . $self->{special_arg};
|
||||
$self->{no_navicmd} = 1;
|
||||
|
@ -117,12 +170,12 @@ sub build_command {
|
|||
$self->{secure} = 1;
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
if (defined($self->{secfilepath})) {
|
||||
$self->{cmd} .= " -Secfilepath '" . $self->{secfilepath} . "'";
|
||||
} elsif (defined($self->{username})) {
|
||||
|
@ -132,35 +185,9 @@ sub build_command {
|
|||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
if ($self->{no_navicmd} == 0) {
|
||||
$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}->option_exit();
|
||||
}
|
||||
|
||||
# Need to set timeout over command.
|
||||
$self->{option_results}->{timeout} = $self->{timeout} + 5;
|
||||
return centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{sudo},
|
||||
command => $self->{cmd},
|
||||
command_path => undef,
|
||||
command_options => undef
|
||||
);
|
||||
|
||||
my ($stdout, $exit_code);
|
||||
if (defined($self->{option_results}->{ssh_address}) && $self->{option_results}->{ssh_address} ne '') {
|
||||
($stdout, $exit_code) = $self->{ssh}->execute(
|
||||
hostname => $self->{option_results}->{ssh_address},
|
||||
sudo => $self->{sudo},
|
||||
command => $self->{cmd},
|
||||
timeout => $self->{timeout} + 5
|
||||
);
|
||||
} 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;
|
||||
|
@ -197,26 +232,10 @@ my navisphere manage
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
Execute command remotely in 'ssh'.
|
||||
|
||||
=item B<--ssh-address>
|
||||
|
||||
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>
|
||||
|
||||
Specify navicli path (default: '/opt/Navisphere/bin')
|
||||
|
|
|
@ -50,8 +50,7 @@ sub check_options {
|
|||
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '');
|
||||
|
||||
if (defined($self->{option_results}->{command_options})) {
|
||||
# we remove illegal characters
|
||||
$self->{option_results}->{command_options} =~ s/[`;!&]//g;
|
||||
$self->{option_results}->{command_options} = centreon::plugins::misc::sanitize_command_param(value => $self->{option_results}->{command_options});
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -28,10 +28,6 @@ sub new {
|
|||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
# $options{options} = options object
|
||||
# $options{output} = output object
|
||||
# $options{exit_value} = integer
|
||||
# $options{noptions} = integer
|
||||
|
||||
if (!defined($options{output})) {
|
||||
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}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
"smcli-command:s" => { name => 'smcli_command', default => 'SMcli' },
|
||||
"smcli-path:s" => { name => 'smcli_path', },
|
||||
"sudo:s" => { name => 'sudo', },
|
||||
"extra-options:s@" => { name => 'extra_options' },
|
||||
"special-arg:s@" => { name => 'special_arg' },
|
||||
"hostname:s@" => { name => 'hostname' },
|
||||
"hostname2:s@" => { name => 'hostname2' },
|
||||
"password:s@" => { name => 'password' },
|
||||
"timeout:s@" => { name => 'timeout' },
|
||||
"show-output:s" => { name => 'show_output' },
|
||||
'smcli-command:s' => { name => 'smcli_command' },
|
||||
'smcli-path:s' => { name => 'smcli_path' },
|
||||
'sudo' => { name => 'sudo', },
|
||||
'extra-options:s' => { name => 'extra_options' },
|
||||
'special-arg:s' => { name => 'special_arg' },
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'hostname2:s' => { name => 'hostname2' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout' }
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'SMCLI OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{custommode_name} = $options{custommode_name};
|
||||
|
||||
|
||||
# 1 means we use a file to read
|
||||
$self->{no_smclicmd} = 0;
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_options {
|
||||
my ($self, %options) = @_;
|
||||
# options{options_result}
|
||||
|
||||
$self->{option_results} = $options{option_results};
|
||||
}
|
||||
|
||||
# Method to manage multiples
|
||||
sub set_defaults {
|
||||
sub set_defaults {}
|
||||
|
||||
sub default_command {
|
||||
my ($self, %options) = @_;
|
||||
# options{default}
|
||||
|
||||
# Manage default value
|
||||
foreach (keys %{$options{default}}) {
|
||||
if ($_ eq $self->{custommode_name}) {
|
||||
if (ref($options{default}->{$_}) eq 'ARRAY') {
|
||||
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
|
||||
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
|
||||
if (!defined($self->{option_results}->{$opt}[$i])) {
|
||||
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ref($options{default}->{$_}) eq 'HASH') {
|
||||
foreach my $opt (keys %{$options{default}->{$_}}) {
|
||||
if (!defined($self->{option_results}->{$opt})) {
|
||||
$self->{option_results}->{$opt} = $options{default}->{$_}->{$opt};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'SMcli';
|
||||
}
|
||||
|
||||
sub default_command_path {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return '/opt/IBM_DS/client';
|
||||
}
|
||||
|
||||
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;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
|
||||
$self->{extra_options} = (defined($self->{option_results}->{extra_options})) ? $self->{option_results}->{extra_options} : '-quick -S';
|
||||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
$self->{cmd} = '';
|
||||
$self->{cmd} .= $self->{option_results}->{smcli_path} . '/' if (defined($self->{option_results}->{smcli_path}));
|
||||
$self->{cmd} .= $self->{option_results}->{smcli_command};
|
||||
|
||||
|
||||
if (defined($self->{special_arg}) && $self->{special_arg} ne '') {
|
||||
$self->{cmd} .= ' ' . $self->{special_arg};
|
||||
$self->{no_smclicmd} = 1;
|
||||
# It's ok if we use a file.
|
||||
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->{hostname2} if (defined($self->{hostname2}));
|
||||
|
||||
|
||||
$self->{cmd} .= " -p '" . $self->{password} . "'" if (defined($self->{password}));
|
||||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{no_smclicmd} == 0) {
|
||||
$self->{cmd} .= " -c '" . $options{cmd} . "'";
|
||||
}
|
||||
|
||||
# Need to set timeout over command.
|
||||
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
my ($response, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{sudo},
|
||||
command => $self->{cmd},
|
||||
command_path => undef,
|
||||
command_options => undef,
|
||||
no_quit => 1
|
||||
);
|
||||
my ($response, $exit_code) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{sudo},
|
||||
command => $self->{cmd},
|
||||
command_path => undef,
|
||||
command_options => undef,
|
||||
no_quit => 1
|
||||
);
|
||||
if ($exit_code != 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Command execution error (verbose mode for more details)");
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => "Command execution error (verbose mode for more details)"
|
||||
);
|
||||
$self->{output}->output_add(long_msg => $response);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
|
|
@ -31,7 +31,7 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"storage-command:s" => { name => 'storage_command', },
|
||||
'storage-command:s' => { name => 'storage_command' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -49,13 +49,17 @@ sub run {
|
|||
my $response = $smcli->execute_command(cmd => $self->{option_results}->{storage_command});
|
||||
# IBM smcli: Storage Subsystem health status = optimal.
|
||||
# Dell smcli: Storage array health status = optimal.
|
||||
|
||||
|
||||
my $match_ok_regexp = 'health status.*optimal';
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("storage health status is optimal"));
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => sprintf("storage health status is optimal")
|
||||
);
|
||||
if ($response !~ /$match_ok_regexp/msi) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("Some failures have been found (verbose mode for more details)"));
|
||||
$self->{output}->output_add(
|
||||
severity => 'CRITICAL',
|
||||
short_msg => sprintf("Some failures have been found (verbose mode for more details)")
|
||||
);
|
||||
$self->{output}->output_add(long_msg => $response);
|
||||
}
|
||||
|
||||
|
|
|
@ -632,6 +632,22 @@ sub slurp_file {
|
|||
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 {
|
||||
my (%options) = @_;
|
||||
|
||||
|
@ -641,11 +657,6 @@ sub check_security_command {
|
|||
(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");
|
||||
|
||||
my $content = slurp_file(output => $options{output}, file => $security_file);
|
||||
|
@ -667,6 +678,65 @@ sub check_security_command {
|
|||
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;
|
||||
|
||||
__END__
|
||||
|
|
|
@ -100,7 +100,6 @@ sub get_identifier {
|
|||
sub execute_command {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $timeout = $self->{timeout};
|
||||
if (!defined($timeout)) {
|
||||
$timeout = defined($options{timeout}) ? $options{timeout} : 45;
|
||||
|
@ -157,7 +156,7 @@ my ssh
|
|||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query.
|
||||
Hostname to query in ssh.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::hardware);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub set_system {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -46,14 +45,10 @@ sub set_system {
|
|||
|
||||
sub cmd_execute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
($self->{stdout}) = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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}
|
||||
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'ctconf',
|
||||
command_options => '-v'
|
||||
);
|
||||
|
||||
$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);
|
||||
$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);
|
||||
$self->{output}->output_add(long_msg => sprintf("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));
|
||||
$self->{output}->output_add(
|
||||
long_msg => sprintf(
|
||||
"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 {
|
||||
|
@ -82,39 +87,11 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$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' }
|
||||
});
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
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;
|
||||
|
||||
__END__
|
||||
|
@ -123,11 +100,13 @@ __END__
|
|||
|
||||
Check HSM hardware status.
|
||||
|
||||
Command used: 'ctconf -v'
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--component>
|
||||
|
||||
Which component to check (Default: '.*').
|
||||
Which component to check.
|
||||
Can be: 'hwstatus', 'temperature', 'memory'.
|
||||
|
||||
=item B<--filter>
|
||||
|
@ -150,48 +129,6 @@ Example: --warning='temperature,.*,50'
|
|||
Set critical threshold for 'temperature', 'memory' (syntax: type,regexp,threshold)
|
||||
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
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
@ -22,17 +22,18 @@ package hardware::devices::safenet::hsm::protecttoolkit::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware'
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub prefix_device_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -44,38 +43,38 @@ sub set_counters {
|
|||
key_values => [ { name => 'humidity' }, { name => 'display' } ],
|
||||
output_template => 'Humidity: %.2f%%',
|
||||
perfdatas => [
|
||||
{ label => 'humidity', value => 'humidity', template => '%.2f',
|
||||
unit => '%', min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
},
|
||||
{ label => 'humidity', template => '%.2f',
|
||||
unit => '%', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'temperature', set => {
|
||||
key_values => [ { name => 'temperature' }, { name => 'dewpoint' }, { name => 'display' } ],
|
||||
output_template => 'Temperature: %.2f C',
|
||||
perfdatas => [
|
||||
{ label => 'temperature', value => 'temperature', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
},
|
||||
{ label => 'temperature', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'dew-point', set => {
|
||||
key_values => [ { name => 'dewpoint' }, { name => 'display' } ],
|
||||
output_template => 'Dew Point : %.2f C',
|
||||
perfdatas => [
|
||||
{ label => 'dew_point', value => 'dewpoint', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'dew_point', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'delta', set => {
|
||||
key_values => [ { name => 'delta' }, { name => 'display' } ],
|
||||
output_template => 'Delta (Temp - Dew) : %.2f C',
|
||||
perfdatas => [
|
||||
{ label => 'delta', value => 'delta', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'delta', template => '%.2f',
|
||||
unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -85,51 +84,21 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"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-drive:s" => { name => 'filter_drive', default => '.*' }
|
||||
'filter-drive:s' => { name => 'filter_drive', default => '.*' }
|
||||
});
|
||||
|
||||
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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{drive} = {};
|
||||
my $stdout = centreon::plugins::misc::execute(
|
||||
output => $self->{output},
|
||||
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}
|
||||
my ($stdout) = $options{custom}->execute_command(
|
||||
command => 'tempered',
|
||||
command_path => '/opt/PCsensor/TEMPered/utils'
|
||||
);
|
||||
|
||||
$self->{drive} = {};
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
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);
|
||||
|
@ -149,60 +118,19 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check metrics from TemPerHum sensors
|
||||
Check metrics from TemPerHum sensors.
|
||||
|
||||
Command used: '/opt/PCsensor/TEMPered/utils/tempered'
|
||||
|
||||
=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>
|
||||
|
||||
Filter by drive name (e.g --filter-drive raw4)
|
||||
|
||||
=item B<--warning-*>
|
||||
Threshold Warning
|
||||
Can be: 'temperature', 'humidity', 'dew-point', 'delta'
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
=item B<--critical-*>
|
||||
Threshold Critical
|
||||
Thresholds.
|
||||
Can be: 'temperature', 'humidity', 'dew-point', 'delta'
|
||||
|
||||
=back
|
||||
|
|
|
@ -22,15 +22,17 @@ package hardware::sensors::temperhum::local::plugin;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'environment' => 'hardware::sensors::temperhum::local::mode::environment',
|
||||
);
|
||||
|
||||
$self->{modes} = {
|
||||
'environment' => 'hardware::sensors::temperhum::local::mode::environment'
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli';
|
||||
|
||||
return $self;}
|
||||
1;
|
||||
|
@ -39,6 +41,6 @@ __END__
|
|||
|
||||
=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
|
||||
|
|
|
@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -50,20 +51,40 @@ sub check_options {
|
|||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{manage_returns} = {};
|
||||
$self->{expressions} = [];
|
||||
foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
|
||||
next if (!($entry =~ /(.*?),(.*?),(.*)/));
|
||||
next if (!$self->{output}->is_litteral_status(status => $2));
|
||||
if ($1 ne '') {
|
||||
$self->{manage_returns}->{$1} = {return => $2, msg => $3};
|
||||
my ($expr, $rv, $msg) = ($1, $2, $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 {
|
||||
$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.");
|
||||
$self->{output}->option_exit();
|
||||
|
||||
if ($self->{option_results}->{manage_returns} eq '' ||
|
||||
(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 {
|
||||
|
@ -79,24 +100,32 @@ sub run {
|
|||
my $long_msg = $stdout;
|
||||
$long_msg =~ s/\|/~/mg;
|
||||
$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(
|
||||
severity => $self->{manage_returns}->{$exit_code}->{return},
|
||||
short_msg => $self->{manage_returns}->{$exit_code}->{msg}
|
||||
severity => $self->{expression_default}->{rv},
|
||||
short_msg => $self->{expression_default}->{msg}
|
||||
);
|
||||
} elsif (defined($self->{manage_returns}->{default})) {
|
||||
} elsif ($matched == 0) {
|
||||
$self->{output}->output_add(
|
||||
severity => $self->{manage_returns}->{default}->{return},
|
||||
short_msg => $self->{manage_returns}->{default}->{msg}
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(
|
||||
severity => 'UNKNWON',
|
||||
short_msg => 'Exit code from command'
|
||||
severity => 'UNKNOWN',
|
||||
short_msg => "Command exit code ($exit_code)"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (defined($exit_code)) {
|
||||
$self->{output}->perfdata_add(
|
||||
nlabel => 'command.exit.code.count',
|
||||
|
@ -121,7 +150,7 @@ Check command returns.
|
|||
=item B<--manage-returns>
|
||||
|
||||
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>
|
||||
|
||||
|
|
|
@ -24,13 +24,14 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
$options{options}->add_options(arguments => {
|
||||
'exec-command:s' => { name => 'exec_command' },
|
||||
'exec-command-path:s' => { name => 'exec_command_path' },
|
||||
'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;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -92,7 +100,7 @@ sub run {
|
|||
my $long_msg = $stdout;
|
||||
$long_msg =~ s/\|/~/mg;
|
||||
$self->{output}->output_add(long_msg => $long_msg);
|
||||
|
||||
|
||||
my $matched = 0;
|
||||
my $values = { code => $exit_code, output => $stdout };
|
||||
foreach (@{$self->{expressions}}) {
|
||||
|
|
|
@ -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__
|
|
@ -25,27 +25,21 @@ use warnings;
|
|||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'health-status' => 'centreon::common::smcli::mode::healthstatus',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'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} = {
|
||||
'health-status' => {
|
||||
storage_command => 'show storageArray healthstatus;',
|
||||
}
|
||||
};
|
||||
$self->{customdefault} = {
|
||||
'smcli' => {
|
||||
smcli_path => '/opt/dell/mdstoragemanager/client',
|
||||
}
|
||||
};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,27 +26,20 @@ use base qw(centreon::plugins::script_custom);
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'health-status' => 'centreon::common::smcli::mode::healthstatus',
|
||||
);
|
||||
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom';
|
||||
|
||||
$self->{modes} = {
|
||||
'health-status' => 'centreon::common::smcli::mode::healthstatus'
|
||||
};
|
||||
$self->{custom_modes}->{smcli} = 'centreon::common::smcli::custom::custom';
|
||||
|
||||
$self->{default} = {
|
||||
'health-status' => {
|
||||
storage_command => 'show storageSubsystem healthstatus;',
|
||||
}
|
||||
};
|
||||
$self->{customdefault} = {
|
||||
'smcli' => {
|
||||
smcli_path => '/opt/IBM_DS/client',
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,27 +25,20 @@ use warnings;
|
|||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'health-status' => 'centreon::common::smcli::mode::healthstatus',
|
||||
);
|
||||
$self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom';
|
||||
|
||||
$self->{modes} = {
|
||||
'health-status' => 'centreon::common::smcli::mode::healthstatus'
|
||||
};
|
||||
$self->{custom_modes}->{smcli} = 'centreon::common::smcli::custom::custom';
|
||||
|
||||
$self->{default} = {
|
||||
'health-status' => {
|
||||
storage_command => 'show storageSubsystem healthstatus;',
|
||||
}
|
||||
};
|
||||
$self->{customdefault} = {
|
||||
'smcli' => {
|
||||
smcli_path => '/opt/IBM_DS/client',
|
||||
}
|
||||
};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
|
@ -25,28 +25,21 @@ use warnings;
|
|||
use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
$self->{modes} = {
|
||||
'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} = {
|
||||
'health-status' => {
|
||||
storage_command => 'show storageSubsystem healthstatus;',
|
||||
}
|
||||
};
|
||||
$self->{customdefault} = {
|
||||
'smcli' => {
|
||||
smcli_path => '/opt/IBM_DS/client',
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue