From 036ef13b11907d821c4c5239d764f5971c1de119 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Jan 2020 11:07:46 +0100 Subject: [PATCH] wip: add an option to display powershell --- .../2010/local/mode/activesyncmailbox.pm | 97 +++++++++------ apps/exchange/2010/local/mode/databases.pm | 112 +++++++++++------- apps/exchange/2010/local/mode/imapmailbox.pm | 86 ++++++++------ .../exchange/2010/local/mode/listdatabases.pm | 46 +++---- apps/exchange/2010/local/mode/mapimailbox.pm | 90 ++++++++------ .../2010/local/mode/outlookwebservices.pm | 86 ++++++++------ apps/exchange/2010/local/mode/owamailbox.pm | 101 +++++++++------- apps/exchange/2010/local/mode/queues.pm | 84 ++++++++----- .../2010/local/mode/replicationhealth.pm | 86 ++++++++------ apps/exchange/2010/local/mode/services.pm | 84 ++++++++----- .../exchange/2010/activesyncmailbox.pm | 20 ++-- .../powershell/exchange/2010/databases.pm | 11 +- .../powershell/exchange/2010/imapmailbox.pm | 6 +- .../powershell/exchange/2010/listdatabases.pm | 8 +- .../powershell/exchange/2010/mapimailbox.pm | 8 +- .../exchange/2010/outlookwebservices.pm | 6 +- .../powershell/exchange/2010/owamailbox.pm | 8 +- .../powershell/exchange/2010/powershell.pm | 6 +- .../common/powershell/exchange/2010/queues.pm | 6 +- .../exchange/2010/replicationhealth.pm | 6 +- .../powershell/exchange/2010/services.pm | 8 +- centreon/common/powershell/functions.pm | 2 +- centreon/plugins/misc.pm | 21 ++-- 23 files changed, 568 insertions(+), 420 deletions(-) diff --git a/apps/exchange/2010/local/mode/activesyncmailbox.pm b/apps/exchange/2010/local/mode/activesyncmailbox.pm index 0dda4294c..e7e4824da 100644 --- a/apps/exchange/2010/local/mode/activesyncmailbox.pm +++ b/apps/exchange/2010/local/mode/activesyncmailbox.pm @@ -31,30 +31,31 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, - "mailbox:s" => { name => 'mailbox', }, - "password:s" => { name => 'password', }, - "no-trust-ssl" => { name => 'no_trust_ssl', }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' }, + 'mailbox:s' => { name => 'mailbox' }, + 'password:s' => { name => 'password' }, + 'no-trust-ssl' => { name => 'no_trust_ssl' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -79,29 +80,45 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::activesyncmailbox::get_powershell(remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - mailbox => $self->{option_results}->{mailbox}, - password => $self->{option_results}->{password}, - no_ps => $self->{option_results}->{no_ps}, - no_trust_ssl => $self->{option_results}->{no_trust_ssl} - ); - $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::activesyncmailbox::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + mailbox => $self->{option_results}->{mailbox}, + password => $self->{option_results}->{password}, + no_trust_ssl => $self->{option_results}->{no_trust_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::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 + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } centreon::common::powershell::exchange::2010::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); - + $self->{output}->display(); $self->{output}->exit(); } @@ -149,6 +166,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. @@ -177,4 +198,4 @@ By default, SSL certificate validy is not checked. =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/databases.pm b/apps/exchange/2010/local/mode/databases.pm index a86797814..0f639e068 100644 --- a/apps/exchange/2010/local/mode/databases.pm +++ b/apps/exchange/2010/local/mode/databases.pm @@ -31,36 +31,37 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "no-mailflow" => { name => 'no_mailflow', }, - "no-mapi" => { name => 'no_mapi', }, - "no-copystatus" => { name => 'no_copystatus', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "ps-database-filter:s" => { name => 'ps_database_filter', }, - "ps-database-test-filter:s" => { name => 'ps_database_test_filter', }, - "warning-mapi:s" => { name => 'warning_mapi', }, - "critical-mapi:s" => { name => 'critical_mapi', default => '%{mapi_result} !~ /Success/i' }, - "warning-mailflow:s" => { name => 'warning_mailflow', }, - "critical-mailflow:s" => { name => 'critical_mailflow', default => '%{mailflow_result} !~ /Success/i' }, - "warning-copystatus:s" => { name => 'warning_copystatus', }, - "critical-copystatus:s" => { name => 'critical_copystatus', default => '%{copystatus_indexstate} !~ /Healthy/i' }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + 'no-mailflow' => { name => 'no_mailflow' }, + 'no-mapi' => { name => 'no_mapi' }, + 'no-copystatus' => { name => 'no_copystatus' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'ps-database-filter:s' => { name => 'ps_database_filter' }, + 'ps-database-test-filter:s' => { name => 'ps_database_test_filter' }, + 'warning-mapi:s' => { name => 'warning_mapi' }, + 'critical-mapi:s' => { name => 'critical_mapi', default => '%{mapi_result} !~ /Success/i' }, + 'warning-mailflow:s' => { name => 'warning_mailflow' }, + 'critical-mailflow:s' => { name => 'critical_mailflow', default => '%{mailflow_result} !~ /Success/i' }, + 'warning-copystatus:s' => { name => 'warning_copystatus' }, + 'critical-copystatus:s' => { name => 'critical_copystatus', default => '%{copystatus_indexstate} !~ /Healthy/i' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning_mapi', 'critical_mapi', 'warning_mailflow', 'critical_mailflow', 'warning_copystatus', 'critical_copystatus')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -77,30 +78,47 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - no_mailflow => $self->{option_results}->{no_mailflow}, - no_ps => $self->{option_results}->{no_ps}, - no_mapi => $self->{option_results}->{no_mapi}, - no_copystatus => $self->{option_results}->{no_copystatus}, - filter_database => $self->{option_results}->{ps_database_filter}, - filter_database_test => $self->{option_results}->{ps_database_test_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::databases::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + no_mailflow => $self->{option_results}->{no_mailflow}, + no_mapi => $self->{option_results}->{no_mapi}, + no_copystatus => $self->{option_results}->{no_copystatus}, + filter_database => $self->{option_results}->{ps_database_filter}, + filter_database_test => $self->{option_results}->{ps_database_test_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} + ); 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(); } centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout); - + $self->{output}->display(); $self->{output}->exit(); } @@ -164,6 +182,10 @@ Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Print powershell output. +=item B<--ps-display> + +Display powershell script. + =item B<--ps-database-filter> Filter database (only wilcard '*' can be used. In Powershell). @@ -204,4 +226,4 @@ Can used special variables like: %{copystatus_indexstate}, %{database}, %{server =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/imapmailbox.pm b/apps/exchange/2010/local/mode/imapmailbox.pm index a63605d48..c5107d430 100644 --- a/apps/exchange/2010/local/mode/imapmailbox.pm +++ b/apps/exchange/2010/local/mode/imapmailbox.pm @@ -31,21 +31,22 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, - "mailbox:s" => { name => 'mailbox', }, - "password:s" => { name => 'password', }, + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' }, + 'mailbox:s' => { name => 'mailbox' }, + 'password:s' => { name => 'password' }, }); return $self; @@ -53,7 +54,7 @@ sub new { sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -78,29 +79,44 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::imapmailbox::get_powershell( - remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - mailbox => $self->{option_results}->{mailbox}, - password => $self->{option_results}->{password}, - no_ps => $self->{option_results}->{no_ps}, - ); - $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::imapmailbox::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + mailbox => $self->{option_results}->{mailbox}, + password => $self->{option_results}->{password} + ); + 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} + ); 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(); } centreon::common::powershell::exchange::2010::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); - + $self->{output}->display(); $self->{output}->exit(); } @@ -148,6 +164,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/apps/exchange/2010/local/mode/listdatabases.pm b/apps/exchange/2010/local/mode/listdatabases.pm index 06f86c3b7..38fa33573 100644 --- a/apps/exchange/2010/local/mode/listdatabases.pm +++ b/apps/exchange/2010/local/mode/listdatabases.pm @@ -31,20 +31,20 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "ps-database-filter:s" => { name => 'ps_database_filter', }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-database-filter:s' => { name => 'ps_database_filter' }, + }); + return $self; } @@ -56,11 +56,13 @@ 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}); + 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}, @@ -146,6 +148,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. @@ -156,4 +162,4 @@ Filter database (only wilcard '*' can be used. In Powershell). =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/mapimailbox.pm b/apps/exchange/2010/local/mode/mapimailbox.pm index 3c1dbb83e..940cda22e 100644 --- a/apps/exchange/2010/local/mode/mapimailbox.pm +++ b/apps/exchange/2010/local/mode/mapimailbox.pm @@ -31,28 +31,29 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, - "mailbox:s" => { name => 'mailbox', }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' }, + 'mailbox:s' => { name => 'mailbox' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -73,28 +74,43 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::mapimailbox::get_powershell( - remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - mailbox => $self->{option_results}->{mailbox}, - no_ps => $self->{option_results}->{no_ps}, - ); - $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::mapimailbox::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + mailbox => $self->{option_results}->{mailbox} + ); + 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} + ); 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(); } centreon::common::powershell::exchange::2010::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); - + $self->{output}->display(); $self->{output}->exit(); } @@ -142,6 +158,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. @@ -162,4 +182,4 @@ Set the mailbox to check (Required). =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/outlookwebservices.pm b/apps/exchange/2010/local/mode/outlookwebservices.pm index 2e81b5238..2d01a33e5 100644 --- a/apps/exchange/2010/local/mode/outlookwebservices.pm +++ b/apps/exchange/2010/local/mode/outlookwebservices.pm @@ -31,21 +31,22 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{type} !~ /Success|Information/i' }, - "mailbox:s" => { name => 'mailbox', }, - "password:s" => { name => 'password', }, + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', default => '%{type} !~ /Success|Information/i' }, + 'mailbox:s' => { name => 'mailbox' }, + 'password:s' => { name => 'password' }, }); return $self; @@ -53,7 +54,7 @@ sub new { sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -74,29 +75,44 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::outlookwebservices::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}, - mailbox => $self->{option_results}->{mailbox}, - password => $self->{option_results}->{password}, - ); - $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::outlookwebservices::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + mailbox => $self->{option_results}->{mailbox}, + password => $self->{option_results}->{password} + ); + 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} + ); 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(); } centreon::common::powershell::exchange::2010::outlookwebservices::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); - + $self->{output}->display(); $self->{output}->exit(); } @@ -144,6 +160,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/apps/exchange/2010/local/mode/owamailbox.pm b/apps/exchange/2010/local/mode/owamailbox.pm index a88a01c0d..3f63b80a7 100644 --- a/apps/exchange/2010/local/mode/owamailbox.pm +++ b/apps/exchange/2010/local/mode/owamailbox.pm @@ -31,31 +31,32 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, - "url:s" => { name => 'url', }, - "mailbox:s" => { name => 'mailbox', }, - "password:s" => { name => 'password', }, - "no-trust-ssl" => { name => 'no_trust_ssl', }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' }, + 'url:s' => { name => 'url' }, + 'mailbox:s' => { name => 'mailbox' }, + 'password:s' => { name => 'password' }, + 'no-trust-ssl' => { name => 'no_trust_ssl' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -84,30 +85,46 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::owamailbox::get_powershell(remote_host => $self->{option_results}->{remote_host}, - remote_user => $self->{option_results}->{remote_user}, - remote_password => $self->{option_results}->{remote_password}, - url => $self->{option_results}->{url}, - mailbox => $self->{option_results}->{mailbox}, - password => $self->{option_results}->{password}, - no_ps => $self->{option_results}->{no_ps}, - no_trust_ssl => $self->{option_results}->{no_trust_ssl} - ); - $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::owamailbox::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + url => $self->{option_results}->{url}, + mailbox => $self->{option_results}->{mailbox}, + password => $self->{option_results}->{password}, + no_trust_ssl => $self->{option_results}->{no_trust_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::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 + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } centreon::common::powershell::exchange::2010::owamailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); - + $self->{output}->display(); $self->{output}->exit(); } @@ -155,6 +172,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. @@ -187,4 +208,4 @@ By default, SSL certificate validy is not checked. =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/queues.pm b/apps/exchange/2010/local/mode/queues.pm index fe8c64331..d1eefd639 100644 --- a/apps/exchange/2010/local/mode/queues.pm +++ b/apps/exchange/2010/local/mode/queues.pm @@ -31,27 +31,28 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{status} !~ /Ready|Active/i' }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{status} !~ /Ready|Active/i' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -68,27 +69,42 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::queues::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}, - ); - $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::queues::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password} + ); + 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} + ); 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(); } centreon::common::powershell::exchange::2010::queues::check($self, stdout => $stdout); - + $self->{output}->display(); $self->{output}->exit(); } @@ -136,6 +152,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/apps/exchange/2010/local/mode/replicationhealth.pm b/apps/exchange/2010/local/mode/replicationhealth.pm index adfcdd8cf..9a051317c 100644 --- a/apps/exchange/2010/local/mode/replicationhealth.pm +++ b/apps/exchange/2010/local/mode/replicationhealth.pm @@ -31,27 +31,28 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{result} !~ /Passed/i' }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host', }, + 'remote-user:s' => { name => 'remote_user', }, + 'remote-password:s' => { name => 'remote_password', }, + 'no-ps' => { name => 'no_ps', }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only', }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', default => '%{result} !~ /Passed/i' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -68,27 +69,42 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::replicationhealth::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}, - ); - $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::replicationhealth::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password} + ); + 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} + ); 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(); } centreon::common::powershell::exchange::2010::replicationhealth::check($self, stdout => $stdout); - + $self->{output}->display(); $self->{output}->exit(); } @@ -136,6 +152,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. @@ -152,4 +172,4 @@ Can used special variables like: %{result}, %{server}, %{isvalid}, %{check} =back -=cut \ No newline at end of file +=cut diff --git a/apps/exchange/2010/local/mode/services.pm b/apps/exchange/2010/local/mode/services.pm index 5d361f422..5bd1d3845 100644 --- a/apps/exchange/2010/local/mode/services.pm +++ b/apps/exchange/2010/local/mode/services.pm @@ -31,27 +31,28 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "remote-host:s" => { name => 'remote_host', }, - "remote-user:s" => { name => 'remote_user', }, - "remote-password:s" => { name => 'remote_password', }, - "no-ps" => { name => 'no_ps', }, - "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' }, - "ps-exec-only" => { name => 'ps_exec_only', }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', default => '%{requiredservicesrunning} =~ /True/i and %{servicesnotrunning} ne ""' }, - }); + + $options{options}->add_options(arguments => { + 'remote-host:s' => { name => 'remote_host' }, + 'remote-user:s' => { name => 'remote_user' }, + 'remote-password:s' => { name => 'remote_password' }, + 'no-ps' => { name => 'no_ps' }, + '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' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-display' => { name => 'ps_display' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical', default => '%{requiredservicesrunning} =~ /True/i and %{servicesnotrunning} ne ""' }, + }); + return $self; } sub change_macros { my ($self, %options) = @_; - + foreach (('warning', 'critical')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; @@ -68,22 +69,37 @@ sub check_options { sub run { my ($self, %options) = @_; - - my $ps = centreon::common::powershell::exchange::2010::services::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}, - ); - $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::services::get_powershell( + remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password} + ); + 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} + ); 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(); } @@ -136,6 +152,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. @@ -152,4 +172,4 @@ Can used special variables like: %{servicesrunning}, %{servicesnotrunning}, %{ro =back -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/activesyncmailbox.pm b/centreon/common/powershell/exchange/2010/activesyncmailbox.pm index a4a16f268..d63ef4a75 100644 --- a/centreon/common/powershell/exchange/2010/activesyncmailbox.pm +++ b/centreon/common/powershell/exchange/2010/activesyncmailbox.pm @@ -27,14 +27,10 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate'; - - return '' if ($no_ps == 1); - + my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); - + $ps .= ' try { $ErrorActionPreference = "Stop" @@ -56,7 +52,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { @@ -65,9 +61,11 @@ sub check { # Following output: #[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]] - $self->{output}->output_add(severity => 'OK', - short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok."); - + $self->{output}->output_add( + severity => 'OK', + short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok." + ); + my $checked = 0; $self->{output}->output_add(long_msg => $options{stdout}); while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) { @@ -120,4 +118,4 @@ __END__ Method to check Exchange 2010 activesync on a specific mailbox. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/databases.pm b/centreon/common/powershell/exchange/2010/databases.pm index dd28183a1..710151f74 100644 --- a/centreon/common/powershell/exchange/2010/databases.pm +++ b/centreon/common/powershell/exchange/2010/databases.pm @@ -27,14 +27,11 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps, no_mailflow, no_mapi + # options: no_mailflow, no_mapi my $no_mailflow = (defined($options{no_mailflow})) ? 1 : 0; - my $no_ps = (defined($options{no_ps})) ? 1 : 0; my $no_mapi = (defined($options{no_mapi})) ? 1 : 0; my $no_copystatus = (defined($options{no_copystatus})) ? 1 : 0; - - return '' if ($no_ps == 1); - + my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); $ps .= ' @@ -108,7 +105,7 @@ Foreach ($DB in $MountedDB) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check_mapi { @@ -312,4 +309,4 @@ __END__ Method to check Exchange 2010 databases. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/imapmailbox.pm b/centreon/common/powershell/exchange/2010/imapmailbox.pm index 5d536e319..c2f83f1ad 100644 --- a/centreon/common/powershell/exchange/2010/imapmailbox.pm +++ b/centreon/common/powershell/exchange/2010/imapmailbox.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -55,7 +51,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { diff --git a/centreon/common/powershell/exchange/2010/listdatabases.pm b/centreon/common/powershell/exchange/2010/listdatabases.pm index 03949f7c9..d1011d50a 100644 --- a/centreon/common/powershell/exchange/2010/listdatabases.pm +++ b/centreon/common/powershell/exchange/2010/listdatabases.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps, no_mailflow, no_mapi - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -65,7 +61,7 @@ Foreach ($DB in $MountedDB) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub list { @@ -110,4 +106,4 @@ __END__ Method to list Exchange 2010 databases. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/mapimailbox.pm b/centreon/common/powershell/exchange/2010/mapimailbox.pm index 8d2e55a5d..cb2ef9ca7 100644 --- a/centreon/common/powershell/exchange/2010/mapimailbox.pm +++ b/centreon/common/powershell/exchange/2010/mapimailbox.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -48,7 +44,7 @@ Write-Host "[name=" $mapi.Database "][server=" $mapi.Server "][result=" $mapi.Re exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { @@ -104,4 +100,4 @@ __END__ Method to check Exchange 2010 mapi connection on a specific mailbox. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/outlookwebservices.pm b/centreon/common/powershell/exchange/2010/outlookwebservices.pm index 71442b978..83543a3c3 100644 --- a/centreon/common/powershell/exchange/2010/outlookwebservices.pm +++ b/centreon/common/powershell/exchange/2010/outlookwebservices.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -64,7 +60,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { diff --git a/centreon/common/powershell/exchange/2010/owamailbox.pm b/centreon/common/powershell/exchange/2010/owamailbox.pm index 003b85056..c53a172ed 100644 --- a/centreon/common/powershell/exchange/2010/owamailbox.pm +++ b/centreon/common/powershell/exchange/2010/owamailbox.pm @@ -27,12 +27,8 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate'; - return '' if ($no_ps == 1); - my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); $ps .= ' @@ -56,7 +52,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { @@ -120,4 +116,4 @@ __END__ Method to check Exchange 2010 owa connection on a specific mailbox. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/powershell.pm b/centreon/common/powershell/exchange/2010/powershell.pm index a4627a661..aed12b896 100644 --- a/centreon/common/powershell/exchange/2010/powershell.pm +++ b/centreon/common/powershell/exchange/2010/powershell.pm @@ -28,10 +28,6 @@ use centreon::plugins::misc; #--remote-host --remote-user --remote-password sub powershell_init { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" @@ -125,4 +121,4 @@ __END__ Powershell commands -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/exchange/2010/queues.pm b/centreon/common/powershell/exchange/2010/queues.pm index ab6b09ccb..0d3e1f350 100644 --- a/centreon/common/powershell/exchange/2010/queues.pm +++ b/centreon/common/powershell/exchange/2010/queues.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -49,7 +45,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { diff --git a/centreon/common/powershell/exchange/2010/replicationhealth.pm b/centreon/common/powershell/exchange/2010/replicationhealth.pm index 7adae890b..a6adf432a 100644 --- a/centreon/common/powershell/exchange/2010/replicationhealth.pm +++ b/centreon/common/powershell/exchange/2010/replicationhealth.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -49,7 +45,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { diff --git a/centreon/common/powershell/exchange/2010/services.pm b/centreon/common/powershell/exchange/2010/services.pm index 10138b468..7e590e147 100644 --- a/centreon/common/powershell/exchange/2010/services.pm +++ b/centreon/common/powershell/exchange/2010/services.pm @@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell; sub get_powershell { my (%options) = @_; - # options: no_ps - my $no_ps = (defined($options{no_ps})) ? 1 : 0; - - return '' if ($no_ps == 1); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options); @@ -51,7 +47,7 @@ Foreach ($result in $results) { exit 0 '; - return centreon::plugins::misc::powershell_encoded($ps); + return $ps; } sub check { @@ -110,4 +106,4 @@ __END__ Method to check Exchange 2010 services running or not running. -=cut \ No newline at end of file +=cut diff --git a/centreon/common/powershell/functions.pm b/centreon/common/powershell/functions.pm index 8f7ad7459..1e53ef170 100644 --- a/centreon/common/powershell/functions.pm +++ b/centreon/common/powershell/functions.pm @@ -25,7 +25,7 @@ use warnings; sub escape_jsonstring { my (%options) = @_; - + my $ps = q{ function Escape-JSONString($str) { if ($str -eq $null) {return ""} diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index ff798e49c..c55cafc3c 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -316,14 +316,10 @@ sub trim { } sub powershell_encoded { - my ($value) = $_[0]; - require Encode; require MIME::Base64; - my $bytes = Encode::encode('utf16LE', $value); - my $script = MIME::Base64::encode_base64($bytes, "\n"); - $script =~ s/\n//g; - return $script; + my $bytes = Encode::encode('utf16LE', $_[0]); + return MIME::Base64::encode_base64($bytes, ''); } sub powershell_escape { @@ -338,8 +334,10 @@ sub powershell_escape { sub powershell_json_sanitizer { my (%options) = @_; - centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'JSON::XS', - error_msg => "Cannot load module 'JSON::XS'."); + centreon::plugins::misc::mymodule_load( + output => $options{output}, module => 'JSON::XS', + error_msg => "Cannot load module 'JSON::XS'." + ); foreach my $line (split /\n/, $options{string}) { eval { JSON::XS->new->utf8->decode($line) }; return $line if (!$@); @@ -522,8 +520,10 @@ sub set_timezone { return {} if (!defined($options{name}) || $options{name} eq ''); - centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'DateTime::TimeZone', - error_msg => "Cannot load module 'DateTime::TimeZone'."); + centreon::plugins::misc::mymodule_load( + output => $options{output}, module => 'DateTime::TimeZone', + error_msg => "Cannot load module 'DateTime::TimeZone'." + ); if (DateTime::TimeZone->is_valid_name($options{name})) { return { time_zone => DateTime::TimeZone->new(name => $options{name}) }; } @@ -545,4 +545,3 @@ sub uniq { 1; __END__ -