fix(sccm): sites-status - better management of psprovider (#3065)

This commit is contained in:
qgarnier 2021-08-31 17:36:12 +02:00 committed by GitHub
parent 836fbbe855
commit 88c39bc817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 36 deletions

View File

@ -25,19 +25,19 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use JSON::XS; use JSON::XS;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use centreon::plugins::misc; use centreon::plugins::misc;
use centreon::common::powershell::sccm::sitestatus; use centreon::common::powershell::sccm::sitestatus;
my %map_mode = ( my %map_mode = (
0 => 'Unknown', 0 => '-',
1 => 'Replication maintenance', 1 => 'Replication maintenance',
2 => 'Recovery in progress', 2 => 'Recovery in progress',
3 => 'Upgrade in progress', 3 => 'Upgrade in progress',
4 => 'Evaluation has expired', 4 => 'Evaluation has expired',
5 => 'Site expansion in progress', 5 => 'Site expansion in progress',
6 => 'Interop mode where there are primary sites, having the same version as the CAS, were not upgraded', 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', 7 => 'Interop mode where there are secondary sites, having the same version as the top-level site server, were not upgraded'
); );
my %map_status = ( my %map_status = (
0 => 'Unknown', 0 => 'Unknown',
@ -49,19 +49,19 @@ my %map_status = (
6 => 'Failed to delete or deinstall the secondary site', 6 => 'Failed to delete or deinstall the secondary site',
7 => 'Failed to upgrade the secondary site', 7 => 'Failed to upgrade the secondary site',
8 => 'Secondary site recovery is in progress', 8 => 'Secondary site recovery is in progress',
9 => 'Failed to recover secondary site', 9 => 'Failed to recover secondary site'
); );
my %map_type = ( my %map_type = (
0 => 'Unknown', 0 => 'Unknown',
1 => 'SECONDARY', 1 => 'SECONDARY',
2 => 'PRIMARY', 2 => 'PRIMARY',
4 => 'CAS', 4 => 'CAS'
); );
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return sprintf("status is '%s' [Type: %s] [Mode: '%s']", return sprintf("status is '%s' [type: %s] [mode: '%s']",
$self->{result_values}->{status}, $self->{result_values}->{status},
$self->{result_values}->{type}, $self->{result_values}->{type},
$self->{result_values}->{mode} $self->{result_values}->{mode}
@ -88,7 +88,7 @@ sub set_counters {
]; ];
$self->{maps_counters}->{sites} = [ $self->{maps_counters}->{sites} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, set => {
key_values => [ key_values => [
{ name => 'display' }, { name => 'SiteName' }, { name => 'Type' }, { name => 'Mode' }, { name => 'display' }, { name => 'SiteName' }, { name => 'Type' }, { name => 'Mode' },
{ name => 'Status' }, { name => 'SecondarySiteCMUpdateStatus' } { name => 'Status' }, { name => 'SecondarySiteCMUpdateStatus' }
@ -96,7 +96,7 @@ sub set_counters {
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
} }
]; ];
@ -120,21 +120,12 @@ sub new {
'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
'no-ps' => { name => 'no_ps' }, 'no-ps' => { name => 'no_ps' },
'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-exec-only' => { name => 'ps_exec_only' },
'ps-display' => { name => 'ps_display' }, 'ps-display' => { name => 'ps_display' }
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' }
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -46,25 +46,27 @@ Try {
$module = $modulePath + "\ConfigurationManager.psd1" $module = $modulePath + "\ConfigurationManager.psd1"
Import-Module $module 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 = @() $returnArray = @()
Foreach ($site in $CMObject) { $providers = Get-PSProvider | Where {$_.Name -match "CMSite" }
$returnObject = New-Object -TypeName PSObject foreach ($provider in $providers) {
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteCode" -Value $site.SiteCode New-PSDrive -Name SCCMDrive -PSProvider $provider.Name -Root $env:COMPUTERNAME -Description "SCCM Site" | Out-Null
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SiteName" -Value $site.SiteName CD "SCCMDrive:\"
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Type" -Value $site.Type $CMObject = Get-CMSite
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Mode" -Value $site.Mode CD "C:\"
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "Status" -Value $site.Status Remove-PSDrive -Name SCCMDrive
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "SecondarySiteCMUpdateStatus" -Value $site.SecondarySiteCMUpdateStatus
$returnArray += $returnObject Foreach ($site in $CMObject) {
$returnObject = New-Object -TypeName PSObject
Add-Member -InputObject $returnObject -MemberType NoteProperty -Name "providerName" -Value $provider.Name
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 -forceArray $true $returnArray | ConvertTo-JSON-20 -forceArray $true