(plugin) apps::microsoft::wsus - add downstream servers (#3989)

* wip

* wip

* wip
This commit is contained in:
qgarnier 2022-10-13 15:28:31 +02:00 committed by GitHub
parent bea66af713
commit d4fe70dac6
5 changed files with 66 additions and 50 deletions

View File

@ -100,7 +100,7 @@ sub new {
'ps-display' => { name => 'ps_display' },
'wsus-server:s' => { name => 'wsus_server', default => 'localhost' },
'wsus-port:s' => { name => 'wsus_port', default => 8530 },
'not-updated-since:s' => { name => 'not_updated_since', default => 10 },
'not-updated-since:s' => { name => 'not_updated_since', default => 30 },
'use-ssl' => { name => 'use_ssl' }
});
@ -210,21 +210,15 @@ Set WSUS port.
=item B<--not-updated-since>
Time in minutes to count computers not updated since.
Time in days to count computers not updated since (Default: 30).
=item B<--use-ssl>
Set if WSUS use ssl.
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Warning thresholds.
Can be: 'needing-updates', 'with-update-errors',
'up-to-date', 'not-contacted', 'unassigned'
=item B<--critical-*>
Critical thresholds.
Thresholds.
Can be: 'needing-updates', 'with-update-errors',
'up-to-date', 'not-contacted', 'unassigned'

View File

@ -33,8 +33,7 @@ use DateTime;
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("status is '%s'", $self->{result_values}->{status});
return $msg;
return sprintf("status is '%s'", $self->{result_values}->{status});
}
sub custom_status_calc {
@ -47,8 +46,7 @@ sub custom_status_calc {
sub custom_last_status_output {
my ($self, %options) = @_;
my $msg = sprintf("status is '%s'", $self->{result_values}->{status});
return $msg;
return sprintf("status is '%s'", $self->{result_values}->{status});
}
sub custom_last_status_calc {
@ -73,9 +71,13 @@ sub custom_progress_perfdata {
sub custom_progress_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{progress},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
my $exit = $self->{perfdata}->threshold_check(
value => $self->{result_values}->{progress},
threshold => [
{ label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' }
]
);
return $exit;
}
@ -117,9 +119,13 @@ sub custom_duration_perfdata {
sub custom_duration_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{duration},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
my $exit = $self->{perfdata}->threshold_check(
value => $self->{result_values}->{duration},
threshold => [
{ label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' }
]
);
return $exit;
}
@ -146,12 +152,24 @@ sub custom_duration_calc {
return 0;
}
sub prefix_output_current {
my ($self, %options) = @_;
return "Current Synchronisation ";
}
sub prefix_output_last {
my ($self, %options) = @_;
return "Last Synchronisation ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'current', type => 0, cb_prefix_output => 'prefix_output_current' },
{ name => 'last', type => 0, cb_prefix_output => 'prefix_output_last' },
{ name => 'last', type => 0, cb_prefix_output => 'prefix_output_last' }
];
$self->{maps_counters}->{current} = [
@ -160,7 +178,7 @@ sub set_counters {
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,
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'synchronisation-progress', set => {
@ -168,10 +186,11 @@ sub set_counters {
closure_custom_calc => $self->can('custom_progress_calc'),
closure_custom_output => $self->can('custom_progress_output'),
closure_custom_perfdata => $self->can('custom_progress_perfdata'),
closure_custom_threshold_check => $self->can('custom_progress_threshold'),
closure_custom_threshold_check => $self->can('custom_progress_threshold')
}
},
}
];
$self->{maps_counters}->{last} = [
{ label => 'last-synchronisation-status', threshold => 0, set => {
key_values => [ { name => 'LastSynchronizationResult' } ],
@ -186,24 +205,12 @@ sub set_counters {
closure_custom_calc => $self->can('custom_duration_calc'),
closure_custom_output => $self->can('custom_duration_output'),
closure_custom_perfdata => $self->can('custom_duration_perfdata'),
closure_custom_threshold_check => $self->can('custom_duration_threshold'),
closure_custom_threshold_check => $self->can('custom_duration_threshold')
}
},
];
}
sub prefix_output_current {
my ($self, %options) = @_;
return "Current Synchronisation ";
}
sub prefix_output_last {
my ($self, %options) = @_;
return "Last Synchronisation ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);

View File

@ -55,13 +55,22 @@ Try {
$wsusObject = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$wsusStatus = $wsusObject.GetStatus()
$computerTargetScope = New-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerTargetScope.IncludeDownstreamComputerTargets = $true
$updateSource = "All"
$wsusStatus = $wsusObject.GetComputerStatus($computerTargetScope, $updateSource)
$notUpdatedSinceTimespan = new-object TimeSpan($notUpdatedSince, 0, 0, 0)
$computersNotContactedSinceCount = $wsusObject.GetComputersNotContactedSinceCount([DateTime]::UtcNow.Subtract($notUpdatedSinceTimespan))
$computerTargetScopeNotContactedSince = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerTargetScopeNotContactedSince.ToLastReportedStatusTime = [DateTime]::UtcNow.Subtract($notUpdatedSinceTimespan)
$computerTargetScopeNotContactedSince.IncludeDownstreamComputerTargets = $true
$computersNotContactedSinceCount = $wsusObject.GetComputerTargetCount($computerTargetScopeNotContactedSince)
$computerTargetScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$unassignedComputersCount = $wsusObject.GetComputerTargetGroup([Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::UnassignedComputers).GetComputerTargets().Count
$computerTargetScopeUnassigned = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerTargetScopeUnassigned.IncludeDownstreamComputerTargets = $true
$group = $wsusObject.GetComputerTargetGroups() | ? {$_.Name -like "Unassigned Computers"}
$computerTargetScopeUnassigned.ComputerTargetGroups.Add($group)
$unassignedComputersCount = $wsusObject.GetComputerTargetCount($computerTargetScopeUnassigned)
$item = @{
ComputerTargetsNeedingUpdatesCount = $wsusStatus.ComputerTargetsNeedingUpdatesCount;

View File

@ -54,17 +54,22 @@ Try {
$wsusObject = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$wsusStatus = $wsusObject.GetStatus()
$computerTargetScope = New-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerTargetScope.IncludeDownstreamComputerTargets = $true
$updateSource = "All"
$wsusStatus = $wsusObject.GetComputerStatus($computerTargetScope, $updateSource)
$wsusUpdateStatus = $wsusObject.GetStatus()
$item = @{
ComputerTargetCount = $wsusStatus.ComputerTargetCount;
CustomComputerTargetGroupCount = $wsusStatus.CustomComputerTargetGroupCount;
UpdateCount = $wsusStatus.UpdateCount;
ApprovedUpdateCount = $wsusStatus.ApprovedUpdateCount;
DeclinedUpdateCount = $wsusStatus.DeclinedUpdateCount;
NotApprovedUpdateCount = $wsusStatus.NotApprovedUpdateCount;
UpdatesWithStaleUpdateApprovalsCount = $wsusStatus.UpdatesWithStaleUpdateApprovalsCount;
ExpiredUpdateCount = $wsusStatus.ExpiredUpdateCount
UpdateCount = $wsusUpdateStatus.UpdateCount;
ApprovedUpdateCount = $wsusUpdateStatus.ApprovedUpdateCount;
DeclinedUpdateCount = $wsusUpdateStatus.DeclinedUpdateCount;
NotApprovedUpdateCount = $wsusUpdateStatus.NotApprovedUpdateCount;
UpdatesWithStaleUpdateApprovalsCount = $wsusUpdateStatus.UpdatesWithStaleUpdateApprovalsCount;
ExpiredUpdateCount = $wsusUpdateStatus.ExpiredUpdateCount
}
$jsonString = $item | ConvertTo-JSON-20

View File

@ -54,7 +54,8 @@ Try {
$wsusObject = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$wsusStatus = $wsusObject.GetStatus()
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$wsusStatus = $wsusObject.GetUpdateStatus($UpdateScope, $True)
$item = @{
UpdatesWithClientErrorsCount = $wsusStatus.UpdatesWithClientErrorsCount;