parent
86d716ebcf
commit
b0d32a1e82
|
@ -41,6 +41,9 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::databases;
|
||||
|
||||
my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => 'critical',
|
||||
'warning_mailflow' => 'warning', 'critical_mailflow' => 'critical');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
|
@ -49,36 +52,65 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"no-mailflow" => { name => 'no_mailflow', },
|
||||
"no-mapi" => { name => 'no_mapi', },
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"no-mailflow" => { name => 'no_mailflow', },
|
||||
"no-mapi" => { name => 'no_mapi', },
|
||||
"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-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-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', },
|
||||
"warning-mailflow:s" => { name => 'warning_mailflow', },
|
||||
"critical-mailflow:s" => { name => 'critical_mailflow', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$th =~ s/_/-/;
|
||||
$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::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
no_mapi => $self->{option_results}->{no_mapi});
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
|
||||
my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
no_mapi => $self->{option_results}->{no_mapi},
|
||||
filter_database => $self->{option_results}->{ps_database_filter},
|
||||
filter_database_test => $self->{option_results}->{ps_database_test_filter});
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
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::databases::check($self, stdout => $stdout);
|
||||
|
||||
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::databases::check($self, stdout => $stdout);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -122,6 +154,42 @@ Command path (Default: none).
|
|||
|
||||
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).
|
||||
|
||||
=item B<--ps-database-test-filter>
|
||||
|
||||
Skip mapi/mailflow test (regexp can be used. In Powershell).
|
||||
|
||||
=item B<--warning-mapi>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mapi>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--warning-mailflow>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mailflow>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,167 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::mode::mapimailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::mapimailbox;
|
||||
|
||||
my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => '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 =>
|
||||
{
|
||||
"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-mapi:s" => { name => 'warning_mapi', },
|
||||
"critical-mapi:s" => { name => 'critical_mapi', },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
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();
|
||||
}
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$th =~ s/_/-/;
|
||||
$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::mapimailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
);
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
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::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check mapi connection to a mailbox.
|
||||
|
||||
=over 8
|
||||
|
||||
=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-mapi>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mapi>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--mailbox>
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -47,7 +47,8 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'databases' => 'apps::exchange::2010::local::mode::databases',
|
||||
'databases' => 'apps::exchange::2010::local::mode::databases',
|
||||
'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
|
|
@ -40,78 +40,217 @@ use warnings;
|
|||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
my (%options) = @_;
|
||||
# options: no_ps, 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;
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
my (%options) = @_;
|
||||
# options: no_ps, 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;
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
$MountedDB = Get-MailboxDatabase -Status
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
';
|
||||
|
||||
$Status = "Yes"
|
||||
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 "]" -NoNewline
|
||||
|
||||
If ($DB.Mounted -eq $true) {
|
||||
Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline
|
||||
|
||||
';
|
||||
|
||||
if (defined($options{filter_database_test}) && $options{filter_database_test} ne '') {
|
||||
$ps .= '
|
||||
if (!($DB.Name -match "' . $options{filter_database_test} . '")) {
|
||||
Write-Host "[Skip extra test]"
|
||||
continue
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
$ps .= '
|
||||
If ($DB.Mounted -eq $true) {
|
||||
';
|
||||
|
||||
if ($no_mapi == 0) {
|
||||
$ps .= '
|
||||
# Test Mapi Connectivity
|
||||
$MapiResult = test-mapiconnectivity -Database $DB.Name
|
||||
Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
|
||||
if ($no_mapi == 0) {
|
||||
$ps .= '
|
||||
# Test Mapi Connectivity
|
||||
$MapiResult = test-mapiconnectivity -Database $DB.Name
|
||||
Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
|
||||
';
|
||||
}
|
||||
|
||||
if ($no_mailflow == 0) {
|
||||
$ps .= '
|
||||
# Test Mailflow
|
||||
$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
|
||||
Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
|
||||
}
|
||||
|
||||
if ($no_mailflow == 0) {
|
||||
$ps .= '
|
||||
# Test Mailflow
|
||||
$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
|
||||
Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
|
||||
';
|
||||
}
|
||||
}
|
||||
|
||||
$ps .= '
|
||||
}
|
||||
Write-Host ""
|
||||
$ps .= '
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check_mapi {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{no_mapi})) {
|
||||
$self->{output}->output_add(long_msg => ' Skip MAPI test connectivity');
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{line} !~ /\[mapi=(.*?)\]/) {
|
||||
$self->{output}->output_add(long_msg => ' Skip MAPI test connectivity (information not found)');
|
||||
return ;
|
||||
}
|
||||
|
||||
my $mapi_result = centreon::plugins::misc::trim($1);
|
||||
|
||||
$self->{output}->output_add(long_msg => " MAPI Test connectivity: " . $mapi_result);
|
||||
foreach my $th (('critical_mapi', 'warning_mapi')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$mapi_result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
|
||||
$options{server}, $options{database}, $mapi_result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$mapi_result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
|
||||
$options{server}, $options{database}, $mapi_result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_mailflow {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{no_mailflow})) {
|
||||
$self->{output}->output_add(long_msg => ' Skip Mailflow test');
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{line} !~ /\[mailflow=(.*?)\]\[latency=(.*?)\]/) {
|
||||
$self->{output}->output_add(long_msg => ' Skip Mailflow test (information not found)');
|
||||
return ;
|
||||
}
|
||||
|
||||
my ($mailflow_result, $latency) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2));
|
||||
|
||||
$self->{output}->output_add(long_msg => " Mailflow Test: " . $mailflow_result);
|
||||
foreach my $th (('critical_mailflow', 'warning_mailflow')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$mailflow_result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
|
||||
$options{server}, $options{database}, $mailflow_result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$mailflow_result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
|
||||
$options{server}, $options{database}, $mailflow_result));
|
||||
}
|
||||
}
|
||||
|
||||
$latency =~ /\d+:\d+:(.*)/;
|
||||
if (defined($1)) {
|
||||
$self->{output}->perfdata_add(label => 'latency_' . $options{database}, unit => 's',
|
||||
value => sprintf("%.3f", $1),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
|
||||
#...
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => $options{stdout});
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
|
||||
#...
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'Databases are mounted');
|
||||
if (!defined($self->{option_results}->{no_mapi})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'MAPI Connectivities are ok');
|
||||
}
|
||||
if (!defined($self->{option_results}->{no_mailflow})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'Mailflow test are ok');
|
||||
}
|
||||
|
||||
my $checked = 0;
|
||||
foreach my $line (split /\n/, $options{stdout}) {
|
||||
next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]/);
|
||||
$checked++;
|
||||
my ($database, $server, $mounted) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3));
|
||||
|
||||
# Check mounted
|
||||
$self->{output}->output_add(long_msg => sprintf("Test database '%s' server '%s':", $database, $server));
|
||||
if ($mounted =~ /False/i) {
|
||||
$self->{output}->output_add(long_msg => sprintf(" not mounted\n Skip mapi/mailflow test"));
|
||||
$self->{output}->output_add(short_msg => 'CRITICAL',
|
||||
long_msg => sprintf("Database '%s' server '%s' is not mounted", $database, $server));
|
||||
next;
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf(" mounted"));
|
||||
|
||||
check_mapi($self, database => $database, server => $server, line => $line);
|
||||
check_mailflow($self, database => $database, server => $server, line => $line);
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# permission to link this program with independent modules to produce an executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS also meet, for each linked independent module, the terms and conditions
|
||||
# of the license of that module. An independent module is a module which is not
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
# exception to your version of the program, but you are not obliged to do so. If you
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
# For more information : contact@centreon.com
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package centreon::common::powershell::exchange::2010::mapimailbox;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
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"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
$mapi = test-mapiconnectivity -Identity "' . $options{mailbox} . '"
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "[name=" $mapi.Database "][server=" $mapi.Server "][result=" $mapi.Result "][error=" $mapi.Error "]"
|
||||
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][result= Success ][error=...]
|
||||
|
||||
if ($options{stdout} !~ /^\[name=(.*?)\]\[server=(.*?)\]\[result=(.*?)\]\[error=(.*)\]$/) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
return ;
|
||||
}
|
||||
my ($database, $server, $result, $error) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "MAPI connection to '" . $options{mailbox} . "' is '" . $result . "'.");
|
||||
$self->{output}->output_add(long_msg => sprintf("Database: %s, Server: %s\nError: %s",
|
||||
$database, $server, $error));
|
||||
foreach my $th (('critical_mapi', 'warning_mapi')) {
|
||||
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("MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Method to check Exchange 2010 mapi connection on a specific mailbox.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue