From 6a920d0bcd5a2433e8157f6a10faf0cf9e8ea25b Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Tue, 13 May 2014 17:07:28 +0200 Subject: [PATCH] Refs #5542 Working in progress on Exchange 2010 --- .../exchange/2010/local/mode/databases.pm | 127 ++++++++++++++++++ .../apps/exchange/2010/local/plugin.pm | 65 +++++++++ .../powershell/exchange/2010/databases.pm | 125 +++++++++++++++++ centreon-plugins/centreon/plugins/misc.pm | 12 ++ 4 files changed, 329 insertions(+) create mode 100644 centreon-plugins/apps/exchange/2010/local/mode/databases.pm create mode 100644 centreon-plugins/apps/exchange/2010/local/plugin.pm create mode 100644 centreon-plugins/centreon/common/powershell/exchange/2010/databases.pm diff --git a/centreon-plugins/apps/exchange/2010/local/mode/databases.pm b/centreon-plugins/apps/exchange/2010/local/mode/databases.pm new file mode 100644 index 000000000..6e27920b2 --- /dev/null +++ b/centreon-plugins/apps/exchange/2010/local/mode/databases.pm @@ -0,0 +1,127 @@ +################################################################################ +# 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 . +# +# 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 +# +#################################################################################### + +package apps::exchange::2010::local::mode::databases; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::common::powershell::exchange::2010::databases; + +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', }, + "no-mailflow" => { name => 'no_mailflow', }, + "no-mapi" => { name => 'no_mapi', }, + "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' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +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}, + 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); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check: Exchange Databases are Mounted, Mapi/Mailflow Connectivity to all databases are working. + +=over 8 + +=item B<--no-mailflow> + +Don't check mailflow connectivity. + +=item B<--no-mapi> + +Don't check mapi connectivity. + +=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'). + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/apps/exchange/2010/local/plugin.pm b/centreon-plugins/apps/exchange/2010/local/plugin.pm new file mode 100644 index 000000000..afabb9f14 --- /dev/null +++ b/centreon-plugins/apps/exchange/2010/local/plugin.pm @@ -0,0 +1,65 @@ +################################################################################ +# 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 . +# +# 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 +# +#################################################################################### + +package apps::exchange::2010::local::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'databases' => 'apps::exchange::2010::local::mode::databases', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Windows Exchange 2010 locally. +!!! Experimental system !!! + +=cut diff --git a/centreon-plugins/centreon/common/powershell/exchange/2010/databases.pm b/centreon-plugins/centreon/common/powershell/exchange/2010/databases.pm new file mode 100644 index 000000000..7d5326414 --- /dev/null +++ b/centreon-plugins/centreon/common/powershell/exchange/2010/databases.pm @@ -0,0 +1,125 @@ +################################################################################ +# 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 . +# +# 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 +# +#################################################################################### + +package centreon::common::powershell::exchange::2010::databases; + +use strict; +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" +[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 + } +} else { + 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 + +$Status = "Yes" +Foreach ($DB in $MountedDB) { + Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline + + 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_mailflow == 0) { + $ps .= ' + # Test Mailflow + $MailflowResult = Test-mailflow -Targetdatabase $DB.Name + Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline +'; + } + + $ps .= ' + } + Write-Host "" +} + +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 ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ] + #... + + $self->{output}->output_add(severity => 'OK', + short_msg => $options{stdout}); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to check Exchange 2010 databases. + +=cut \ No newline at end of file diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index b19ff18df..61e573ac2 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -37,6 +37,7 @@ package centreon::plugins::misc; use strict; use warnings; +use utf8; # Function more simple for Windows platform sub windows_execute { @@ -247,6 +248,17 @@ sub trim { return $value; } +sub powershell_encoded { + my ($value) = $_[0]; + + require Encode; + require MIME::Base64; + my $bytes = Encode::encode("utf16LE", $value); + my $script = MIME::Base64::encode_base64($bytes, "\n"); + $script =~ s/\n//g; + return $script; +} + 1; __END__