parent
bc5e72fc91
commit
08db75fa27
|
@ -0,0 +1,182 @@
|
|||
################################################################################
|
||||
# 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::activesyncmailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::activesyncmailbox;
|
||||
|
||||
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 =>
|
||||
{
|
||||
"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', },
|
||||
"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}->{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::activesyncmailbox::get_powershell(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 . " 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::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check activesync 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>
|
||||
|
||||
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<--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
|
|
@ -0,0 +1,176 @@
|
|||
################################################################################
|
||||
# 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::imapmailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::imapmailbox;
|
||||
|
||||
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 =>
|
||||
{
|
||||
"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', },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
"password:s" => { name => 'password', },
|
||||
});
|
||||
$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();
|
||||
}
|
||||
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::imapmailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
|
||||
password => $self->{option_results}->{password},
|
||||
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::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check imap 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>
|
||||
|
||||
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<--mailbox>
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Set the password for the mailbox (Required).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -47,8 +47,10 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'databases' => 'apps::exchange::2010::local::mode::databases',
|
||||
'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox',
|
||||
'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox',
|
||||
'databases' => 'apps::exchange::2010::local::mode::databases',
|
||||
'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox',
|
||||
'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
################################################################################
|
||||
# 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::activesyncmailbox;
|
||||
|
||||
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;
|
||||
my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate';
|
||||
|
||||
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"
|
||||
$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-ActiveSyncConnectivity -MailboxCredential $cred ' . $no_trust_ssl . '
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Foreach ($result in $results) {
|
||||
Write-Host "[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:
|
||||
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok.");
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
|
||||
my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$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("ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $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("ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $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
|
|
@ -120,7 +120,7 @@ Foreach ($DB in $MountedDB) {
|
|||
$ps .= '
|
||||
# Test Mailflow
|
||||
$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
|
||||
Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
|
||||
Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime.TotalMilliseconds "]" -NoNewline
|
||||
';
|
||||
}
|
||||
|
||||
|
@ -200,10 +200,9 @@ sub check_mailflow {
|
|||
}
|
||||
}
|
||||
|
||||
$latency =~ /\d+:\d+:(.*)/;
|
||||
if (defined($1)) {
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => 'latency_' . $options{database}, unit => 's',
|
||||
value => sprintf("%.3f", $1),
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +212,7 @@ sub check {
|
|||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
|
||||
#...
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
################################################################################
|
||||
# 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::imapmailbox;
|
||||
|
||||
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"
|
||||
$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-ImapConnectivity -MailboxCredential $cred
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Foreach ($result in $results) {
|
||||
Write-Host "[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:
|
||||
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Imap to '" . $options{mailbox} . "' is ok.");
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
|
||||
my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$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("Imap scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $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("Imap scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $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 imap on a specific mailbox.
|
||||
|
||||
=cut
|
|
@ -184,6 +184,7 @@ sub perfdata_add {
|
|||
my ($self, %options) = @_;
|
||||
my $perfdata = {'label' => '', 'value' => '', unit => '', warning => '', critical => '', min => '', max => ''};
|
||||
$perfdata = {%$perfdata, %options};
|
||||
$perfdata->{label} =~ s/'/''/g;
|
||||
push @{$self->{perfdatas}}, $perfdata;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue