From f8a51568c5e512187d4b9be63aee8bc97e607884 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Jan 2020 14:46:36 +0100 Subject: [PATCH] add ps-display option for powershell modes --- .../apps/backup/veeam/local/mode/jobstatus.pm | 113 +++++++++------- .../apps/backup/veeam/local/mode/listjobs.pm | 72 ++++++---- .../exchange/2010/local/mode/listdatabases.pm | 82 +++++++---- .../hyperv/2012/local/mode/listnodevms.pm | 93 ++++++++----- .../2012/local/mode/nodeintegrationservice.pm | 76 +++++++---- .../hyperv/2012/local/mode/nodereplication.pm | 68 ++++++---- .../hyperv/2012/local/mode/nodesnapshot.pm | 80 ++++++----- .../hyperv/2012/local/mode/nodevmstatus.pm | 80 +++++++---- .../local/mode/scvmmintegrationservice.pm | 128 ++++++++++-------- .../hyperv/2012/local/mode/scvmmsnapshot.pm | 104 ++++++++------ .../hyperv/2012/local/mode/scvmmvmstatus.pm | 107 +++++++++------ .../apps/hyperv/2012/local/plugin.pm | 16 +-- .../local/mode/databasereplicationstatus.pm | 68 ++++++---- .../apps/sccm/local/mode/sitestatus.pm | 65 +++++---- .../apps/wsus/local/mode/computersstatus.pm | 84 +++++++----- .../apps/wsus/local/mode/serverstatistics.pm | 75 ++++++---- .../wsus/local/mode/synchronisationstatus.pm | 125 ++++++++++------- .../apps/wsus/local/mode/updatesstatus.pm | 75 ++++++---- centreon-plugins/apps/wsus/local/plugin.pm | 8 +- .../powershell/dell/compellent/hbausage.pm | 8 +- .../powershell/dell/compellent/volumeusage.pm | 8 +- .../powershell/hyperv/2012/listnodevms.pm | 29 ++-- .../hyperv/2012/nodeintegrationservice.pm | 8 +- .../powershell/hyperv/2012/nodereplication.pm | 8 +- .../powershell/hyperv/2012/nodesnapshot.pm | 6 +- .../powershell/hyperv/2012/nodevmstatus.pm | 6 +- .../hyperv/2012/scvmmintegrationservice.pm | 8 +- .../powershell/hyperv/2012/scvmmsnapshot.pm | 8 +- .../powershell/hyperv/2012/scvmmvmstatus.pm | 8 +- .../sccm/databasereplicationstatus.pm | 5 +- .../common/powershell/sccm/sitestatus.pm | 5 +- .../common/powershell/veeam/jobstatus.pm | 6 +- .../common/powershell/veeam/listjobs.pm | 6 +- .../common/powershell/windows/liststorages.pm | 31 +++-- .../powershell/windows/pendingreboot.pm | 6 +- .../common/powershell/wsus/computersstatus.pm | 5 +- .../powershell/wsus/serverstatistics.pm | 5 +- .../powershell/wsus/synchronisationstatus.pm | 5 +- .../common/powershell/wsus/updatesstatus.pm | 5 +- centreon-plugins/database/postgres/plugin.pm | 4 +- .../os/windows/local/mode/liststorages.pm | 49 +++++-- .../os/windows/local/mode/pendingreboot.pm | 46 +++++-- .../dell/compellent/local/mode/hbausage.pm | 97 +++++++------ .../dell/compellent/local/mode/volumeusage.pm | 112 ++++++++------- 44 files changed, 1181 insertions(+), 822 deletions(-) diff --git a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm index 9e695cebd..22e6492bb 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm @@ -32,7 +32,7 @@ sub custom_status_threshold { my ($self, %options) = @_; my $status = 'ok'; my $message; - + eval { local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; }; @@ -58,14 +58,13 @@ sub custom_status_threshold { sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status} . ' [type: ' . $self->{result_values}->{type} . ']'; - return $msg; + return 'status : ' . $self->{result_values}->{status} . ' [type: ' . $self->{result_values}->{type} . ']'; } 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'}; $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; @@ -75,20 +74,19 @@ sub custom_status_calc { sub custom_long_output { my ($self, %options) = @_; - my $msg = 'started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed}); - return $msg; + return 'started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed}); } sub custom_long_calc { my ($self, %options) = @_; - + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'}; $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; $self->{result_values}->{is_running} = $options{new_datas}->{$self->{instance} . '_is_running'}; - + return -11 if ($self->{result_values}->{is_running} != 1); return 0; @@ -96,12 +94,12 @@ sub custom_long_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok', skipped_code => { -11 => 1, -10 => 1 } }, ]; - + $self->{maps_counters}->{global} = [ { label => 'total', set => { key_values => [ { name => 'total' } ], @@ -112,7 +110,7 @@ sub set_counters { } }, ]; - + $self->{maps_counters}->{job} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'display' }, { name => 'type' }, { name => 'is_running' } ], @@ -137,26 +135,26 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-name:s" => { name => 'filter_name' }, - "filter-type:s" => { name => 'filter_type' }, - "filter-end-time:s" => { name => 'filter_end_time', default => 86400 }, - "filter-start-time:s" => { name => 'filter_start_time' }, - "ok-status:s" => { name => 'ok_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{is_running} == 0 and not %{status} =~ /Success/i' }, - "warning-long:s" => { name => 'warning_long' }, - "critical-long:s" => { name => 'critical_long' }, - }); - + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-end-time:s' => { name => 'filter_end_time', default => 86400 }, + 'filter-start-time:s' => { name => 'filter_start_time' }, + 'ok-status:s' => { name => 'ok_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{is_running} == 0 and not %{status} =~ /Success/i' }, + 'warning-long:s' => { name => 'warning_long' }, + 'critical-long:s' => { name => 'critical_long' }, + }); + return $self; } @@ -169,25 +167,39 @@ sub check_options { sub prefix_job_output { my ($self, %options) = @_; - + return "Job '" . $options{instance_value}->{display} . "' "; } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::veeam::jobstatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::veeam::jobstatus::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -202,13 +214,14 @@ sub manage_selection { my $current_time = time(); foreach my $line (split /\n/, $stdout) { next if ($line !~ /^\[name\s*=(.*?)\]\[type\s*=(.*?)\]\[isrunning\s*=(.*?)\]\[result\s*=(.*?)\]\[creationTimeUTC\s*=(.*?)\]\[endTimeUTC\s*=(.*?)\]/i); - - my ($name, $type, $is_running, $result, $start_time, $end_time) = (centreon::plugins::misc::trim($1), - centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), - centreon::plugins::misc::trim($5), centreon::plugins::misc::trim($6)); + + my ($name, $type, $is_running, $result, $start_time, $end_time) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3), + centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5), centreon::plugins::misc::trim($6) + ); $start_time =~ s/,/\./; $end_time =~ s/,/\./; - + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping job '" . $name . "': no matching filter.", debug => 1); @@ -274,6 +287,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm index f1197c78e..26678e6d4 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm @@ -31,18 +31,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-name:s" => { name => 'filter_name' }, - }); - + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -59,15 +59,17 @@ sub run { $self->{output}->output_add(long_msg => "'" . $_ . "' [type = " . $self->{jobs}->{$_}->{type} . "]"); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List jobs:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List jobs:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name', 'type']); } @@ -86,18 +88,32 @@ sub disco_show { sub manage_selection { my ($self, %options) = @_; - my $ps = centreon::common::powershell::veeam::listjobs::get_powershell( - no_ps => $self->{option_results}->{no_ps}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::veeam::listjobs::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -113,7 +129,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping job '" . $name . "': no type or no matching filter type", debug => 1); next; } - + $self->{jobs}->{$name} = { type => $type }; } } @@ -149,6 +165,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm b/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm index 38fa33573..bc64ab038 100644 --- a/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm +++ b/centreon-plugins/apps/exchange/2010/local/mode/listdatabases.pm @@ -55,26 +55,43 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell( - remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - no_ps => $self->{option_results}->{no_ps}, - filter_database => $self->{option_results}->{ps_database_filter} + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + filter_database => $self->{option_results}->{ps_database_filter} + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} ); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => 'List databases:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List databases:' + ); centreon::common::powershell::exchange::2010::listdatabases::list($self, stdout => $stdout); } @@ -84,24 +101,29 @@ sub run { sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name', 'server', 'mounted']); } sub disco_show { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell(remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - no_ps => $self->{option_results}->{no_ps}, - filter_database => $self->{option_results}->{ps_database_filter}); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + filter_database => $self->{option_results}->{ps_database_filter} + ); + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); centreon::common::powershell::exchange::2010::listdatabases::disco_show($self, stdout => $stdout); } diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm b/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm index e4c04afd5..95dfa119c 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/listnodevms.pm @@ -31,16 +31,17 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps', }, - "ps-exec-only" => { name => 'ps_exec_only', }, - }); + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + }); + return $self; } @@ -51,24 +52,41 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::listnodevms::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::listnodevms::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Virtual Machines:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List Virtual Machines:' + ); centreon::common::powershell::hyperv::2012::listnodevms::list($self, stdout => $stdout); } - + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -81,14 +99,19 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::listnodevms::get_powershell(no_ps => $self->{option_results}->{no_ps}); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::listnodevms::get_powershell(); + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); centreon::common::powershell::hyperv::2012::listnodevms::disco_show($self, stdout => $stdout); } @@ -123,10 +146,14 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm index 9350c3bad..8e04cf1c0 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -122,23 +122,24 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-note:s" => { name => 'filter_note' }, - "filter-status:s" => { name => 'filter_status', default => 'running' }, - "warning-global-status:s" => { name => 'warning_global_status', default => '%{integration_service_state} =~ /Update required/i' }, - "critical-global-status:s" => { name => 'critical_global_status', default => '' }, - "warning-service-status:s" => { name => 'warning_service_status', default => '' }, - "critical-service-status:s" => { name => 'critical_service_status', default => '%{primary_status} !~ /Ok/i' }, - }); + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-note:s' => { name => 'filter_note' }, + 'filter-status:s' => { name => 'filter_status', default => 'running' }, + 'warning-global-status:s' => { name => 'warning_global_status', default => '%{integration_service_state} =~ /Update required/i' }, + 'critical-global-status:s' => { name => 'critical_global_status', default => '' }, + 'warning-service-status:s' => { name => 'warning_service_status', default => '' }, + 'critical-service-status:s' => { name => 'critical_service_status', default => '%{primary_status} !~ /Ok/i' }, + }); + return $self; } @@ -151,18 +152,33 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::nodeintegrationservice::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::nodeintegrationservice::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -246,6 +262,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm index 9b83907ee..089dd8fb5 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodereplication.pm @@ -72,43 +72,59 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "warning-status:s" => { name => 'warning_status', default => '%{health} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{health} =~ /Critical/i' }, - }); + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'warning-status:s' => { name => 'warning_status', default => '%{health} =~ /Warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{health} =~ /Critical/i' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::nodereplication::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } - my $ps = centreon::common::powershell::hyperv::2012::nodereplication::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -164,6 +180,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm index 95c7d5a2d..bb55bcdc7 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodesnapshot.pm @@ -51,16 +51,14 @@ sub set_counters { sub custom_snapshot_output { my ($self, %options) = @_; - my $msg = "[status = " . $self->{result_values}->{status_absolute} . "] checkpoint started '" . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot_absolute}) . "' ago"; - return $msg; + return "[status = " . $self->{result_values}->{status_absolute} . "] checkpoint started '" . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot_absolute}) . "' ago"; } sub custom_backing_output { my ($self, %options) = @_; - my $msg = "[status = " . $self->{result_values}->{status_absolute} . "] backing started '" . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{backing_absolute}) . "' ago"; - - return $msg; + + return "[status = " . $self->{result_values}->{status_absolute} . "] backing started '" . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{backing_absolute}) . "' ago"; } sub prefix_vm_output { @@ -73,36 +71,52 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-note:s" => { name => 'filter_note' }, - "filter-status:s" => { name => 'filter_status', default => 'running' }, - }); + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-note:s' => { name => 'filter_note' }, + 'filter-status:s' => { name => 'filter_status', default => 'running' }, + }); + return $self; } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::nodesnapshot::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::nodesnapshot::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -140,8 +154,8 @@ sub manage_selection { } $self->{vm}->{$id} = { - display => $name, - snapshot => $chkpt{snapshot} > 0 ? $time - $chkpt{snapshot} : undef, + display => $name, + snapshot => $chkpt{snapshot} > 0 ? $time - $chkpt{snapshot} : undef, backing => $chkpt{backing} > 0 ? $time - $chkpt{backing} : undef, status => $status }; @@ -180,6 +194,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm b/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm index 5dbeb5532..769c27dc8 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/nodevmstatus.pm @@ -73,44 +73,60 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-note:s" => { name => 'filter_note' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Operating normally/i' }, - }); + + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-note:s' => { name => 'filter_note' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Operating normally/i' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::nodevmstatus::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::nodevmstatus::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -119,7 +135,7 @@ sub manage_selection { #[name= XXXX2 ][state= Running ][status= Operating normally ][IsClustered= False ][note= ] #[name= XXXX3 ][state= Running ][status= Operating normally ][IsClustered= False ][note= ] $self->{vm} = {}; - + my $id = 1; while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[IsClustered=\s*(.*?)\s*\]\[note=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) { my ($name, $state, $status, $is_clustered, $note) = ($1, $2, $3, $4, $5); @@ -129,16 +145,16 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); next; } - if (defined($self->{option_results}->{filter_note}) && $self->{option_results}->{filter_note} ne '' && + if (defined($self->{option_results}->{filter_note}) && $self->{option_results}->{filter_note} ne '' && $note !~ /$self->{option_results}->{filter_note}/i) { $self->{output}->output_add(long_msg => "skipping '" . $note . "': no matching filter.", debug => 1); next; } - + $self->{vm}->{$id} = { display => $name, vm => $name, status => $status, state => $state, is_clustered => $is_clustered }; $id++; } - + if (scalar(keys %{$self->{vm}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No virtual machine found."); $self->{output}->option_exit(); @@ -176,6 +192,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm index a66ca323b..31aa2c858 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm @@ -141,43 +141,44 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "scvmm-hostname:s" => { name => 'scvmm_hostname' }, - "scvmm-username:s" => { name => 'scvmm_username' }, - "scvmm-password:s" => { name => 'scvmm_password' }, - "scvmm-port:s" => { name => 'scvmm_port', default => 8100 }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-hostgroup:s" => { name => 'filter_hostgroup' }, - "filter-status:s" => { name => 'filter_status' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{vmaddition} =~ /not detected/i' }, - "warning-osshutdown-status:s" => { name => 'warning_osshutdown_status', default => '' }, - "critical-osshutdown-status:s" => { name => 'critical_osshutdown_status', default => '' }, - "warning-timesync-status:s" => { name => 'warning_timesync_status', default => '' }, - "critical-timesync-status:s" => { name => 'critical_timesync_status', default => '' }, - "warning-dataexchange-status:s" => { name => 'warning_dataexchange_status', default => '' }, - "critical-dataexchange-status:s" => { name => 'critical_dataexchange_status', default => '' }, - "warning-heartbeat-status:s" => { name => 'warning_heartbeat_status', default => '' }, - "critical-heartbeat-status:s" => { name => 'critical_heartbeat_status', default => '' }, - "warning-backup-status:s" => { name => 'warning_backup_status', default => '' }, - "critical-backup-status:s" => { name => 'critical_backup_status', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'scvmm-hostname:s' => { name => 'scvmm_hostname' }, + 'scvmm-username:s' => { name => 'scvmm_username' }, + 'scvmm-password:s' => { name => 'scvmm_password' }, + 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-hostgroup:s' => { name => 'filter_hostgroup' }, + 'filter-status:s' => { name => 'filter_status' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{vmaddition} =~ /not detected/i' }, + 'warning-osshutdown-status:s' => { name => 'warning_osshutdown_status', default => '' }, + 'critical-osshutdown-status:s' => { name => 'critical_osshutdown_status', default => '' }, + 'warning-timesync-status:s' => { name => 'warning_timesync_status', default => '' }, + 'critical-timesync-status:s' => { name => 'critical_timesync_status', default => '' }, + 'warning-dataexchange-status:s' => { name => 'warning_dataexchange_status', default => '' }, + 'critical-dataexchange-status:s' => { name => 'critical_dataexchange_status', default => '' }, + 'warning-heartbeat-status:s' => { name => 'warning_heartbeat_status', default => '' }, + 'critical-heartbeat-status:s' => { name => 'critical_heartbeat_status', default => '' }, + 'warning-backup-status:s' => { name => 'warning_backup_status', default => '' }, + 'critical-backup-status:s' => { name => 'critical_backup_status', default => '' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + foreach my $label (('scvmm_hostname', 'scvmm_username', 'scvmm_password', 'scvmm_port')) { if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { my ($label_opt) = $label; @@ -186,31 +187,48 @@ sub check_options { $self->{output}->option_exit(); } } - - $self->change_macros(macros => ['warning_status', 'critical_status', 'warning_osshutdown_status', 'critical_osshutdown_status', + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'warning_osshutdown_status', 'critical_osshutdown_status', 'warning_timesync_status', 'critical_timesync_status', 'warning_dataexchange_status', 'critical_dataexchange_status', - 'warning_heartbeat_status', 'critical_heartbeat_status', 'warning_backup_status', 'critical_backup_status']); + 'warning_heartbeat_status', 'critical_heartbeat_status', 'warning_backup_status', 'critical_backup_status' + ]); } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::scvmmintegrationservice::get_powershell( - scvmm_hostname => $self->{option_results}->{scvmm_hostname}, - scvmm_username => $self->{option_results}->{scvmm_username}, - scvmm_password => $self->{option_results}->{scvmm_password}, - scvmm_port => $self->{option_results}->{scvmm_port}, - no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::scvmmintegrationservice::get_powershell( + scvmm_hostname => $self->{option_results}->{scvmm_hostname}, + scvmm_username => $self->{option_results}->{scvmm_username}, + scvmm_password => $self->{option_results}->{scvmm_password}, + scvmm_port => $self->{option_results}->{scvmm_port} + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -220,7 +238,7 @@ sub manage_selection { #[VM= test3 ][Description= ][Status= HostNotResponding ][Cloud= ][HostGroup= All Hosts\CORP\test3 ][VMAddition= Not Detected ] #[VM= test4 ][Description= ][Status= HostNotResponding ][Cloud= ][HostGroup= All Hosts\CORP\test4 ][VMAddition= Not Detected ] $self->{vm} = {}; - + my $id = 1; my @lines = split /\n/, $stdout; foreach my $line (@lines) { @@ -228,7 +246,7 @@ sub manage_selection { while ($line =~ /\[(.*?)=\s*(.*?)\s*\]/g) { $values{lc($1)} = $2; } - + $values{hostgroup} =~ s/\\/\//g; my $filtered = 0; foreach (('vm', 'description', 'status', 'hostgroup')) { @@ -239,7 +257,7 @@ sub manage_selection { last; } } - + $self->{vm}->{$id} = { %values } if ($filtered == 0); $id++; } @@ -292,6 +310,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm index a55e3364f..eee3c8e57 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmsnapshot.pm @@ -29,7 +29,7 @@ use centreon::common::powershell::hyperv::2012::scvmmsnapshot; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All VM snapshots are ok' }, ]; @@ -45,14 +45,13 @@ sub set_counters { sub custom_vm_output { my ($self, %options) = @_; - my $msg = 'checkpoint started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot_absolute}); - return $msg; + return 'checkpoint started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{snapshot_absolute}); } sub prefix_vm_output { my ($self, %options) = @_; - + return "VM '" . $options{instance_value}->{display} . "' "; } @@ -60,31 +59,32 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "scvmm-hostname:s" => { name => 'scvmm_hostname' }, - "scvmm-username:s" => { name => 'scvmm_username' }, - "scvmm-password:s" => { name => 'scvmm_password' }, - "scvmm-port:s" => { name => 'scvmm_port', default => 8100 }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-description:s"=> { name => 'filter_description' }, - "filter-hostgroup:s" => { name => 'filter_hostgroup' }, - "filter-status:s" => { name => 'filter_status', default => 'running' }, - }); + + $options{options}->add_options(arguments => { + 'scvmm-hostname:s' => { name => 'scvmm_hostname' }, + 'scvmm-username:s' => { name => 'scvmm_username' }, + 'scvmm-password:s' => { name => 'scvmm_password' }, + 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-hostgroup:s' => { name => 'filter_hostgroup' }, + 'filter-status:s' => { name => 'filter_status', default => 'running' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + foreach my $label (('scvmm_hostname', 'scvmm_username', 'scvmm_password', 'scvmm_port')) { if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { my ($label_opt) = $label; @@ -97,31 +97,47 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::scvmmsnapshot::get_powershell(scvmm_hostname => $self->{option_results}->{scvmm_hostname}, - scvmm_username => $self->{option_results}->{scvmm_username}, - scvmm_password => $self->{option_results}->{scvmm_password}, - scvmm_port => $self->{option_results}->{scvmm_port}, - no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::scvmmsnapshot::get_powershell( + scvmm_hostname => $self->{option_results}->{scvmm_hostname}, + scvmm_username => $self->{option_results}->{scvmm_username}, + scvmm_password => $self->{option_results}->{scvmm_password}, + scvmm_port => $self->{option_results}->{scvmm_port}, + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + #[name= test-server ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ] #[checkpointAddedTime= 1475502741.957 ] #[checkpointAddedTime= 1475502963.21 ] $self->{vm} = {}; - + my $id = 1; while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[description=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) { my %values = (vm => $1, description => $2, status => $3, cloud => $4, hostgroup => $5); @@ -143,7 +159,7 @@ sub manage_selection { last; } } - + $self->{vm}->{$id} = { display => $values{vm}, snapshot => time() - $chkpt } if ($filtered == 0); $id++; } @@ -196,6 +212,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. @@ -228,4 +248,4 @@ Can be: 'snapshot' (in seconds). =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm index 12454b4a5..653d928fc 100644 --- a/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm +++ b/centreon-plugins/apps/hyperv/2012/local/mode/scvmmvmstatus.pm @@ -31,8 +31,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status : ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -64,7 +63,7 @@ sub set_counters { sub prefix_vm_output { my ($self, %options) = @_; - + return "VM '" . $options{instance_value}->{vm} . "' "; } @@ -72,32 +71,33 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "scvmm-hostname:s" => { name => 'scvmm_hostname' }, - "scvmm-username:s" => { name => 'scvmm_username' }, - "scvmm-password:s" => { name => 'scvmm_password' }, - "scvmm-port:s" => { name => 'scvmm_port', default => 8100 }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "filter-vm:s" => { name => 'filter_vm' }, - "filter-description:s"=> { name => 'filter_description' }, - "filter-hostgroup:s" => { name => 'filter_hostgroup' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Running|Stopped/i' }, - }); + + $options{options}->add_options(arguments => { + 'scvmm-hostname:s' => { name => 'scvmm_hostname' }, + 'scvmm-username:s' => { name => 'scvmm_username' }, + 'scvmm-password:s' => { name => 'scvmm_password' }, + 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'filter-vm:s' => { name => 'filter_vm' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-hostgroup:s' => { name => 'filter_hostgroup' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Running|Stopped/i' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + foreach my $label (('scvmm_hostname', 'scvmm_username', 'scvmm_password', 'scvmm_port')) { if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { my ($label_opt) = $label; @@ -111,35 +111,50 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::hyperv::2012::scvmmvmstatus::get_powershell( - scvmm_hostname => $self->{option_results}->{scvmm_hostname}, - scvmm_username => $self->{option_results}->{scvmm_username}, - scvmm_password => $self->{option_results}->{scvmm_password}, - scvmm_port => $self->{option_results}->{scvmm_port}, - no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::hyperv::2012::scvmmvmstatus::get_powershell( + scvmm_hostname => $self->{option_results}->{scvmm_hostname}, + scvmm_username => $self->{option_results}->{scvmm_username}, + scvmm_password => $self->{option_results}->{scvmm_password}, + scvmm_port => $self->{option_results}->{scvmm_port} + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + #[name= test-server ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ] #[name= test-server2 ][description= ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server2 ] $self->{vm} = {}; - + my $id = 1; while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[description=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) { my %values = (vm => $1, description => $2, status => $3, cloud => $4, hostgroup => $5); - + my $filtered = 0; $values{hostgroup} =~ s/\\/\//g; foreach (('vm', 'description', 'hostgroup')) { @@ -150,12 +165,12 @@ sub manage_selection { last; } } - + $self->{vm}->{$id} = { display => $values{vm}, vm => $values{vm}, status => $values{status}, hostgroup => $values{hostgroup} } if ($filtered == 0); $id++; } - + if (scalar(keys %{$self->{vm}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No virtual machine found."); $self->{output}->option_exit(); @@ -209,6 +224,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/hyperv/2012/local/plugin.pm b/centreon-plugins/apps/hyperv/2012/local/plugin.pm index 5040af657..d04761268 100644 --- a/centreon-plugins/apps/hyperv/2012/local/plugin.pm +++ b/centreon-plugins/apps/hyperv/2012/local/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-node-vms' => 'apps::hyperv::2012::local::mode::listnodevms', - 'node-integration-service' => 'apps::hyperv::2012::local::mode::nodeintegrationservice', - 'node-replication' => 'apps::hyperv::2012::local::mode::nodereplication', - 'node-snapshot' => 'apps::hyperv::2012::local::mode::nodesnapshot', - 'node-vm-status' => 'apps::hyperv::2012::local::mode::nodevmstatus', - 'scvmm-integration-service' => 'apps::hyperv::2012::local::mode::scvmmintegrationservice', - 'scvmm-snapshot' => 'apps::hyperv::2012::local::mode::scvmmsnapshot', - 'scvmm-vm-status' => 'apps::hyperv::2012::local::mode::scvmmvmstatus', + 'list-node-vms' => 'apps::hyperv::2012::local::mode::listnodevms', + 'node-integration-service' => 'apps::hyperv::2012::local::mode::nodeintegrationservice', + 'node-replication' => 'apps::hyperv::2012::local::mode::nodereplication', + 'node-snapshot' => 'apps::hyperv::2012::local::mode::nodesnapshot', + 'node-vm-status' => 'apps::hyperv::2012::local::mode::nodevmstatus', + 'scvmm-integration-service' => 'apps::hyperv::2012::local::mode::scvmmintegrationservice', + 'scvmm-snapshot' => 'apps::hyperv::2012::local::mode::scvmmsnapshot', + 'scvmm-vm-status' => 'apps::hyperv::2012::local::mode::scvmmvmstatus', ); return $self; diff --git a/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm b/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm index 2114f7166..e9106381d 100644 --- a/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm +++ b/centreon-plugins/apps/sccm/local/mode/databasereplicationstatus.pm @@ -27,6 +27,7 @@ use warnings; use JSON::XS; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::common::powershell::sccm::databasereplicationstatus; +use centreon::plugins::misc; use DateTime; my %map_link_status = ( @@ -64,8 +65,7 @@ my %map_type = ( sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Overall Link status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Overall Link status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -78,12 +78,12 @@ sub custom_status_calc { sub custom_site_status_output { my ($self, %options) = @_; - my $msg = sprintf("status is '%s', Site-to-Site state is '%s' [Type: %s] [Last sync: %s]", + return sprintf("status is '%s', Site-to-Site state is '%s' [Type: %s] [Last sync: %s]", $self->{result_values}->{status}, $self->{result_values}->{site_to_site_state}, $self->{result_values}->{type}, - centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_sync_time})); - return $msg; + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_sync_time}) + ); } sub custom_site_status_calc { @@ -93,23 +93,23 @@ sub custom_site_status_calc { $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_SiteType'}; $self->{result_values}->{site_to_site_state} = $options{new_datas}->{$self->{instance} . '_SiteToSiteGlobalState'}; $self->{result_values}->{sync_time} = $options{new_datas}->{$self->{instance} . '_SiteToSiteGlobalSyncTime'}; - + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); $self->{result_values}->{sync_time} =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/; my $sync_time = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %$tz); - + $self->{result_values}->{last_sync_time} = time() - $sync_time->epoch; return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'sites', type => 1, cb_prefix_output => 'prefix_output_site', message_multiple => 'All sites status are ok' }, ]; - + $self->{maps_counters}->{global} = [ { label => 'link-status', threshold => 0, set => { key_values => [ { name => 'LinkStatus' } ], @@ -145,12 +145,13 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'no-ps' => { name => 'no_ps' }, - 'ps-exec-only' => { name => 'ps_exec_only' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, 'critical-link-status:s' => { name => 'critical_link_status', default => '' }, 'warning-site-status:s' => { name => 'warning_site_status', default => '' }, @@ -165,18 +166,29 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_link_status', 'critical_link_status', - 'warning_site_status', 'critical_site_status']); + $self->change_macros(macros => [ + 'warning_link_status', 'critical_link_status', + 'warning_site_status', 'critical_site_status' + ]); } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::sccm::databasereplicationstatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - ); - - $self->{option_results}->{command_options} .= " " . $ps; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::sccm::databasereplicationstatus::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, @@ -185,8 +197,10 @@ sub manage_selection { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -253,6 +267,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/sccm/local/mode/sitestatus.pm b/centreon-plugins/apps/sccm/local/mode/sitestatus.pm index 8f61dd050..8d9068800 100644 --- a/centreon-plugins/apps/sccm/local/mode/sitestatus.pm +++ b/centreon-plugins/apps/sccm/local/mode/sitestatus.pm @@ -26,6 +26,7 @@ use strict; use warnings; use JSON::XS; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::misc; use centreon::common::powershell::sccm::sitestatus; my %map_mode = ( @@ -60,11 +61,11 @@ my %map_type = ( sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("status is '%s' [Type: %s] [Mode: '%s']", + return sprintf("status is '%s' [Type: %s] [Mode: '%s']", $self->{result_values}->{status}, $self->{result_values}->{type}, - $self->{result_values}->{mode}); - return $msg; + $self->{result_values}->{mode} + ); } sub custom_status_calc { @@ -75,17 +76,17 @@ sub custom_status_calc { $self->{result_values}->{mode} = $options{new_datas}->{$self->{instance} . '_Mode'}; $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_Status'}; $self->{result_values}->{secondary_site_status} = $options{new_datas}->{$self->{instance} . '_SecondarySiteCMUpdateStatus'}; - + return 0; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'sites', type => 1, cb_prefix_output => 'prefix_output_site', message_multiple => 'All sites status are ok' }, ]; - + $self->{maps_counters}->{sites} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'display' }, { name => 'SiteName' }, { name => 'Type' }, { name => 'Mode' }, @@ -109,18 +110,19 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'no-ps' => { name => 'no_ps' }, - 'ps-exec-only' => { name => 'ps_exec_only' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); - + return $self; } @@ -133,12 +135,21 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::sccm::sitestatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - ); - - $self->{option_results}->{command_options} .= " " . $ps; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::sccm::sitestatus::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, @@ -147,8 +158,10 @@ sub manage_selection { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -221,6 +234,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/wsus/local/mode/computersstatus.pm b/centreon-plugins/apps/wsus/local/mode/computersstatus.pm index 75425c46b..8ddcc0cbf 100644 --- a/centreon-plugins/apps/wsus/local/mode/computersstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/computersstatus.pm @@ -25,15 +25,16 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use JSON::XS; +use centreon::plugins::misc; use centreon::common::powershell::wsus::computersstatus; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_output' }, ]; - + $self->{maps_counters}->{global} = [ { label => 'up-to-date', set => { key_values => [ { name => 'ComputersUpToDateCount' } ], @@ -93,21 +94,21 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "wsus-server:s" => { name => 'wsus_server', default => 'localhost' }, - "wsus-port:s" => { name => 'wsus_port', default => 8530 }, - "not-updated-since:s" => { name => 'not_updated_since', default => 10 }, - "use-ssl" => { name => 'use_ssl' }, - "filter-counters:s" => { name => 'filter_counters' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'wsus-server:s' => { name => 'wsus_server', default => 'localhost' }, + 'wsus-port:s' => { name => 'wsus_port', default => 8530 }, + 'not-updated-since:s' => { name => 'not_updated_since', default => 10 }, + 'use-ssl' => { name => 'use_ssl' }, }); - + return $self; } @@ -121,28 +122,43 @@ sub manage_selection { my $use_ssl = "\$false"; $use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl})); - - my $ps = centreon::common::powershell::wsus::computersstatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - wsus_server => $self->{option_results}->{wsus_server}, - wsus_port => $self->{option_results}->{wsus_port}, - not_updated_since => $self->{option_results}->{not_updated_since}, - use_ssl => $use_ssl - ); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::wsus::computersstatus::get_powershell( + wsus_server => $self->{option_results}->{wsus_server}, + wsus_port => $self->{option_results}->{wsus_port}, + not_updated_since => $self->{option_results}->{not_updated_since}, + use_ssl => $use_ssl + ); + + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + my $decoded; eval { $decoded = JSON::XS->new->utf8->decode(centreon::plugins::misc::powershell_json_sanitizer(string => $stdout, output => $self->{output})); @@ -186,6 +202,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm b/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm index 51f4f8c5a..d83b6132e 100644 --- a/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm +++ b/centreon-plugins/apps/wsus/local/mode/serverstatistics.pm @@ -25,15 +25,16 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use JSON::XS; +use centreon::plugins::misc; use centreon::common::powershell::wsus::serverstatistics; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, ]; - + $self->{maps_counters}->{global} = [ { label => 'computers', set => { key_values => [ { name => 'ComputerTargetCount' } ], @@ -114,18 +115,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "wsus-server:s" => { name => 'wsus_server', default => 'localhost' }, - "wsus-port:s" => { name => 'wsus_port', default => 8530 }, - "use-ssl" => { name => 'use_ssl' }, - "filter-counters:s" => { name => 'filter_counters' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'wsus-server:s' => { name => 'wsus_server', default => 'localhost' }, + 'wsus-port:s' => { name => 'wsus_port', default => 8530 }, + 'use-ssl' => { name => 'use_ssl' }, }); return $self; @@ -141,23 +142,37 @@ sub manage_selection { my $use_ssl = "\$false"; $use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl})); - - my $ps = centreon::common::powershell::wsus::serverstatistics::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - wsus_server => $self->{option_results}->{wsus_server}, - wsus_port => $self->{option_results}->{wsus_port}, - use_ssl => $use_ssl - ); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::wsus::serverstatistics::get_powershell( + wsus_server => $self->{option_results}->{wsus_server}, + wsus_port => $self->{option_results}->{wsus_port}, + use_ssl => $use_ssl + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -205,6 +220,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm b/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm index 91a395654..bd466c052 100644 --- a/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/synchronisationstatus.pm @@ -26,6 +26,7 @@ use strict; use warnings; use JSON::XS; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::misc; use centreon::common::powershell::wsus::synchronisationstatus; use DateTime; @@ -60,11 +61,13 @@ sub custom_last_status_calc { sub custom_progress_perfdata { my ($self, %options) = @_; - $self->{output}->perfdata_add(label => 'synchronisation_progress', - value => $self->{result_values}->{progress}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'synchronisation_progress', + value => $self->{result_values}->{progress}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), + min => 0, max => 100 + ); } sub custom_progress_threshold { @@ -79,11 +82,11 @@ sub custom_progress_threshold { sub custom_progress_output { my ($self, %options) = @_; - my $msg = sprintf("Progress: %.2f%% (%d/%d items)", + return sprintf("Progress: %.2f%% (%d/%d items)", $self->{result_values}->{progress}, $self->{result_values}->{processed}, - $self->{result_values}->{total}); - return $msg; + $self->{result_values}->{total} + ); } sub custom_progress_calc { @@ -102,11 +105,13 @@ sub custom_progress_calc { sub custom_duration_perfdata { my ($self, %options) = @_; - $self->{output}->perfdata_add(label => 'last_synchronisation_duration', - value => $self->{result_values}->{duration}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), - min => 0, unit => 's'); + $self->{output}->perfdata_add( + label => 'last_synchronisation_duration', + value => $self->{result_values}->{duration}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), + min => 0, unit => 's' + ); } sub custom_duration_threshold { @@ -121,8 +126,7 @@ sub custom_duration_threshold { sub custom_duration_output { my ($self, %options) = @_; - my $msg = sprintf("Duration: %s", centreon::plugins::misc::change_seconds(value => $self->{result_values}->{duration})); - return $msg; + return sprintf('Duration: %s', centreon::plugins::misc::change_seconds(value => $self->{result_values}->{duration})); } sub custom_duration_calc { @@ -144,12 +148,12 @@ sub custom_duration_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'current', type => 0, cb_prefix_output => 'prefix_output_current' }, { name => 'last', type => 0, cb_prefix_output => 'prefix_output_last' }, ]; - + $self->{maps_counters}->{current} = [ { label => 'synchronisation-status', threshold => 0, set => { key_values => [ { name => 'SynchronizationStatus' } ], @@ -204,24 +208,25 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "wsus-server:s" => { name => 'wsus_server', default => 'localhost' }, - "wsus-port:s" => { name => 'wsus_port', default => 8530 }, - "use-ssl" => { name => 'use_ssl' }, - "warning-synchronisation-status:s" => { name => 'warning_synchronisation_status', default => '' }, - "critical-synchronisation-status:s" => { name => 'critical_synchronisation_status', default => '' }, - "warning-last-synchronisation-status:s" => { name => 'warning_last_synchronisation_status', default => '' }, - "critical-last-synchronisation-status:s" => { name => 'critical_last_synchronisation_status', default => '%{status} !~ /Succeeded/' }, - "timezone:s" => { name => 'timezone', default => 'UTC' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'wsus-server:s' => { name => 'wsus_server', default => 'localhost' }, + 'wsus-port:s' => { name => 'wsus_port', default => 8530 }, + 'use-ssl' => { name => 'use_ssl' }, + 'timezone:s' => { name => 'timezone', default => 'UTC' }, + 'warning-synchronisation-status:s' => { name => 'warning_synchronisation_status', default => '' }, + 'critical-synchronisation-status:s' => { name => 'critical_synchronisation_status', default => '' }, + 'warning-last-synchronisation-status:s' => { name => 'warning_last_synchronisation_status', default => '' }, + 'critical-last-synchronisation-status:s' => { name => 'critical_last_synchronisation_status', default => '%{status} !~ /Succeeded/' }, }); - + return $self; } @@ -229,8 +234,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_synchronisation_status', 'critical_synchronisation_status', - 'warning_last_synchronisation_status', 'critical_last_synchronisation_status']); + $self->change_macros(macros => [ + 'warning_synchronisation_status', 'critical_synchronisation_status', + 'warning_last_synchronisation_status', 'critical_last_synchronisation_status'] + ); } sub manage_selection { @@ -238,23 +245,37 @@ sub manage_selection { my $use_ssl = "\$false"; $use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl})); - - my $ps = centreon::common::powershell::wsus::synchronisationstatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - wsus_server => $self->{option_results}->{wsus_server}, - wsus_port => $self->{option_results}->{wsus_port}, - use_ssl => $use_ssl - ); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::wsus::synchronisationstatus::get_powershell( + wsus_server => $self->{option_results}->{wsus_server}, + wsus_port => $self->{option_results}->{wsus_port}, + use_ssl => $use_ssl + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -311,6 +332,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm b/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm index 0d949dd3b..dee5932c2 100644 --- a/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm +++ b/centreon-plugins/apps/wsus/local/mode/updatesstatus.pm @@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use JSON::XS; +use centreon::plugins::misc; use centreon::common::powershell::wsus::updatesstatus; sub set_counters { @@ -93,20 +94,20 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "wsus-server:s" => { name => 'wsus_server', default => 'localhost' }, - "wsus-port:s" => { name => 'wsus_port', default => 8530 }, - "use-ssl" => { name => 'use_ssl' }, - "filter-counters:s" => { name => 'filter_counters' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'wsus-server:s' => { name => 'wsus_server', default => 'localhost' }, + 'wsus-port:s' => { name => 'wsus_port', default => 8530 }, + 'use-ssl' => { name => 'use_ssl' }, }); - + return $self; } @@ -120,27 +121,41 @@ sub manage_selection { my $use_ssl = "\$false"; $use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl})); - - my $ps = centreon::common::powershell::wsus::updatesstatus::get_powershell( - no_ps => $self->{option_results}->{no_ps}, - wsus_server => $self->{option_results}->{wsus_server}, - wsus_port => $self->{option_results}->{wsus_port}, - use_ssl => $use_ssl - ); - $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::wsus::updatesstatus::get_powershell( + wsus_server => $self->{option_results}->{wsus_server}, + wsus_port => $self->{option_results}->{wsus_port}, + use_ssl => $use_ssl + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + my $decoded; eval { $decoded = JSON::XS->new->utf8->decode(centreon::plugins::misc::powershell_json_sanitizer(string => $stdout, output => $self->{output})); @@ -184,6 +199,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/apps/wsus/local/plugin.pm b/centreon-plugins/apps/wsus/local/plugin.pm index ace11c15b..8cfdb9c2a 100644 --- a/centreon-plugins/apps/wsus/local/plugin.pm +++ b/centreon-plugins/apps/wsus/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'computers-status' => 'apps::wsus::local::mode::computersstatus', - 'server-statistics' => 'apps::wsus::local::mode::serverstatistics', - 'synchronisation-status' => 'apps::wsus::local::mode::synchronisationstatus', - 'updates-status' => 'apps::wsus::local::mode::updatesstatus', + 'computers-status' => 'apps::wsus::local::mode::computersstatus', + 'server-statistics' => 'apps::wsus::local::mode::serverstatistics', + 'synchronisation-status' => 'apps::wsus::local::mode::synchronisationstatus', + 'updates-status' => 'apps::wsus::local::mode::updatesstatus', ); return $self; diff --git a/centreon-plugins/centreon/common/powershell/dell/compellent/hbausage.pm b/centreon-plugins/centreon/common/powershell/dell/compellent/hbausage.pm index a1ecd2da9..b89b8ce71 100644 --- a/centreon-plugins/centreon/common/powershell/dell/compellent/hbausage.pm +++ b/centreon-plugins/centreon/common/powershell/dell/compellent/hbausage.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::dell::compellent::hbausage; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -94,7 +90,7 @@ $ret = Remove-DellSavedApiConnection -Name $connName exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -105,4 +101,4 @@ __END__ Method to get compellent hba informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm b/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm index 35432d30d..ecce9fb85 100644 --- a/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm +++ b/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::dell::compellent::volumeusage; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -107,7 +103,7 @@ $ret = Remove-DellSavedApiConnection -Name $connName exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -118,4 +114,4 @@ __END__ Method to get compellent volume informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm index 6c70524cb..acda49bc5 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm @@ -26,9 +26,6 @@ use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -52,7 +49,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } @@ -65,8 +62,10 @@ sub list { foreach my $line (split /\n/, $options{stdout}) { next if ($line !~ /^\[name=(.*?)\]\[state=(.*?)\]\[status=(.*?)\]\[IsClustered=(.*?)\]\[note=(.*?)\]/); - my ($name, $state, $status, $IsClustered, $note) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), - centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + my ($name, $state, $status, $IsClustered, $note) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5) + ); $self->{output}->output_add(long_msg => "'" . $name . "' [state = $state, status = " . $status . ']'); } @@ -81,12 +80,18 @@ sub disco_show { foreach my $line (split /\n/, $options{stdout}) { next if ($line !~ /^\[name=(.*?)\]\[state=(.*?)\]\[status=(.*?)\]\[IsClustered=(.*?)\]\[note=(.*?)\]/); - my ($name, $state, $status, $IsClustered, $note) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), - centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + my ($name, $state, $status, $IsClustered, $note) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5) + ); - $self->{output}->add_disco_entry(name => $name, - state => $state, - status => $status, is_clustered => $IsClustered, note => $note); + $self->{output}->add_disco_entry( + name => $name, + state => $state, + status => $status, + is_clustered => $IsClustered, + note => $note + ); } } @@ -98,4 +103,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index 6729ab183..08c0922f1 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::nodeintegrationservice; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -55,7 +51,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -66,4 +62,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm index cb99818c6..d9592a1a6 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::nodereplication; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -50,7 +46,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -61,4 +57,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm index a36bafdef..dcbf11273 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::nodesnapshot; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -78,7 +74,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm index f02eb70f9..1aa780ba3 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::nodevmstatus; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -63,7 +59,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm index ed66ebb62..ca4d72fbb 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::scvmmintegrationservice; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -69,7 +65,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -80,4 +76,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm index bbac9c66b..d91ae71ef 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::scvmmsnapshot; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -67,7 +63,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -78,4 +74,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm index 04e36b72e..8f90fe66f 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::hyperv::2012::scvmmvmstatus; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -59,7 +55,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; @@ -70,4 +66,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/powershell/sccm/databasereplicationstatus.pm b/centreon-plugins/centreon/common/powershell/sccm/databasereplicationstatus.pm index ab7204df2..2d7360c58 100644 --- a/centreon-plugins/centreon/common/powershell/sccm/databasereplicationstatus.pm +++ b/centreon-plugins/centreon/common/powershell/sccm/databasereplicationstatus.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -83,7 +80,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/sccm/sitestatus.pm b/centreon-plugins/centreon/common/powershell/sccm/sitestatus.pm index 6989d3e08..437d14562 100644 --- a/centreon-plugins/centreon/common/powershell/sccm/sitestatus.pm +++ b/centreon-plugins/centreon/common/powershell/sccm/sitestatus.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -78,7 +75,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/veeam/jobstatus.pm b/centreon-plugins/centreon/common/powershell/veeam/jobstatus.pm index 0bc681ef5..efaeb0b51 100644 --- a/centreon-plugins/centreon/common/powershell/veeam/jobstatus.pm +++ b/centreon-plugins/centreon/common/powershell/veeam/jobstatus.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::veeam::jobstatus; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -75,7 +71,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/veeam/listjobs.pm b/centreon-plugins/centreon/common/powershell/veeam/listjobs.pm index a37dc7df6..7d6859267 100644 --- a/centreon-plugins/centreon/common/powershell/veeam/listjobs.pm +++ b/centreon-plugins/centreon/common/powershell/veeam/listjobs.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::veeam::listjobs; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -66,7 +62,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/windows/liststorages.pm b/centreon-plugins/centreon/common/powershell/windows/liststorages.pm index 041405da0..a9fa92e56 100644 --- a/centreon-plugins/centreon/common/powershell/windows/liststorages.pm +++ b/centreon-plugins/centreon/common/powershell/windows/liststorages.pm @@ -26,9 +26,6 @@ use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -50,8 +47,9 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } + 1; sub list { @@ -62,11 +60,12 @@ sub list { #... foreach my $line (split /\n/, $options{stdout}) { next if ($line !~ /^\[name=(.*?)\]\[type=(.*?)\]\[providername=.*?\]\[desc=(.*?)\]\[size=(.*?)\]\[freespace=(.*?)\]/); - my ($disk, $type, $desc, $size, $free) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), - centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + my ($disk, $type, $desc, $size, $free) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5) + ); $self->{output}->output_add(long_msg => "'" . $disk . "' [size = $size, free = $free, desc = $desc, type = $map_type{$type}]"); - } } 1; @@ -81,14 +80,18 @@ sub disco_show { #... foreach my $line (split /\n/, $options{stdout}) { next if ($line !~ /^\[name=(.*?)\]\[type=(.*?)\]\[providername=.*?\]\[desc=(.*?)\]\[size=(.*?)\]\[freespace=(.*?)\]/); - my ($disk, $type, $desc, $size, $free) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), - centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + my ($disk, $type, $desc, $size, $free) = ( + centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5) + ); - $self->{output}->add_disco_entry(name => $disk, - size => $size, - free => $free, - type => $map_type{$type}, - desc => $desc); + $self->{output}->add_disco_entry( + name => $disk, + size => $size, + free => $free, + type => $map_type{$type}, + desc => $desc + ); } } diff --git a/centreon-plugins/centreon/common/powershell/windows/pendingreboot.pm b/centreon-plugins/centreon/common/powershell/windows/pendingreboot.pm index faa942e00..17f393c7d 100644 --- a/centreon-plugins/centreon/common/powershell/windows/pendingreboot.pm +++ b/centreon-plugins/centreon/common/powershell/windows/pendingreboot.pm @@ -22,13 +22,9 @@ package centreon::common::powershell::windows::pendingreboot; use strict; use warnings; -use centreon::plugins::misc; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -126,7 +122,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/wsus/computersstatus.pm b/centreon-plugins/centreon/common/powershell/wsus/computersstatus.pm index abf6a3e5f..30940205b 100644 --- a/centreon-plugins/centreon/common/powershell/wsus/computersstatus.pm +++ b/centreon-plugins/centreon/common/powershell/wsus/computersstatus.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -83,7 +80,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/wsus/serverstatistics.pm b/centreon-plugins/centreon/common/powershell/wsus/serverstatistics.pm index 218f5f4df..6d08ba700 100644 --- a/centreon-plugins/centreon/common/powershell/wsus/serverstatistics.pm +++ b/centreon-plugins/centreon/common/powershell/wsus/serverstatistics.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -79,7 +76,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/wsus/synchronisationstatus.pm b/centreon-plugins/centreon/common/powershell/wsus/synchronisationstatus.pm index 449bd80fc..0b4c317f7 100644 --- a/centreon-plugins/centreon/common/powershell/wsus/synchronisationstatus.pm +++ b/centreon-plugins/centreon/common/powershell/wsus/synchronisationstatus.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -79,7 +76,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/centreon/common/powershell/wsus/updatesstatus.pm b/centreon-plugins/centreon/common/powershell/wsus/updatesstatus.pm index c36c901cd..317dbf41b 100644 --- a/centreon-plugins/centreon/common/powershell/wsus/updatesstatus.pm +++ b/centreon-plugins/centreon/common/powershell/wsus/updatesstatus.pm @@ -26,9 +26,6 @@ use centreon::common::powershell::functions; sub get_powershell { my (%options) = @_; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -76,7 +73,7 @@ Try { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } 1; diff --git a/centreon-plugins/database/postgres/plugin.pm b/centreon-plugins/database/postgres/plugin.pm index 63f25f329..a243d814e 100644 --- a/centreon-plugins/database/postgres/plugin.pm +++ b/centreon-plugins/database/postgres/plugin.pm @@ -79,8 +79,8 @@ sub init { $self->{sqldefault}->{psqlcmd}[$i]->{dbname} = $options_result->{db_name}[$i]; } } - - $self->SUPER::init(%options); + + $self->SUPER::init(%options); } 1; diff --git a/centreon-plugins/os/windows/local/mode/liststorages.pm b/centreon-plugins/os/windows/local/mode/liststorages.pm index e068522ff..52e6efa31 100644 --- a/centreon-plugins/os/windows/local/mode/liststorages.pm +++ b/centreon-plugins/os/windows/local/mode/liststorages.pm @@ -38,7 +38,8 @@ sub new { 'command:s' => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'ps-exec-only' => { name => 'ps_exec_only', } + 'ps-exec-only' => { name => 'ps_exec_only', }, + 'ps-display' => { name => 'ps_display' } }); return $self; @@ -51,10 +52,20 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps}); - $self->{option_results}->{command_options} .= " " . $ps; + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::windows::liststorages::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } my ($stdout) = centreon::plugins::misc::windows_execute( output => $self->{output}, @@ -64,30 +75,36 @@ sub run { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => 'List disk:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List disk:' + ); centreon::common::powershell::windows::liststorages::list($self, stdout => $stdout); } - + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name', 'size', 'free', 'type', 'desc']); } sub disco_show { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::windows::liststorages::get_powershell(); + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::windows_execute( output => $self->{output}, timeout => $self->{option_results}->{timeout}, @@ -129,6 +146,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/os/windows/local/mode/pendingreboot.pm b/centreon-plugins/os/windows/local/mode/pendingreboot.pm index 024384a52..3efd04a43 100644 --- a/centreon-plugins/os/windows/local/mode/pendingreboot.pm +++ b/centreon-plugins/os/windows/local/mode/pendingreboot.pm @@ -30,8 +30,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = sprintf( + + return sprintf( 'Reboot Pending: %s [Windows Update: %s][Component Based Servicing: %s][SCCM Client: %s][File Rename Operations: %s][Computer Name Change: %s]', $self->{result_values}->{RebootPending}, $self->{result_values}->{WindowsUpdate}, @@ -40,12 +40,11 @@ sub custom_status_output { $self->{result_values}->{PendFileRename}, $self->{result_values}->{PendComputerRename} ); - return $msg; } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{CBServicing} = $options{new_datas}->{$self->{instance} . '_CBServicing'}; $self->{result_values}->{RebootPending} = $options{new_datas}->{$self->{instance} . '_RebootPending'}; $self->{result_values}->{WindowsUpdate} = $options{new_datas}->{$self->{instance} . '_WindowsUpdate'}; @@ -57,7 +56,7 @@ sub custom_status_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'pendingreboot', type => 0 }, ]; @@ -78,7 +77,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' }, @@ -86,8 +85,9 @@ sub new { 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, 'warning-status:s' => { name => 'warning_status', default => '%{RebootPending} =~ /true/i' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } }); return $self; @@ -96,17 +96,27 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::windows::pendingreboot::get_powershell( - no_ps => $self->{option_results}->{no_ps}); - - $self->{option_results}->{command_options} .= " " . $ps; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::windows::pendingreboot::get_powershell(); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, @@ -115,8 +125,10 @@ sub manage_selection { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -159,6 +171,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm index 0a701b462..de5a1190e 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm @@ -105,23 +105,24 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - 'cem-host:s' => { name => 'cem_host' }, - 'cem-user:s' => { name => 'cem_user' }, - 'cem-password:s' => { name => 'cem_password' }, - 'cem-port:s' => { name => 'cem_port', default => 3033 }, - 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, - 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'no-ps' => { name => 'no_ps' }, - 'ps-exec-only' => { name => 'ps_exec_only' }, - 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, - 'start-time:s' => { name => 'start_time' }, - 'end-time:s' => { name => 'end_time' }, - 'timezone:s' => { name => 'timezone' }, + 'cem-host:s' => { name => 'cem_host' }, + 'cem-user:s' => { name => 'cem_user' }, + 'cem-password:s' => { name => 'cem_password' }, + 'cem-port:s' => { name => 'cem_port', default => 3033 }, + 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, + 'start-time:s' => { name => 'start_time' }, + 'end-time:s' => { name => 'end_time' }, + 'timezone:s' => { name => 'timezone' }, }); return $self; @@ -131,23 +132,23 @@ sub get_iso8601 { my ($self, %options) = @_; my $value = $options{date}->datetime . '.' . sprintf("%03d", $options{date}->millisecond()); my $offset = $options{date}->offset(); - + $value .= "-" if ($offset < 0); $value .= "+" if ($offset >= 0); $offset = abs($offset); $value .= sprintf("%02d:%02d", $offset / 3600, $offset % 3600); - + return $value; } sub parse_date { my ($self, %options) = @_; - + if ($options{date} !~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/) { $self->{output}->add_option_msg(short_msg => "Wrong time option '" . $options{date} . "'."); $self->{output}->option_exit(); } - + my $dt = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %{$self->{tz}} @@ -158,7 +159,7 @@ sub parse_date { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); foreach my $label (('cem_host', 'cem_user', 'cem_password', 'cem_port', 'sdk_path_dll')) { if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { @@ -168,7 +169,7 @@ sub check_options { $self->{output}->option_exit(); } } - + my ($dt_start, $dt_end); $self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); if (defined($self->{option_results}->{end_time}) && $self->{option_results}->{end_time} ne '') { @@ -177,7 +178,7 @@ sub check_options { $dt_end = DateTime->now(%{$self->{tz}}); } $self->{end_time} = $self->get_iso8601(date => $dt_end); - + if (defined($self->{option_results}->{start_time}) && $self->{option_results}->{start_time} ne '') { $dt_start = $self->parse_date(date => $self->{option_results}->{start_time}); } else { @@ -188,19 +189,29 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::dell::compellent::hbausage::get_powershell( - cem_host => $self->{option_results}->{cem_host}, - cem_user => $self->{option_results}->{cem_user}, - cem_password => $self->{option_results}->{cem_password}, - cem_port => $self->{option_results}->{cem_port}, - sdk_path_dll => $self->{option_results}->{sdk_path_dll}, - no_ps => $self->{option_results}->{no_ps}, - filter_sc => $self->{option_results}->{ps_sc_filter}, - end_time => $self->{end_time}, start_time => $self->{start_time} - ); - - $self->{option_results}->{command_options} .= " " . $ps; + + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::dell::compellent::hbausage::get_powershell( + cem_host => $self->{option_results}->{cem_host}, + cem_user => $self->{option_results}->{cem_user}, + cem_password => $self->{option_results}->{cem_password}, + cem_port => $self->{option_results}->{cem_port}, + sdk_path_dll => $self->{option_results}->{sdk_path_dll}, + filter_sc => $self->{option_results}->{ps_sc_filter}, + end_time => $self->{end_time}, start_time => $self->{start_time} + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::windows_execute( output => $self->{output}, timeout => $self->{option_results}->{timeout}, @@ -209,12 +220,14 @@ sub manage_selection { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + # microseconds for latencies #[sc=PRD-SAN-01][name=xxxx][ReadIops=39,5][ReadKbPerSecond=1220,75][ReadLatency=3997][WriteIops=95,75][WriteKbPerSecond=1217][WriteLatency=3903,25] $self->{hba} = {}; @@ -223,7 +236,7 @@ sub manage_selection { my ($sc, $name, $read_iops, $read_kbps, $read_latency, $write_iops, $write_kbps, $write_latency) = ($1, $2, $3, $4, $5, $6, $7, $8); my $display = $sc . '/' . $name; - + $self->{hba}->{$name} = { display => $display, read_iops => $read_iops, read_bps => $read_kbps * 1000, read_latency => $read_latency / 1000, write_iops => $write_iops, write_bps => $write_kbps * 1000, write_latency => $write_latency / 1000 @@ -282,6 +295,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output. diff --git a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm index 3410faf2f..aa8dfe2cc 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm @@ -29,11 +29,12 @@ use centreon::common::powershell::dell::compellent::volumeusage; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'sc', type => 1, cb_prefix_output => 'prefix_sc_output', message_multiple => 'All storage centers are ok', cb_init => 'sc_init' }, { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' } ]; + $self->{maps_counters}->{sc} = [ { label => 'sc-total', set => { key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], @@ -44,7 +45,7 @@ sub set_counters { } }, ]; - + $self->{maps_counters}->{volume} = [ { label => 'volume-usage', set => { key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], @@ -79,19 +80,19 @@ sub set_counters { sub prefix_sc_output { my ($self, %options) = @_; - + return "Storage center '" . $options{instance_value}->{display} . "' "; } sub prefix_volume_output { my ($self, %options) = @_; - + return "Volume '" . $options{instance_value}->{display} . "' "; } sub sc_init { my ($self, %options) = @_; - + if (defined($self->{option_results}->{ps_sc_volume}) && $self->{option_results}->{ps_sc_volume} ne '') { return 1; } @@ -100,7 +101,7 @@ sub sc_init { sub custom_usage_perfdata { my ($self, %options) = @_; - + my $label = $self->{result_values}->{type} . '_used'; my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { @@ -126,7 +127,7 @@ sub custom_usage_perfdata { sub custom_usage_threshold { my ($self, %options) = @_; - + my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); @@ -140,14 +141,16 @@ sub custom_usage_threshold { sub custom_usage_output { my ($self, %options) = @_; - + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("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( + "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; } @@ -167,7 +170,7 @@ sub custom_usage_calc { $self->{result_values}->{free} = 0; $self->{result_values}->{prct_free} = 0; } - + return 0; } @@ -175,23 +178,24 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - 'cem-host:s' => { name => 'cem_host' }, - 'cem-user:s' => { name => 'cem_user' }, - 'cem-password:s' => { name => 'cem_password' }, - 'cem-port:s' => { name => 'cem_port', default => 3033 }, - 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, - 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - 'no-ps' => { name => 'no_ps' }, - 'ps-exec-only' => { name => 'ps_exec_only' }, - 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, - 'ps-sc-volume:s' => { name => 'ps_sc_volume' }, - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, + 'cem-host:s' => { name => 'cem_host' }, + 'cem-user:s' => { name => 'cem_user' }, + 'cem-password:s' => { name => 'cem_password' }, + 'cem-port:s' => { name => 'cem_port', default => 3033 }, + 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, + 'ps-sc-volume:s' => { name => 'ps_sc_volume' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; @@ -200,7 +204,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + foreach my $label (('cem_host', 'cem_user', 'cem_password', 'cem_port', 'sdk_path_dll')) { if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { my ($label_opt) = $label; @@ -213,19 +217,29 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell( - cem_host => $self->{option_results}->{cem_host}, - cem_user => $self->{option_results}->{cem_user}, - cem_password => $self->{option_results}->{cem_password}, - cem_port => $self->{option_results}->{cem_port}, - sdk_path_dll => $self->{option_results}->{sdk_path_dll}, - no_ps => $self->{option_results}->{no_ps}, - filter_sc => $self->{option_results}->{ps_sc_filter}, - filter_vol => $self->{option_results}->{ps_sc_volume} - ); - $self->{option_results}->{command_options} .= " " . $ps; + if (!defined($self->{option_results}->{no_ps})) { + my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell( + cem_host => $self->{option_results}->{cem_host}, + cem_user => $self->{option_results}->{cem_user}, + cem_password => $self->{option_results}->{cem_password}, + cem_port => $self->{option_results}->{cem_port}, + sdk_path_dll => $self->{option_results}->{sdk_path_dll}, + filter_sc => $self->{option_results}->{ps_sc_filter}, + filter_vol => $self->{option_results}->{ps_sc_volume} + ); + if (defined($self->{option_results}->{ps_display})) { + $self->{output}->output_add( + severity => 'OK', + short_msg => $ps + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + $self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); + } + my ($stdout) = centreon::plugins::misc::windows_execute( output => $self->{output}, timeout => $self->{option_results}->{timeout}, @@ -234,12 +248,14 @@ sub manage_selection { command_options => $self->{option_results}->{command_options} ); if (defined($self->{option_results}->{ps_exec_only})) { - $self->{output}->output_add(severity => 'OK', - short_msg => $stdout); + $self->{output}->output_add( + severity => 'OK', + short_msg => $stdout + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } - + # [sc=PRD-SAN-01][volume=SC-S06][configuredSpace=xxxxx][freeSpace=xxxxx][activeSpace=xxxxx][raidOverhead=xxx][totalDiskSpace=xxxx][replaySpace=xxxx] $self->{volume} = {}; $self->{sc} = {}; @@ -247,7 +263,7 @@ sub manage_selection { my ($sc, $volume, $configured_space, $free_space, $active_space, $raid_overhead, $total_disk_space, $replay_space) = ($1, $2, $3, $4, $5, $6, $7, $8); my $name = $sc . '/' . $volume; - + $self->{volume}->{$name} = { display => $name, total => $configured_space, type => 'volume', used => $active_space + $raid_overhead + $replay_space, @@ -316,6 +332,10 @@ Command path (Default: none). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). +=item B<--ps-display> + +Display powershell script. + =item B<--ps-exec-only> Print powershell output.