enhance mode outllok-webservices

This commit is contained in:
garnier-quentin 2019-03-05 16:45:09 +01:00
parent 9bf8cf5fa5
commit ac6e872d73
4 changed files with 58 additions and 37 deletions

View File

@ -33,22 +33,22 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$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', },
});
$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', },
});
return $self;
}
@ -85,7 +85,7 @@ sub run {
remote_user => $self->{option_results}->{remote_user},
remote_password => $self->{option_results}->{remote_password},
mailbox => $self->{option_results}->{mailbox},
password => $self->{option_results}->{password},
password => $self->{option_results}->{password},
no_ps => $self->{option_results}->{no_ps},
);
$self->{option_results}->{command_options} .= " " . $ps;
@ -173,4 +173,4 @@ Set the password for the mailbox (Required).
=back
=cut
=cut

View File

@ -33,21 +33,22 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$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', },
});
$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', },
});
return $self;
}
@ -81,6 +82,7 @@ sub run {
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},
@ -161,6 +163,10 @@ Can used special variables like: %{type}, %{id}, %{message}
Set the mailbox to check (Required).
=item B<--password>
Set the password for the mailbox.
=back
=cut
=cut

View File

@ -120,4 +120,4 @@ __END__
Method to check Exchange 2010 imap on a specific mailbox.
=cut
=cut

View File

@ -36,8 +36,23 @@ sub get_powershell {
$ps .= '
try {
$ErrorActionPreference = "Stop"
$ErrorActionPreference = "Stop"
';
if (defined($options{password}) && $options{password} ne '') {
$ps .= '
$username = "' . $options{mailbox} . '"
$password = "' . $options{password} . '"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$results = Test-OutlookWebServices -WarningAction:SilentlyContinue -MailboxCredential $cred
';
} else {
$ps .= '
$results = Test-OutlookWebServices -WarningAction:SilentlyContinue -Identity "' . $options{mailbox} . '"
';
}
$ps .= '
} catch {
Write-Host $Error[0].Exception
exit 1
@ -107,4 +122,4 @@ __END__
Method to check Exchange 2010 outlook autodiscovery webservices.
=cut
=cut