wip: add an option to display powershell

This commit is contained in:
garnier-quentin 2020-01-27 11:07:46 +01:00
parent f023213020
commit 7315fe1dda
23 changed files with 568 additions and 420 deletions

View File

@ -31,30 +31,31 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning' },
"critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' },
"mailbox:s" => { name => 'mailbox', }, 'mailbox:s' => { name => 'mailbox' },
"password:s" => { name => 'password', }, 'password:s' => { name => 'password' },
"no-trust-ssl" => { name => 'no_trust_ssl', }, 'no-trust-ssl' => { name => 'no_trust_ssl' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -79,29 +80,45 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::activesyncmailbox::get_powershell(remote_host => $self->{option_results}->{remote_host}, if (!defined($self->{option_results}->{no_ps})) {
remote_user => $self->{option_results}->{remote_user}, my $ps = centreon::common::powershell::exchange::2010::activesyncmailbox::get_powershell(
remote_password => $self->{option_results}->{remote_password}, remote_host => $self->{option_results}->{remote_host},
mailbox => $self->{option_results}->{mailbox}, remote_user => $self->{option_results}->{remote_user},
password => $self->{option_results}->{password}, remote_password => $self->{option_results}->{remote_password},
no_ps => $self->{option_results}->{no_ps}, mailbox => $self->{option_results}->{mailbox},
no_trust_ssl => $self->{option_results}->{no_trust_ssl} password => $self->{option_results}->{password},
); 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}, if (defined($self->{option_results}->{ps_display})) {
timeout => $self->{option_results}->{timeout}, $self->{output}->output_add(
command => $self->{option_results}->{command}, severity => 'OK',
command_path => $self->{option_results}->{command_path}, short_msg => $ps
command_options => $self->{option_results}->{command_options}); );
$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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); centreon::common::powershell::exchange::2010::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -149,6 +166,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -177,4 +198,4 @@ By default, SSL certificate validy is not checked.
=back =back
=cut =cut

View File

@ -31,36 +31,37 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'no-mailflow' => { name => 'no_mailflow' },
"no-mailflow" => { name => 'no_mailflow', }, 'no-mapi' => { name => 'no_mapi' },
"no-mapi" => { name => 'no_mapi', }, 'no-copystatus' => { name => 'no_copystatus' },
"no-copystatus" => { name => 'no_copystatus', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"ps-database-filter:s" => { name => 'ps_database_filter', }, 'ps-database-filter:s' => { name => 'ps_database_filter' },
"ps-database-test-filter:s" => { name => 'ps_database_test_filter', }, 'ps-database-test-filter:s' => { name => 'ps_database_test_filter' },
"warning-mapi:s" => { name => 'warning_mapi', }, 'warning-mapi:s' => { name => 'warning_mapi' },
"critical-mapi:s" => { name => 'critical_mapi', default => '%{mapi_result} !~ /Success/i' }, 'critical-mapi:s' => { name => 'critical_mapi', default => '%{mapi_result} !~ /Success/i' },
"warning-mailflow:s" => { name => 'warning_mailflow', }, 'warning-mailflow:s' => { name => 'warning_mailflow' },
"critical-mailflow:s" => { name => 'critical_mailflow', default => '%{mailflow_result} !~ /Success/i' }, 'critical-mailflow:s' => { name => 'critical_mailflow', default => '%{mailflow_result} !~ /Success/i' },
"warning-copystatus:s" => { name => 'warning_copystatus', }, 'warning-copystatus:s' => { name => 'warning_copystatus' },
"critical-copystatus:s" => { name => 'critical_copystatus', default => '%{copystatus_indexstate} !~ /Healthy/i' }, 'critical-copystatus:s' => { name => 'critical_copystatus', default => '%{copystatus_indexstate} !~ /Healthy/i' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning_mapi', 'critical_mapi', 'warning_mailflow', 'critical_mailflow', 'warning_copystatus', 'critical_copystatus')) { foreach (('warning_mapi', 'critical_mapi', 'warning_mailflow', 'critical_mailflow', 'warning_copystatus', 'critical_copystatus')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -77,30 +78,47 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(remote_host => $self->{option_results}->{remote_host}, if (!defined($self->{option_results}->{no_ps})) {
remote_user => $self->{option_results}->{remote_user}, my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(
remote_password => $self->{option_results}->{remote_password}, remote_host => $self->{option_results}->{remote_host},
no_mailflow => $self->{option_results}->{no_mailflow}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password},
no_mapi => $self->{option_results}->{no_mapi}, no_mailflow => $self->{option_results}->{no_mailflow},
no_copystatus => $self->{option_results}->{no_copystatus}, no_mapi => $self->{option_results}->{no_mapi},
filter_database => $self->{option_results}->{ps_database_filter}, no_copystatus => $self->{option_results}->{no_copystatus},
filter_database_test => $self->{option_results}->{ps_database_test_filter}); filter_database => $self->{option_results}->{ps_database_filter},
$self->{option_results}->{command_options} .= " " . $ps; filter_database_test => $self->{option_results}->{ps_database_test_filter}
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, );
timeout => $self->{option_results}->{timeout}, if (defined($self->{option_results}->{ps_display})) {
command => $self->{option_results}->{command}, $self->{output}->output_add(
command_path => $self->{option_results}->{command_path}, severity => 'OK',
command_options => $self->{option_results}->{command_options}); 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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout); centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -164,6 +182,10 @@ Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
Print powershell output. Print powershell output.
=item B<--ps-display>
Display powershell script.
=item B<--ps-database-filter> =item B<--ps-database-filter>
Filter database (only wilcard '*' can be used. In Powershell). Filter database (only wilcard '*' can be used. In Powershell).
@ -204,4 +226,4 @@ Can used special variables like: %{copystatus_indexstate}, %{database}, %{server
=back =back
=cut =cut

View File

@ -31,21 +31,22 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"remote-host:s" => { name => 'remote_host', }, 'remote-host:s' => { name => 'remote_host' },
"remote-user:s" => { name => 'remote_user', }, 'remote-user:s' => { name => 'remote_user' },
"remote-password:s" => { name => 'remote_password', }, 'remote-password:s' => { name => 'remote_password' },
"no-ps" => { name => 'no_ps', }, 'no-ps' => { name => 'no_ps' },
"timeout:s" => { name => 'timeout', default => 50 }, 'timeout:s' => { name => 'timeout', default => 50 },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command-path:s" => { name => 'command_path' }, 'command-path:s' => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, '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' },
"warning:s" => { name => 'warning', }, 'ps-display' => { name => 'ps_display' },
"critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, 'warning:s' => { name => 'warning' },
"mailbox:s" => { name => 'mailbox', }, 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' },
"password:s" => { name => 'password', }, 'mailbox:s' => { name => 'mailbox' },
'password:s' => { name => 'password' },
}); });
return $self; return $self;
@ -53,7 +54,7 @@ sub new {
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -78,29 +79,44 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::imapmailbox::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::imapmailbox::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
mailbox => $self->{option_results}->{mailbox}, remote_password => $self->{option_results}->{remote_password},
password => $self->{option_results}->{password}, mailbox => $self->{option_results}->{mailbox},
no_ps => $self->{option_results}->{no_ps}, password => $self->{option_results}->{password}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); centreon::common::powershell::exchange::2010::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -148,6 +164,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.

View File

@ -31,20 +31,20 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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-database-filter:s' => { name => 'ps_database_filter' },
"ps-database-filter:s" => { name => 'ps_database_filter', }, });
});
return $self; return $self;
} }
@ -56,11 +56,13 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell(remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password},
filter_database => $self->{option_results}->{ps_database_filter}); no_ps => $self->{option_results}->{no_ps},
filter_database => $self->{option_results}->{ps_database_filter}
);
$self->{option_results}->{command_options} .= " " . $ps; $self->{option_results}->{command_options} .= " " . $ps;
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
timeout => $self->{option_results}->{timeout}, timeout => $self->{option_results}->{timeout},
@ -146,6 +148,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -156,4 +162,4 @@ Filter database (only wilcard '*' can be used. In Powershell).
=back =back
=cut =cut

View File

@ -31,28 +31,29 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning' },
"critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' },
"mailbox:s" => { name => 'mailbox', }, 'mailbox:s' => { name => 'mailbox' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -73,28 +74,43 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::mapimailbox::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::mapimailbox::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
mailbox => $self->{option_results}->{mailbox}, remote_password => $self->{option_results}->{remote_password},
no_ps => $self->{option_results}->{no_ps}, mailbox => $self->{option_results}->{mailbox}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); centreon::common::powershell::exchange::2010::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -142,6 +158,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -162,4 +182,4 @@ Set the mailbox to check (Required).
=back =back
=cut =cut

View File

@ -31,21 +31,22 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"remote-host:s" => { name => 'remote_host', }, 'remote-host:s' => { name => 'remote_host' },
"remote-user:s" => { name => 'remote_user', }, 'remote-user:s' => { name => 'remote_user' },
"remote-password:s" => { name => 'remote_password', }, 'remote-password:s' => { name => 'remote_password' },
"no-ps" => { name => 'no_ps', }, 'no-ps' => { name => 'no_ps' },
"timeout:s" => { name => 'timeout', default => 50 }, 'timeout:s' => { name => 'timeout', default => 50 },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command-path:s" => { name => 'command_path' }, 'command-path:s' => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, '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' },
"warning:s" => { name => 'warning', }, 'ps-display' => { name => 'ps_display' },
"critical:s" => { name => 'critical', default => '%{type} !~ /Success|Information/i' }, 'warning:s' => { name => 'warning', },
"mailbox:s" => { name => 'mailbox', }, 'critical:s' => { name => 'critical', default => '%{type} !~ /Success|Information/i' },
"password:s" => { name => 'password', }, 'mailbox:s' => { name => 'mailbox' },
'password:s' => { name => 'password' },
}); });
return $self; return $self;
@ -53,7 +54,7 @@ sub new {
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -74,29 +75,44 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::outlookwebservices::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::outlookwebservices::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password},
mailbox => $self->{option_results}->{mailbox}, mailbox => $self->{option_results}->{mailbox},
password => $self->{option_results}->{password}, password => $self->{option_results}->{password}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::outlookwebservices::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); centreon::common::powershell::exchange::2010::outlookwebservices::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -144,6 +160,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.

View File

@ -31,31 +31,32 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning' },
"critical:s" => { name => 'critical', default => '%{result} !~ /Success/i' }, 'critical:s' => { name => 'critical', default => '%{result} !~ /Success/i' },
"url:s" => { name => 'url', }, 'url:s' => { name => 'url' },
"mailbox:s" => { name => 'mailbox', }, 'mailbox:s' => { name => 'mailbox' },
"password:s" => { name => 'password', }, 'password:s' => { name => 'password' },
"no-trust-ssl" => { name => 'no_trust_ssl', }, 'no-trust-ssl' => { name => 'no_trust_ssl' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -84,30 +85,46 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::owamailbox::get_powershell(remote_host => $self->{option_results}->{remote_host}, if (!defined($self->{option_results}->{no_ps})) {
remote_user => $self->{option_results}->{remote_user}, my $ps = centreon::common::powershell::exchange::2010::owamailbox::get_powershell(
remote_password => $self->{option_results}->{remote_password}, remote_host => $self->{option_results}->{remote_host},
url => $self->{option_results}->{url}, remote_user => $self->{option_results}->{remote_user},
mailbox => $self->{option_results}->{mailbox}, remote_password => $self->{option_results}->{remote_password},
password => $self->{option_results}->{password}, url => $self->{option_results}->{url},
no_ps => $self->{option_results}->{no_ps}, mailbox => $self->{option_results}->{mailbox},
no_trust_ssl => $self->{option_results}->{no_trust_ssl} password => $self->{option_results}->{password},
); 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}, if (defined($self->{option_results}->{ps_display})) {
timeout => $self->{option_results}->{timeout}, $self->{output}->output_add(
command => $self->{option_results}->{command}, severity => 'OK',
command_path => $self->{option_results}->{command_path}, short_msg => $ps
command_options => $self->{option_results}->{command_options}); );
$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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::owamailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox}); centreon::common::powershell::exchange::2010::owamailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -155,6 +172,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -187,4 +208,4 @@ By default, SSL certificate validy is not checked.
=back =back
=cut =cut

View File

@ -31,27 +31,28 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning' },
"critical:s" => { name => 'critical', default => '%{status} !~ /Ready|Active/i' }, 'critical:s' => { name => 'critical', default => '%{status} !~ /Ready|Active/i' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -68,27 +69,42 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::queues::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::queues::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::queues::check($self, stdout => $stdout); centreon::common::powershell::exchange::2010::queues::check($self, stdout => $stdout);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -136,6 +152,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.

View File

@ -31,27 +31,28 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host', },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user', },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password', },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps', },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning', },
"critical:s" => { name => 'critical', default => '%{result} !~ /Passed/i' }, 'critical:s' => { name => 'critical', default => '%{result} !~ /Passed/i' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -68,27 +69,42 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::replicationhealth::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::replicationhealth::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
centreon::common::powershell::exchange::2010::replicationhealth::check($self, stdout => $stdout); centreon::common::powershell::exchange::2010::replicationhealth::check($self, stdout => $stdout);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -136,6 +152,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -152,4 +172,4 @@ Can used special variables like: %{result}, %{server}, %{isvalid}, %{check}
=back =back
=cut =cut

View File

@ -31,27 +31,28 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'remote-host:s' => { name => 'remote_host' },
"remote-host:s" => { name => 'remote_host', }, 'remote-user:s' => { name => 'remote_user' },
"remote-user:s" => { name => 'remote_user', }, 'remote-password:s' => { name => 'remote_password' },
"remote-password:s" => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"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' },
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning' },
"critical:s" => { name => 'critical', default => '%{requiredservicesrunning} =~ /True/i and %{servicesnotrunning} ne ""' }, 'critical:s' => { name => 'critical', default => '%{requiredservicesrunning} =~ /True/i and %{servicesnotrunning} ne ""' },
}); });
return $self; return $self;
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning', 'critical')) { foreach (('warning', 'critical')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{data}->{$1}/g;
@ -68,22 +69,37 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $ps = centreon::common::powershell::exchange::2010::services::get_powershell( if (!defined($self->{option_results}->{no_ps})) {
remote_host => $self->{option_results}->{remote_host}, my $ps = centreon::common::powershell::exchange::2010::services::get_powershell(
remote_user => $self->{option_results}->{remote_user}, remote_host => $self->{option_results}->{remote_host},
remote_password => $self->{option_results}->{remote_password}, remote_user => $self->{option_results}->{remote_user},
no_ps => $self->{option_results}->{no_ps}, remote_password => $self->{option_results}->{remote_password}
); );
$self->{option_results}->{command_options} .= " " . $ps; if (defined($self->{option_results}->{ps_display})) {
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, $self->{output}->output_add(
timeout => $self->{option_results}->{timeout}, severity => 'OK',
command => $self->{option_results}->{command}, short_msg => $ps
command_path => $self->{option_results}->{command_path}, );
command_options => $self->{option_results}->{command_options}); $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})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => $stdout); severity => 'OK',
short_msg => $stdout
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit(); $self->{output}->exit();
} }
@ -136,6 +152,10 @@ Command path (Default: none).
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-display>
Display powershell script.
=item B<--ps-exec-only> =item B<--ps-exec-only>
Print powershell output. Print powershell output.
@ -152,4 +172,4 @@ Can used special variables like: %{servicesrunning}, %{servicesnotrunning}, %{ro
=back =back
=cut =cut

View File

@ -27,14 +27,10 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; my (%options) = @_;
# options: no_ps
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate'; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
$ps .= ' $ps .= '
try { try {
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@ -56,7 +52,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {
@ -65,9 +61,11 @@ sub check {
# Following output: # Following output:
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]] #[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok."); severity => 'OK',
short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok."
);
my $checked = 0; my $checked = 0;
$self->{output}->output_add(long_msg => $options{stdout}); $self->{output}->output_add(long_msg => $options{stdout});
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) { while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
@ -120,4 +118,4 @@ __END__
Method to check Exchange 2010 activesync on a specific mailbox. Method to check Exchange 2010 activesync on a specific mailbox.
=cut =cut

View File

@ -27,14 +27,11 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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_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_mapi = (defined($options{no_mapi})) ? 1 : 0;
my $no_copystatus = (defined($options{no_copystatus})) ? 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
$ps .= ' $ps .= '
@ -108,7 +105,7 @@ Foreach ($DB in $MountedDB) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check_mapi { sub check_mapi {
@ -312,4 +309,4 @@ __END__
Method to check Exchange 2010 databases. Method to check Exchange 2010 databases.
=cut =cut

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -55,7 +51,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -65,7 +61,7 @@ Foreach ($DB in $MountedDB) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub list { sub list {
@ -110,4 +106,4 @@ __END__
Method to list Exchange 2010 databases. Method to list Exchange 2010 databases.
=cut =cut

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); 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 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {
@ -104,4 +100,4 @@ __END__
Method to check Exchange 2010 mapi connection on a specific mailbox. Method to check Exchange 2010 mapi connection on a specific mailbox.
=cut =cut

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -64,7 +60,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {

View File

@ -27,12 +27,8 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; my (%options) = @_;
# options: no_ps
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate'; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
$ps .= ' $ps .= '
@ -56,7 +52,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {
@ -120,4 +116,4 @@ __END__
Method to check Exchange 2010 owa connection on a specific mailbox. Method to check Exchange 2010 owa connection on a specific mailbox.
=cut =cut

View File

@ -28,10 +28,6 @@ use centreon::plugins::misc;
#--remote-host --remote-user --remote-password #--remote-host --remote-user --remote-password
sub powershell_init { sub powershell_init {
my (%options) = @_; my (%options) = @_;
# options: no_ps
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
return '' if ($no_ps == 1);
my $ps = ' my $ps = '
$culture = new-object "System.Globalization.CultureInfo" "en-us" $culture = new-object "System.Globalization.CultureInfo" "en-us"
@ -125,4 +121,4 @@ __END__
Powershell commands Powershell commands
=cut =cut

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -49,7 +45,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -49,7 +45,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {

View File

@ -27,10 +27,6 @@ use centreon::common::powershell::exchange::2010::powershell;
sub get_powershell { sub get_powershell {
my (%options) = @_; 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); my $ps = centreon::common::powershell::exchange::2010::powershell::powershell_init(%options);
@ -51,7 +47,7 @@ Foreach ($result in $results) {
exit 0 exit 0
'; ';
return centreon::plugins::misc::powershell_encoded($ps); return $ps;
} }
sub check { sub check {
@ -110,4 +106,4 @@ __END__
Method to check Exchange 2010 services running or not running. Method to check Exchange 2010 services running or not running.
=cut =cut

View File

@ -25,7 +25,7 @@ use warnings;
sub escape_jsonstring { sub escape_jsonstring {
my (%options) = @_; my (%options) = @_;
my $ps = q{ my $ps = q{
function Escape-JSONString($str) { function Escape-JSONString($str) {
if ($str -eq $null) {return ""} if ($str -eq $null) {return ""}

View File

@ -316,14 +316,10 @@ sub trim {
} }
sub powershell_encoded { sub powershell_encoded {
my ($value) = $_[0];
require Encode; require Encode;
require MIME::Base64; require MIME::Base64;
my $bytes = Encode::encode('utf16LE', $value); my $bytes = Encode::encode('utf16LE', $_[0]);
my $script = MIME::Base64::encode_base64($bytes, "\n"); return MIME::Base64::encode_base64($bytes, '');
$script =~ s/\n//g;
return $script;
} }
sub powershell_escape { sub powershell_escape {
@ -338,8 +334,10 @@ sub powershell_escape {
sub powershell_json_sanitizer { sub powershell_json_sanitizer {
my (%options) = @_; my (%options) = @_;
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'JSON::XS', centreon::plugins::misc::mymodule_load(
error_msg => "Cannot load module 'JSON::XS'."); output => $options{output}, module => 'JSON::XS',
error_msg => "Cannot load module 'JSON::XS'."
);
foreach my $line (split /\n/, $options{string}) { foreach my $line (split /\n/, $options{string}) {
eval { JSON::XS->new->utf8->decode($line) }; eval { JSON::XS->new->utf8->decode($line) };
return $line if (!$@); return $line if (!$@);
@ -522,8 +520,10 @@ sub set_timezone {
return {} if (!defined($options{name}) || $options{name} eq ''); return {} if (!defined($options{name}) || $options{name} eq '');
centreon::plugins::misc::mymodule_load(output => $options{output}, module => 'DateTime::TimeZone', centreon::plugins::misc::mymodule_load(
error_msg => "Cannot load module 'DateTime::TimeZone'."); output => $options{output}, module => 'DateTime::TimeZone',
error_msg => "Cannot load module 'DateTime::TimeZone'."
);
if (DateTime::TimeZone->is_valid_name($options{name})) { if (DateTime::TimeZone->is_valid_name($options{name})) {
return { time_zone => DateTime::TimeZone->new(name => $options{name}) }; return { time_zone => DateTime::TimeZone->new(name => $options{name}) };
} }
@ -545,4 +545,3 @@ sub uniq {
1; 1;
__END__ __END__