From 36a588f78b1981bc926d17a2258f086031e922cd Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Wed, 24 Apr 2019 18:25:22 +0200 Subject: [PATCH] add sccm plugin --- .../local/mode/databasereplicationstatus.pm | 245 ++++++++++++++++++ apps/sccm/local/mode/sitestatus.pm | 226 ++++++++++++++++ apps/sccm/local/plugin.pm | 49 ++++ .../sccm/databasereplicationstatus.pm | 97 +++++++ centreon/common/powershell/sccm/sitestatus.pm | 90 +++++++ 5 files changed, 707 insertions(+) create mode 100644 apps/sccm/local/mode/databasereplicationstatus.pm create mode 100644 apps/sccm/local/mode/sitestatus.pm create mode 100644 apps/sccm/local/plugin.pm create mode 100644 centreon/common/powershell/sccm/databasereplicationstatus.pm create mode 100644 centreon/common/powershell/sccm/sitestatus.pm diff --git a/apps/sccm/local/mode/databasereplicationstatus.pm b/apps/sccm/local/mode/databasereplicationstatus.pm new file mode 100644 index 000000000..71bd96326 --- /dev/null +++ b/apps/sccm/local/mode/databasereplicationstatus.pm @@ -0,0 +1,245 @@ +# +# Copyright 2019 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::sccm::local::mode::databasereplicationstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use JSON::XS; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::common::powershell::sccm::databasereplicationstatus; +use DateTime; + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("Overall Link status is '%s'", $self->{result_values}->{status}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_LinkStatus'}; + return 0; +} + +sub custom_site_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("status is '%s', Site-to-Site state is '%s' [Type: %s] [Last sync: %s]", + $self->{result_values}->{status}, + $self->{result_values}->{site_to_site_state}, + $self->{result_values}->{type}, + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{last_sync_time})); + return $msg; +} + +sub custom_site_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_SiteStatus'}; + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_SiteType'}; + $self->{result_values}->{site_to_site_state} = $options{new_datas}->{$self->{instance} . '_SiteToSiteGlobalState'}; + $self->{result_values}->{sync_time} = $options{new_datas}->{$self->{instance} . '_SiteToSiteGlobalSyncTime'}; + + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); + $self->{result_values}->{sync_time} =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/; + my $sync_time = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, %$tz); + + $self->{result_values}->{last_sync_time} = time() - $sync_time->epoch; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'sites', type => 1, cb_prefix_output => 'prefix_output_site', message_multiple => 'All sites status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'link-status', threshold => 0, set => { + key_values => [ { name => 'LinkStatus' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + $self->{maps_counters}->{sites} = [ + { label => 'site-status', threshold => 0, set => { + key_values => [ { name => 'SiteType' }, { name => 'SiteStatus' }, { name => 'SiteToSiteGlobalState' }, + { name => 'SiteToSiteGlobalSyncTime' } ], + closure_custom_calc => $self->can('custom_site_status_calc'), + closure_custom_output => $self->can('custom_site_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_output_site { + my ($self, %options) = @_; + + return "Site '" . $options{instance_value}->{display} . "' "; +} + +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 => { + "timeout:s" => { name => 'timeout', default => 30 }, + "command:s" => { name => 'command', default => 'powershell.exe' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + "no-ps" => { name => 'no_ps' }, + "ps-exec-only" => { name => 'ps_exec_only' }, + "warning-link-status:s" => { name => 'warning_link_status', default => '' }, + "critical-link-tatus:s" => { name => 'critical_link_status', default => '' }, + "warning-site-status:s" => { name => 'warning_site_status', default => '' }, + "critical-site-tatus:s" => { name => 'critical_site_status', default => '' }, + "timezone:s" => { name => 'timezone', default => 'UTC' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_link_status', 'critical_link_status', + 'warning_site_status', 'critical_site_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::sccm::databasereplicationstatus::get_powershell( + no_ps => $self->{option_results}->{no_ps}, + ); + + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + 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(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($stdout); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + $self->{global}->{LinkStatus} = $decoded->{LinkStatus}; + + $self->{sites}->{$decoded->{Site1}} = { + display => $decoded->{Site1}, + SiteType => $decoded->{SiteType1}, + SiteStatus => $decoded->{Site1Status}, + SiteToSiteGlobalState => $decoded->{Site1ToSite2GlobalState}, + SiteToSiteGlobalSyncTime => $decoded->{Site1ToSite2GlobalSyncTime}, + }; + $self->{sites}->{$decoded->{Site2}} = { + display => $decoded->{Site2}, + SiteType => $decoded->{SiteType2}, + SiteStatus => $decoded->{Site2Status}, + SiteToSiteGlobalState => $decoded->{Site2ToSite1GlobalState}, + SiteToSiteGlobalSyncTime => $decoded->{Site2ToSite1GlobalSyncTime}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check database replication status. + +=over 8 + +=item B<--timeout> + +Set timeout time for command execution (Default: 30 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-link-status> + +Set warning threshold for current synchronisation status (Default: '') +Can used special variables like: %{status}. + +=item B<--critical-link-status> + +Set critical threshold for current synchronisation status (Default: ''). +Can used special variables like: %{status}. + +=item B<--warning-site-status> + +Set warning threshold for current synchronisation status (Default: '') +Can used special variables like: %{status}, %{type}, %{site_to_site_state}, %{last_sync_time}. + +=item B<--critical-site-status> + +Set critical threshold for current synchronisation status (Default: ''). +Can used special variables like: %{status}, %{type}, %{site_to_site_state}, %{last_sync_time}. + +=back + +=cut diff --git a/apps/sccm/local/mode/sitestatus.pm b/apps/sccm/local/mode/sitestatus.pm new file mode 100644 index 000000000..7ae521b24 --- /dev/null +++ b/apps/sccm/local/mode/sitestatus.pm @@ -0,0 +1,226 @@ +# +# Copyright 2019 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::sccm::local::mode::sitestatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use JSON::XS; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::common::powershell::sccm::sitestatus; + +my %map_mode = ( + 0 => 'Unknown', + 1 => 'Replication maintenance', + 2 => 'Recovery in progress', + 3 => 'Upgrade in progress', + 4 => 'Evaluation has expired', + 5 => 'Site expansion in progress', + 6 => 'Interop mode where there are primary sites, having the same version as the CAS, were not upgraded', + 7 => 'Interop mode where there are secondary sites, having the same version as the top-level site server, were not upgraded', +); +my %map_status = ( + 0 => 'Unknown', + 1 => 'ACTIVE', + 2 => 'PENDING', + 3 => 'FAILED', + 4 => 'DELETED', + 5 => 'UPGRADE', + 6 => 'Failed to delete or deinstall the secondary site', + 7 => 'Failed to upgrade the secondary site', + 8 => 'Secondary site recovery is in progress', + 9 => 'Failed to recover secondary site', +); +my %map_type = ( + 0 => 'Unknown', + 1 => 'SECONDARY', + 2 => 'PRIMARY', + 4 => 'CAS', +); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("status is '%s' [Type: %s] [Mode: '%s']", + $self->{result_values}->{status}, + $self->{result_values}->{type}, + $self->{result_values}->{mode}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_SiteName'}; + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_Type'}; + $self->{result_values}->{mode} = $options{new_datas}->{$self->{instance} . '_Mode'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_Status'}; + $self->{result_values}->{secondary_site_status} = $options{new_datas}->{$self->{instance} . '_SecondarySiteCMUpdateStatus'}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sites', type => 1, cb_prefix_output => 'prefix_output_site', message_multiple => 'All sites status are ok' }, + ]; + + $self->{maps_counters}->{sites} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'display' }, { name => 'SiteName' }, { name => 'Type' }, { name => 'Mode' }, + { name => 'Status' }, { name => 'SecondarySiteCMUpdateStatus' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_output_site { + my ($self, %options) = @_; + + return "Site '" . $options{instance_value}->{display} . "' "; +} + +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 => { + "timeout:s" => { name => 'timeout', default => 30 }, + "command:s" => { name => 'command', default => 'powershell.exe' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + "no-ps" => { name => 'no_ps' }, + "ps-exec-only" => { name => 'ps_exec_only' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-tatus:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::sccm::sitestatus::get_powershell( + no_ps => $self->{option_results}->{no_ps}, + ); + + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + 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(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($stdout); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + foreach my $site (@{$decoded}) { + $self->{sites}->{$site->{SiteCode}} = { + display => $site->{SiteCode}, + SiteName => $site->{SiteName}, + Type => $map_type{$site->{Type}}, + Mode => $map_mode{$site->{Mode}}, + Status => $map_status{$site->{Status}}, + SecondarySiteCMUpdateStatus => $site->{SecondarySiteCMUpdateStatus}, + }; + } + + use Data::Dumper; + print Dumper $self->{sites}; +} + +1; + +__END__ + +=head1 MODE + +Check sites status. + +=over 8 + +=item B<--timeout> + +Set timeout time for command execution (Default: 30 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-status> + +Set warning threshold for current synchronisation status (Default: '') +Can used special variables like: %{status}. + +=item B<--critical-status> + +Set critical threshold for current synchronisation status (Default: ''). +Can used special variables like: %{status}. + +=back + +=cut diff --git a/apps/sccm/local/plugin.pm b/apps/sccm/local/plugin.pm new file mode 100644 index 000000000..8e2f4170b --- /dev/null +++ b/apps/sccm/local/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2019 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::sccm::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; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'database-replication-status' => 'apps::sccm::local::mode::databasereplicationstatus', + 'site-status' => 'apps::sccm::local::mode::sitestatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check SCCM through powershell. + +=cut diff --git a/centreon/common/powershell/sccm/databasereplicationstatus.pm b/centreon/common/powershell/sccm/databasereplicationstatus.pm new file mode 100644 index 000000000..6bb779d64 --- /dev/null +++ b/centreon/common/powershell/sccm/databasereplicationstatus.pm @@ -0,0 +1,97 @@ +# +# Copyright 2019 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::sccm::databasereplicationstatus; + +use strict; +use warnings; +use centreon::common::powershell::functions; + +sub get_powershell { + my (%options) = @_; + 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 +'; + + $ps .= centreon::common::powershell::functions::escape_jsonstring(%options); + $ps .= centreon::common::powershell::functions::convert_to_json(%options); + + $ps .= ' +$ProgressPreference = "SilentlyContinue" + +Try { + $ErrorActionPreference = "Stop" + + $module = ${env:ProgramFiles(x86)} + "\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" + Import-Module $module + + New-PSDrive -Name SCCMDrive -PSProvider "AdminUI.PS.Provider\CMSite" -Root $env:COMPUTERNAME -Description "SCCM Site" | Out-Null + CD "SCCMDrive:\" + + $CMObject = Get-CMSite + + CD "C:\" + Remove-PSDrive -Name SCCMDrive + + $CMObject = Get-CMDatabaseReplicationStatus + + $returnObject = New-Object -TypeName PSObject + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "LinkStatus" -Value $CMObject.LinkStatus + + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site1" -Value $CMObject.Site1 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteName1" -Value $CMObject.SiteName1 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteType1" -Value $CMObject.SiteType1 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site1Status" -Value $CMObject.Site1Status + + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site2" -Value $CMObject.Site2 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteName2" -Value $CMObject.SiteName2 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteType2" -Value $CMObject.SiteType2 + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site2Status" -Value $CMObject.Site2Status + + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site1ToSite2GlobalState" -Value $CMObject.Site1ToSite2GlobalState + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site1ToSite2GlobalSyncTime" -Value $CMObject.Site1ToSite2GlobalSyncTime + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site2ToSite1GlobalState" -Value $CMObject.Site2ToSite1GlobalState + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Site2ToSite1GlobalSyncTime" -Value $CMObject.Site2ToSite1GlobalSyncTime + + $returnObject | ConvertTo-JSON-20 +} Catch { + Write-Host $Error[0].Exception + exit 1 +} + +exit 0 +'; + return centreon::plugins::misc::powershell_encoded($ps); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to get SCCM database replication informations. + +=cut diff --git a/centreon/common/powershell/sccm/sitestatus.pm b/centreon/common/powershell/sccm/sitestatus.pm new file mode 100644 index 000000000..99510c358 --- /dev/null +++ b/centreon/common/powershell/sccm/sitestatus.pm @@ -0,0 +1,90 @@ +# +# Copyright 2019 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::sccm::sitestatus; + +use strict; +use warnings; +use centreon::common::powershell::functions; + +sub get_powershell { + my (%options) = @_; + 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 +'; + + $ps .= centreon::common::powershell::functions::escape_jsonstring(%options); + $ps .= centreon::common::powershell::functions::convert_to_json(%options); + + $ps .= ' +$ProgressPreference = "SilentlyContinue" + +Try { + $ErrorActionPreference = "Stop" + + $module = ${env:ProgramFiles(x86)} + "\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" + Import-Module $module + + New-PSDrive -Name SCCMDrive -PSProvider "AdminUI.PS.Provider\CMSite" -Root $env:COMPUTERNAME -Description "SCCM Site" | Out-Null + CD "SCCMDrive:\" + + $CMObject = Get-CMSite + + CD "C:\" + Remove-PSDrive -Name SCCMDrive + + $returnArray = @() + + Foreach ($site in $CMObject) { + $returnObject = New-Object -TypeName PSObject + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteCode" -Value $site.SiteCode + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteName" -Value $site.SiteName + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Type" -Value $site.Type + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Mode" -Value $site.Mode + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Status" -Value $site.Status + Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SecondarySiteCMUpdateStatus" -Value $site.SecondarySiteCMUpdateStatus + $returnArray += $returnObject + } + + $returnArray | ConvertTo-JSON-20 +} Catch { + Write-Host $Error[0].Exception + exit 1 +} + +exit 0 +'; + return centreon::plugins::misc::powershell_encoded($ps); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to get SCCM database replication informations. + +=cut