diff --git a/apps/exchange/2010/local/mode/listdatabases.pm b/apps/exchange/2010/local/mode/listdatabases.pm new file mode 100644 index 000000000..068e21094 --- /dev/null +++ b/apps/exchange/2010/local/mode/listdatabases.pm @@ -0,0 +1,160 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::exchange::2010::local::mode::listdatabases; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::powershell::exchange::2010::listdatabases; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + 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', }, + "ps-database-filter:s" => { name => 'ps_database_filter', }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%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}); + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + if (defined($self->{option_results}->{ps_exec_only})) { + $self->{output}->output_add(severity => 'OK', + short_msg => $stdout); + } else { + $self->{output}->output_add(severity => 'OK', + short_msg => 'List databases:'); + centreon::common::powershell::exchange::2010::listdatabases::list($self, stdout => $stdout); + } + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'server', 'mounted']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::exchange::2010::listdatabases::get_powershell(remote_host => $self->{option_results}->{remote_host}, + remote_user => $self->{option_results}->{remote_user}, + remote_password => $self->{option_results}->{remote_password}, + no_ps => $self->{option_results}->{no_ps}, + filter_database => $self->{option_results}->{ps_database_filter}); + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + centreon::common::powershell::exchange::2010::listdatabases::disco_show($self, stdout => $stdout); +} + +1; + +__END__ + +=head1 MODE + +List Exchange databases. + +=over 8 + +=item B<--remote-host> + +Open a session to the remote-host (fully qualified host name). --remote-user and --remote-password are optional + +=item B<--remote-user> + +Open a session to the remote-host with authentication. This also needs --remote-host and --remote-password. + +=item B<--remote-password> + +Open a session to the remote-host with authentication. This also needs --remote-user and --remote-host. + +=item B<--timeout> + +Set timeout time for command execution (Default: 50 sec) + +=item B<--no-ps> + +Don't encode powershell. To be used with --command and 'type' command. + +=item B<--command> + +Command to get information (Default: 'powershell.exe'). +Can be changed if you have output in a file. To be used with --no-ps option!!! + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). + +=item B<--ps-exec-only> + +Print powershell output. + +=item B<--ps-database-filter> + +Filter database (only wilcard '*' can be used. In Powershell). + +=back + +=cut \ No newline at end of file diff --git a/apps/exchange/2010/local/mode/owamailbox.pm b/apps/exchange/2010/local/mode/owamailbox.pm new file mode 100644 index 000000000..d78c37b62 --- /dev/null +++ b/apps/exchange/2010/local/mode/owamailbox.pm @@ -0,0 +1,196 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::exchange::2010::local::mode::owamailbox; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::powershell::exchange::2010::owamailbox; + +my %threshold = ('warning' => 'warning', 'critical' => 'critical'); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + 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', }, + "url:s" => { name => 'url', }, + "mailbox:s" => { name => 'mailbox', }, + "password:s" => { name => 'password', }, + "no-trust-ssl" => { name => 'no_trust_ssl', }, + }); + $self->{thresholds} = {}; + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{url}) || $self->{option_results}->{url} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify '--url' option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option."); + $self->{output}->option_exit(); + } + foreach my $th (keys %threshold) { + next if (!defined($self->{option_results}->{$th})); + if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th}); + $self->{output}->option_exit(); + } + + my $operator = defined($1) && $1 ne '' ? $1 : '!='; + my $state = defined($2) && $2 ne '' ? $2 : 'Success'; + $self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} }; + } +} + +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}->{ps_exec_only})) { + $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(); +} + +1; + +__END__ + +=head1 MODE + +Check OWA connection to a mailbox. + +=over 8 + +=item B<--remote-host> + +Open a session to the remote-host (fully qualified host name). --remote-user and --remote-password are optional + +=item B<--remote-user> + +Open a session to the remote-host with authentication. This also needs --remote-host and --remote-password. + +=item B<--remote-password> + +Open a session to the remote-host with authentication. This also needs --remote-user and --remote-host. + +=item B<--timeout> + +Set timeout time for command execution (Default: 50 sec) + +=item B<--no-ps> + +Don't encode powershell. To be used with --command and 'type' command. + +=item B<--command> + +Command to get information (Default: 'powershell.exe'). +Can be changed if you have output in a file. To be used with --no-ps option!!! + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). + +=item B<--ps-exec-only> + +Print powershell output. + +=item B<--warning> + +Warning threshold +(If set without value, it's: "!=Success". Need to change if your not US language. +Regexp can be used) + +=item B<--critical> + +Critical threshold +(If set without value, it's: "!=Success". Need to change if your not US language. +Regexp can be used) + +=item B<--url> + +Set the OWA Url (Required). + +=item B<--mailbox> + +Set the mailbox to check (Required). + +=item B<--password> + +Set the password for the mailbox (Required). + +=item B<--no-trust-ssl> + +By default, SSL certificate validy is not checked. + +=back + +=cut \ No newline at end of file diff --git a/apps/exchange/2010/local/plugin.pm b/apps/exchange/2010/local/plugin.pm index f038891ee..5d1df0997 100644 --- a/apps/exchange/2010/local/plugin.pm +++ b/apps/exchange/2010/local/plugin.pm @@ -34,8 +34,10 @@ sub new { %{$self->{modes}} = ( 'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox', 'databases' => 'apps::exchange::2010::local::mode::databases', + 'list-databases' => 'apps::exchange::2010::local::mode::listdatabases', 'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox', - 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', + 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', + 'owa-mailbox' => 'apps::exchange::2010::local::mode::owamailbox', ); return $self; diff --git a/centreon/common/powershell/exchange/2010/listdatabases.pm b/centreon/common/powershell/exchange/2010/listdatabases.pm new file mode 100644 index 000000000..448acf0aa --- /dev/null +++ b/centreon/common/powershell/exchange/2010/listdatabases.pm @@ -0,0 +1,113 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::powershell::exchange::2010::listdatabases; + +use strict; +use warnings; +use centreon::plugins::misc; +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); + + $ps .= ' +# Check to make sure all databases are mounted +try { + $ErrorActionPreference = "Stop" +'; + + if (defined($options{filter_database})) { + $ps .= ' + $MountedDB = Get-MailboxDatabase -Identity "' . $options{filter_database} . '" -Status +'; + } else { + $ps .= ' + $MountedDB = Get-MailboxDatabase -Status +'; + } + + $ps .= ' +} catch { + Write-Host $Error[0].Exception + exit 1 +} +Foreach ($DB in $MountedDB) { + Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "][size=" $DB.DatabaseSize "][asize=" $DB.AvailableNewMailboxSpace "]" -NoNewline + +'; + $ps .= ' +} + +exit 0 +'; + + return centreon::plugins::misc::powershell_encoded($ps); +} + +sub list { + my ($self, %options) = @_; + + # Following output: + #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ] + #... + + foreach my $line (split /\n/, $options{stdout}) { + next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/); + my ($database, $server, $mounted, $size, $asize) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + + $self->{output}->output_add(long_msg => "'" . $database . "' [server = $server, mounted = " . $mounted . ']'); + } +} + +sub disco_show { + my ($self, %options) = @_; + + # Following output: + #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ] + #... + + foreach my $line (split /\n/, $options{stdout}) { + next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/); + my ($database, $server, $mounted, $size, $asize) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), + centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + + $self->{output}->add_disco_entry(name => $database, + server => $server, + mounted => $mounted); + } +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to list Exchange 2010 databases. + +=cut \ No newline at end of file diff --git a/centreon/common/powershell/exchange/2010/owamailbox.pm b/centreon/common/powershell/exchange/2010/owamailbox.pm new file mode 100644 index 000000000..06957e67f --- /dev/null +++ b/centreon/common/powershell/exchange/2010/owamailbox.pm @@ -0,0 +1,115 @@ +# +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::powershell::exchange::2010::owamailbox; + +use strict; +use warnings; +use centreon::plugins::misc; +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" + $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-OwaConnectivity -WarningAction:SilentlyContinue -Url:' . $options{url} . ' -MailboxCredential:$cred ' . $no_trust_ssl . ' +} catch { + Write-Host $Error[0].Exception + exit 1 +} + +Foreach ($result in $results) { + Write-Host "[url=" $result.Url "][scenario=" $result.Scenario "][result=" $result.Result "][latency=" $result.Latency.TotalMilliseconds "][[error=" $Result.Error "]]" +} +exit 0 +'; + + return centreon::plugins::misc::powershell_encoded($ps); +} + +sub check { + my ($self, %options) = @_; + # options: stdout + + # Following output: + #[url= http://xxxx/ ][scenario= Options ][result= Ignored ][latency= ][[error=...]] + $self->{output}->output_add(severity => 'OK', + short_msg => "OWA to '" . $options{mailbox} . "' is ok."); + + my $checked = 0; + $self->{output}->output_add(long_msg => $options{stdout}); + while ($options{stdout} =~ /\[url=(.*?)\]\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) { + my ($url, $scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), $self->{output}->to_utf8($2), centreon::plugins::misc::trim($3), + centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5)); + + $checked++; + foreach my $th (('critical', 'warning')) { + next if (!defined($self->{thresholds}->{$th})); + + if ($self->{thresholds}->{$th}->{operator} eq '=' && + $result =~ /$self->{thresholds}->{$th}->{state}/) { + $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out}, + short_msg => sprintf("OWA scenario '%s' to '%s' is '%s' [url: %s]", + $scenario, $options{mailbox}, $result, $url)); + } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && + $result !~ /$self->{thresholds}->{$th}->{state}/) { + $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out}, + short_msg => sprintf("OWA scenario '%s' to '%s' is '%s' [url: %s]", + $scenario, $options{mailbox}, $result, $url)); + } + } + + if ($latency =~ /^(\d+)/) { + $self->{output}->perfdata_add(label => $url . '_' . $scenario, unit => 's', + value => sprintf("%.3f", $1 / 1000), + min => 0); + } + } + + if ($checked == 0) { + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => 'Cannot find informations'); + } +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to check Exchange 2010 activesync on a specific mailbox. + +=cut \ No newline at end of file