add wsus powershell plugin

This commit is contained in:
Colin Gagnaire 2019-03-21 14:12:48 +01:00
parent d378847612
commit d2fe17653e
9 changed files with 1439 additions and 0 deletions

View File

@ -0,0 +1,228 @@
#
# 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::wsus::local::mode::computersstatus;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::wsus::computersstatus;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'up-to-date', set => {
key_values => [ { name => 'ComputersUpToDateCount' } ],
output_template => 'Up-to-date: %d',
perfdatas => [
{ label => 'computers_up_to_date', value => 'ComputersUpToDateCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'needing-updates', set => {
key_values => [ { name => 'ComputerTargetsNeedingUpdatesCount' } ],
output_template => 'Needing Updates: %d',
perfdatas => [
{ label => 'computers_needing_updates', value => 'ComputerTargetsNeedingUpdatesCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'with-update-errors', set => {
key_values => [ { name => 'ComputerTargetsWithUpdateErrorsCount' } ],
output_template => 'With Update Errors: %d',
perfdatas => [
{ label => 'computers_with_update_errors', value => 'ComputerTargetsWithUpdateErrorsCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'not-contacted', set => {
key_values => [ { name => 'ComputersNotContactedSinceCount' } ],
output_template => 'Not Contacted: %d',
perfdatas => [
{ label => 'computers_not_contacted', value => 'ComputersNotContactedSinceCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'unassigned', set => {
key_values => [ { name => 'UnassignedComputersCount' } ],
output_template => 'Unassigned: %s',
perfdatas => [
{ label => 'computers_unassigned', value => 'UnassignedComputersCount_absolute',
template => '%d', min => 0 },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Computers ";
}
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' },
"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 },
"use-ssl" => { name => 'use_ssl' },
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $use_ssl = "\$false";
$use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl}));
my $ps = centreon::common::powershell::wsus::computersstatus::get_powershell(
no_ps => $self->{option_results}->{no_ps},
wsus_server => $self->{option_results}->{wsus_server},
wsus_port => $self->{option_results}->{wsus_port},
not_updated_since => $self->{option_results}->{not_updated_since},
use_ssl => $use_ssl
);
$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();
}
#[ComputerTargetsNeedingUpdatesCount = 0][ComputerTargetsWithUpdateErrorsCount = 0][ComputersUpToDateCount = 0][ComputersNotContactedSinceCount = 0][UnassignedComputersCount = 0]
if ($stdout =~ /^\[ComputerTargetsNeedingUpdatesCount\s*=\s*(\d+)\s*\]\[ComputerTargetsWithUpdateErrorsCount\s*=\s*(\d+)\s*\]\[ComputersUpToDateCount\s*=\s*(\d+)\s*\]\[ComputersNotContactedSinceCount\s*=\s*(\d+)\s*\]\[UnassignedComputersCount\s*=\s*(\d+)\s*\]/i) {
$self->{global} = {
ComputerTargetsNeedingUpdatesCount => $1,
ComputerTargetsWithUpdateErrorsCount => $2,
ComputersUpToDateCount => $3,
ComputersNotContactedSinceCount => $4,
UnassignedComputersCount => $5,
};
}
}
1;
__END__
=head1 MODE
Check computers 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<--wsus-server>
Set WSUS hostname/IP.
=item B<--wsus-port>
Set WSUS port.
=item B<--not-updated-since>
Time in minutes to count computers not updated since.
=item B<--use-ssl>
Set if WSUS use ssl.
=item B<--warning-*>
Warning thresholds.
Can be: 'needing-updates', 'with-update-errors',
'up-to-date', 'not-contacted', 'unassigned'
=item B<--critical-*>
Critical thresholds.
Can be: 'needing-updates', 'with-update-errors',
'up-to-date', 'not-contacted', 'unassigned'
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='errors'
=back
=cut

View File

@ -0,0 +1,248 @@
#
# 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::wsus::local::mode::serverstatistics;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::wsus::serverstatistics;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'computers', set => {
key_values => [ { name => 'ComputerTargetCount' } ],
output_template => 'Computers: %d',
perfdatas => [
{ label => 'computers', value => 'ComputerTargetCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'computer-groups', set => {
key_values => [ { name => 'CustomComputerTargetGroupCount' } ],
output_template => 'Computer Groups: %d',
perfdatas => [
{ label => 'computer_groups', value => 'CustomComputerTargetGroupCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'updates', set => {
key_values => [ { name => 'UpdateCount' } ],
output_template => 'Updates: %d',
perfdatas => [
{ label => 'updates', value => 'UpdateCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'approved-updates', set => {
key_values => [ { name => 'ApprovedUpdateCount' } ],
output_template => 'Approved Updates: %d',
perfdatas => [
{ label => 'approved_updates', value => 'ApprovedUpdateCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'declined-updates', set => {
key_values => [ { name => 'DeclinedUpdateCount' } ],
output_template => 'Declined Updates: %d',
perfdatas => [
{ label => 'declined_updates', value => 'DeclinedUpdateCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'not-approved-updates', set => {
key_values => [ { name => 'NotApprovedUpdateCount' } ],
output_template => 'Not Approved Updates: %d',
perfdatas => [
{ label => 'not_approved_updates', value => 'NotApprovedUpdateCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'stale-updates', set => {
key_values => [ { name => 'UpdatesWithStaleUpdateApprovalsCount' } ],
output_template => 'Stale Updates: %d',
perfdatas => [
{ label => 'stale_updates', value => 'UpdatesWithStaleUpdateApprovalsCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'expired-updates', set => {
key_values => [ { name => 'ExpiredUpdateCount' } ],
output_template => 'Expired Updates: %d',
perfdatas => [
{ label => 'expired_updates', value => 'ExpiredUpdateCount_absolute',
template => '%d', min => 0 },
],
}
},
];
}
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' },
"wsus-server:s" => { name => 'wsus_server', default => 'localhost' },
"wsus-port:s" => { name => 'wsus_port', default => 8530 },
"use-ssl" => { name => 'use_ssl' },
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $use_ssl = "\$false";
$use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl}));
my $ps = centreon::common::powershell::wsus::serverstatistics::get_powershell(
no_ps => $self->{option_results}->{no_ps},
wsus_server => $self->{option_results}->{wsus_server},
wsus_port => $self->{option_results}->{wsus_port},
use_ssl => $use_ssl
);
$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();
}
#[ComputerTargetCount = 0 ][CustomComputerTargetGroupCount = 1 ][UpdateCount = 109 ][ApprovedUpdateCount = 0 ][DeclinedUpdateCount = 0 ][NotApprovedUpdateCount = 109 ][UpdatesWithStaleUpdateApprovalsCount = 0 ][ExpiredUpdateCount = 0 ]
if ($stdout =~ /^\[ComputerTargetCount\s*=\s*(\d+)\s*\]\[CustomComputerTargetGroupCount\s*=\s*(\d+)\s*\]\[UpdateCount\s*=\s*(\d+)\s*\]\[ApprovedUpdateCount\s*=\s*(\d+)\s*\]\[DeclinedUpdateCount\s*=\s*(\d+)\s*\]\[NotApprovedUpdateCount\s*=\s*(\d+)\s*\]\[UpdatesWithStaleUpdateApprovalsCount\s*=\s*(\d+)\s*\]\[ExpiredUpdateCount\s*=\s*(\d+)\s*\]/i) {
$self->{global} = {
ComputerTargetCount => $1,
CustomComputerTargetGroupCount => $2,
UpdateCount => $3,
ApprovedUpdateCount => $4,
DeclinedUpdateCount => $5,
NotApprovedUpdateCount => $6,
UpdatesWithStaleUpdateApprovalsCount => $7,
ExpiredUpdateCount => $8,
};
}
}
1;
__END__
=head1 MODE
Check server statistics.
=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<--wsus-server>
Set WSUS hostname/IP (Dafault: localhost).
=item B<--wsus-port>
Set WSUS port (Default: 8530).
=item B<--use-ssl>
Set if WSUS use ssl.
=item B<--warning-*>
Warning thresholds.
Can be: 'computers', 'computer-groups', 'updates',
'approved-updates', 'declined-updates',
'not-approved-updates', 'stale-updates', 'expired-updates'
=item B<--critical-*>
Critical thresholds.
Can be: 'computers', 'computer-groups', 'updates',
'approved-updates', 'declined-updates',
'not-approved-updates', 'stale-updates', 'expired-updates'
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='not'
=back
=cut

View File

@ -0,0 +1,360 @@
#
# 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::wsus::local::mode::synchronisationstatus;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::common::powershell::wsus::synchronisationstatus;
use DateTime;
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("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} . '_SynchronizationStatus'};
return 0;
}
sub custom_last_status_output {
my ($self, %options) = @_;
my $msg = sprintf("status is '%s'", $self->{result_values}->{status});
return $msg;
}
sub custom_last_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_LastSynchronizationResult'};
return 0;
}
sub custom_progress_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'synchronisation_progress',
value => $self->{result_values}->{progress},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}),
min => 0, max => 100);
}
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' } ]);
return $exit;
}
sub custom_progress_output {
my ($self, %options) = @_;
my $msg = sprintf("Progress: %.2f%% (%d/%d items)",
$self->{result_values}->{progress},
$self->{result_values}->{processed},
$self->{result_values}->{total});
return $msg;
}
sub custom_progress_calc {
my ($self, %options) = @_;
$self->{result_values}->{processed} = $options{new_datas}->{$self->{instance} . '_ProcessedItems'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_TotalItems'};
$self->{result_values}->{progress} = 0;
return 0 if ($self->{result_values}->{total} == 0);
$self->{result_values}->{progress} = $self->{result_values}->{processed} * 100 / $self->{result_values}->{total};
return 0;
}
sub custom_duration_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'last_synchronisation_duration',
value => $self->{result_values}->{duration},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}),
min => 0, unit => 's');
}
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' } ]);
return $exit;
}
sub custom_duration_output {
my ($self, %options) = @_;
my $msg = sprintf("Duration: %s", centreon::plugins::misc::change_seconds(value => $self->{result_values}->{duration}));
return $msg;
}
sub custom_duration_calc {
my ($self, %options) = @_;
my $start_time = $options{new_datas}->{$self->{instance} . '_LastSynchronizationStartTime'};
my $end_time = $options{new_datas}->{$self->{instance} . '_LastSynchronizationEndTime'};
my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone});
$start_time =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+).*$/;
my $start_time_dt = DateTime->new(year => $3, month => $1, day => $2, hour => $4, minute => $5, second => $6, %$tz);
$end_time =~ /^(\d+)\/(\d+)\/(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+).*$/;
my $end_time_dt = DateTime->new(year => $3, month => $1, day => $2, hour => $4, minute => $5, second => $6, %$tz);
$self->{result_values}->{duration} = $end_time_dt->epoch - $start_time_dt->epoch;
return 0;
}
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' },
];
$self->{maps_counters}->{current} = [
{ label => 'synchronisation-status', threshold => 0, set => {
key_values => [ { name => 'SynchronizationStatus' } ],
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,
}
},
{ label => 'synchronisation-progress', set => {
key_values => [ { name => 'TotalItems' }, { name => 'ProcessedItems' } ],
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'),
}
},
];
$self->{maps_counters}->{last} = [
{ label => 'last-synchronisation-status', threshold => 0, set => {
key_values => [ { name => 'LastSynchronizationResult' } ],
closure_custom_calc => $self->can('custom_last_status_calc'),
closure_custom_output => $self->can('custom_last_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
{ label => 'last-synchronisation-duration', set => {
key_values => [ { name => 'LastSynchronizationStartTime' }, { name => 'LastSynchronizationEndTime' } ],
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'),
}
},
];
}
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);
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' },
"wsus-server:s" => { name => 'wsus_server', default => 'localhost' },
"wsus-port:s" => { name => 'wsus_port', default => 8530 },
"use-ssl" => { name => 'use_ssl' },
"warning-synchronisation-status:s" => { name => 'warning_synchronisation_status', default => '' },
"critical-synchronisation-tatus:s" => { name => 'critical_synchronisation_status', default => '' },
"warning-last-synchronisation-status:s" => { name => 'warning_last_synchronisation_status', default => '' },
"critical-last-synchronisation-tatus:s" => { name => 'critical_last_synchronisation_status', default => '%{status} !~ /Succeeded/' },
"timezone:s" => { name => 'timezone', default => 'UTC' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_synchronisation_status', 'critical_synchronisation_status',
'warning_last_synchronisation_status', 'critical_last_synchronisation_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $use_ssl = "\$false";
$use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl}));
my $ps = centreon::common::powershell::wsus::synchronisationstatus::get_powershell(
no_ps => $self->{option_results}->{no_ps},
wsus_server => $self->{option_results}->{wsus_server},
wsus_port => $self->{option_results}->{wsus_port},
use_ssl => $use_ssl
);
$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();
}
#[SynchronizationStatus = NotProcessing][TotalItems = 0 ][ProcessedItems = 0 ][LastSynchronizationResult = Succeeded ][LastSynchronizationStartTime = 3/21/2019 8:48:50 AM ][LastSynchronizationEndTime = 3/21/2019 10:21:23 AM ]
if ($stdout =~ /^\[SynchronizationStatus\s*=\s*(\w+)\s*\]\[TotalItems\s*=\s*(\d+)\s*\]\[ProcessedItems\s*=\s*(\d+)\s*\]\[LastSynchronizationResult\s*=\s*(\w+)\s*\]\[LastSynchronizationStartTime\s*=\s*(.*)\s*\]\[LastSynchronizationEndTime\s*=\s*(.*)\s*\]/i) {
$self->{current} = {
SynchronizationStatus => $1,
TotalItems => $2,
ProcessedItems => $3,
};
$self->{last} = {
LastSynchronizationResult => $4,
LastSynchronizationStartTime => $5,
LastSynchronizationEndTime => $6,
};
}
}
1;
__END__
=head1 MODE
Check synchronisation 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<--wsus-server>
Set WSUS hostname/IP (Dafault: localhost).
=item B<--wsus-port>
Set WSUS port (Default: 8530).
=item B<--use-ssl>
Set if WSUS use ssl.
=item B<--warning-synchronisation-status>
Set warning threshold for current synchronisation status (Default: '')
Can used special variables like: %{status}.
=item B<--critical-synchronisation-status>
Set critical threshold for current synchronisation status (Default: '').
Can used special variables like: %{status}.
=item B<--warning-last-synchronisation-status>
Set warning threshold for current synchronisation status (Default: '')
Can used special variables like: %{status}.
=item B<--critical-last-synchronisation-status>
Set critical threshold for current synchronisation status (Default: '%{status} !~ /Succeeded/').
Can used special variables like: %{status}.
=item B<--warning-*>
Warning thresholds.
Can be: 'progress' (%), 'duration' (s).
=item B<--critical-*>
Critical thresholds.
Can be: 'progress' (%), 'duration' (s).
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='status'
=back
=cut

View File

@ -0,0 +1,222 @@
#
# 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::wsus::local::mode::updatesstatus;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::common::powershell::wsus::updatesstatus;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'with-client-errors', set => {
key_values => [ { name => 'UpdatesWithClientErrorsCount' } ],
output_template => 'With Client Errors: %d',
perfdatas => [
{ label => 'updates_with_client_errors', value => 'UpdatesWithClientErrorsCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'with-server-errors', set => {
key_values => [ { name => 'UpdatesWithServerErrorsCount' } ],
output_template => 'With Server Errors: %d',
perfdatas => [
{ label => 'updates_with_server_errors', value => 'UpdatesWithServerErrorsCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'needing-files', set => {
key_values => [ { name => 'UpdatesNeedingFilesCount' } ],
output_template => 'Needing Files: %d',
perfdatas => [
{ label => 'updates_needing_files_count', value => 'UpdatesNeedingFilesCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'needed-by-computers', set => {
key_values => [ { name => 'UpdatesNeededByComputersCount' } ],
output_template => 'Needed By Computers: %d',
perfdatas => [
{ label => 'updates_needed_by_computers', value => 'UpdatesNeededByComputersCount_absolute',
template => '%d', min => 0 },
],
}
},
{ label => 'up-to-date', set => {
key_values => [ { name => 'UpdatesUpToDateCount' } ],
output_template => 'Up-to-date: %s',
perfdatas => [
{ label => 'updates_up_to_date', value => 'UpdatesUpToDateCount_absolute',
template => '%d', min => 0 },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Updates ";
}
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' },
"wsus-server:s" => { name => 'wsus_server', default => 'localhost' },
"wsus-port:s" => { name => 'wsus_port', default => 8530 },
"use-ssl" => { name => 'use_ssl' },
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $use_ssl = "\$false";
$use_ssl = "\$true" if (defined($self->{option_results}->{use_ssl}));
my $ps = centreon::common::powershell::wsus::updatesstatus::get_powershell(
no_ps => $self->{option_results}->{no_ps},
wsus_server => $self->{option_results}->{wsus_server},
wsus_port => $self->{option_results}->{wsus_port},
use_ssl => $use_ssl
);
$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();
}
#[UpdatesWithClientErrorsCount = 0 ][UpdatesWithServerErrorsCount = 0 ][UpdatesNeedingFilesCount = 0 ][UpdatesNeededByComputersCount = 0 ][UpdatesUpToDateCount = 0 ]
if ($stdout =~ /^\[UpdatesWithClientErrorsCount\s*=\s*(\d+)\s*\]\[UpdatesWithServerErrorsCount\s*=\s*(\d+)\s*\]\[UpdatesNeedingFilesCount\s*=\s*(\d+)\s*\]\[UpdatesNeededByComputersCount\s*=\s*(\d+)\s*\]\[UpdatesUpToDateCount\s*=\s*(\d+)\s*\]/i) {
$self->{global} = {
UpdatesWithClientErrorsCount => $1,
UpdatesWithServerErrorsCount => $2,
UpdatesNeedingFilesCount => $3,
UpdatesNeededByComputersCount => $4,
UpdatesUpToDateCount => $5,
};
}
}
1;
__END__
=head1 MODE
Check updates 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<--wsus-server>
Set WSUS hostname/IP (Dafault: localhost).
=item B<--wsus-port>
Set WSUS port (Default: 8530).
=item B<--use-ssl>
Set if WSUS use ssl.
=item B<--warning-*>
Warning thresholds.
Can be: 'with-client-errors', 'with-server-errors',
'needing-files', 'needed-by-computers', 'up-to-date'.
=item B<--critical-*>
Critical thresholds.
Can be: 'with-client-errors', 'with-server-errors',
'needing-files', 'needed-by-computers', 'up-to-date'.
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='errors'
=back
=cut

View File

@ -0,0 +1,51 @@
#
# 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::wsus::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}} = (
'computers-status' => 'apps::wsus::local::mode::computersstatus',
'server-statistics' => 'apps::wsus::local::mode::serverstatistics',
'synchronisation-status' => 'apps::wsus::local::mode::synchronisationstatus',
'updates-status' => 'apps::wsus::local::mode::updatesstatus',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check WSUS through powershell.
=cut

View File

@ -0,0 +1,86 @@
#
# 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::wsus::computersstatus;
use strict;
use warnings;
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
$wsusServer = "' . $options{wsus_server} . '"
$useSsl = ' . $options{secure_connection} . '
$wsusPort = ' . $options{wsus_port} . '
$notUpdatedSince = ' . $options{not_updated_since} . '
Try {
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
} Catch {
Write-Host $Error[0].Exception
exit 1
}
$ProgressPreference = "SilentlyContinue"
Try {
$ErrorActionPreference = "Stop"
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$notUpdatedSinceTimespan = new-object TimeSpan($notUpdatedSince, 0, 0, 0)
$computersNotContactedSinceCount = $wsus.GetComputersNotContactedSinceCount([DateTime]::UtcNow.Subtract($notUpdatedSinceTimespan))
$computerTargetScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope
$unassignedComputersCount = $wsus.GetComputerTargetGroup([Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::UnassignedComputers).GetComputerTargets().Count
$status = $wsus.GetStatus()
Write-Host "[ComputerTargetsNeedingUpdatesCount = "$status.ComputerTargetsNeedingUpdatesCount"]" -NoNewline
Write-Host "[ComputerTargetsWithUpdateErrorsCount = "$status.ComputerTargetsWithUpdateErrorsCount"]" -NoNewline
Write-Host "[ComputersUpToDateCount = "$status.ComputersUpToDateCount"]" -NoNewline
Write-Host "[ComputersNotContactedSinceCount = "$computersNotContactedSinceCount"]" -NoNewline
Write-Host "[UnassignedComputersCount = "$unassignedComputersCount"]"
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get WSUS computers informations.
=cut

View File

@ -0,0 +1,82 @@
#
# 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::wsus::serverstatistics;
use strict;
use warnings;
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
$wsusServer = "' . $options{wsus_server} . '"
$useSsl = ' . $options{secure_connection} . '
$wsusPort = ' . $options{wsus_port} . '
Try {
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
} Catch {
Write-Host $Error[0].Exception
exit 1
}
$ProgressPreference = "SilentlyContinue"
Try {
$ErrorActionPreference = "Stop"
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$status = $wsus.GetStatus()
Write-Host "[ComputerTargetCount = "$status.ComputerTargetCount"]" -NoNewline
Write-Host "[CustomComputerTargetGroupCount = "$status.CustomComputerTargetGroupCount"]" -NoNewline
Write-Host "[UpdateCount = "$status.UpdateCount"]" -NoNewline
Write-Host "[ApprovedUpdateCount = "$status.ApprovedUpdateCount"]" -NoNewline
Write-Host "[DeclinedUpdateCount = "$status.DeclinedUpdateCount"]" -NoNewline
Write-Host "[NotApprovedUpdateCount = "$status.NotApprovedUpdateCount"]" -NoNewline
Write-Host "[UpdatesWithStaleUpdateApprovalsCount = "$status.UpdatesWithStaleUpdateApprovalsCount"]" -NoNewline
Write-Host "[ExpiredUpdateCount = "$status.ExpiredUpdateCount"]"
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get WSUS server statistics.
=cut

View File

@ -0,0 +1,83 @@
#
# 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::wsus::synchronisationstatus;
use strict;
use warnings;
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
$wsusServer = "' . $options{wsus_server} . '"
$useSsl = ' . $options{secure_connection} . '
$wsusPort = ' . $options{wsus_port} . '
Try {
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
} Catch {
Write-Host $Error[0].Exception
exit 1
}
$ProgressPreference = "SilentlyContinue"
Try {
$ErrorActionPreference = "Stop"
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$sync_status = $wsus.GetSubscription().GetSynchronizationStatus()
$sync_progress = $wsus.GetSubscription().GetSynchronizationProgress()
$last_sync = $wsus.GetSubscription().GetLastSynchronizationInfo()
Write-Host "[SynchronizationStatus = "$sync_status"]" -NoNewline
Write-Host "[TotalItems = "$sync_progress.TotalItems"]" -NoNewline
Write-Host "[ProcessedItems = "$sync_progress.ProcessedItems"]" -NoNewline
Write-Host "[LastSynchronizationResult = "$last_sync.Result"]" -NoNewline
Write-Host "[LastSynchronizationStartTime = "$last_sync.StartTime"]" -NoNewline
Write-Host "[LastSynchronizationEndTime = "$last_sync.EndTime"]"
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get WSUS synchronisation informations.
=cut

View File

@ -0,0 +1,79 @@
#
# 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::wsus::updatesstatus;
use strict;
use warnings;
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
$wsusServer = "' . $options{wsus_server} . '"
$useSsl = ' . $options{secure_connection} . '
$wsusPort = ' . $options{wsus_port} . '
Try {
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
} Catch {
Write-Host $Error[0].Exception
exit 1
}
$ProgressPreference = "SilentlyContinue"
Try {
$ErrorActionPreference = "Stop"
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($wsusServer, $useSsl, $wsusPort)
$status = $wsus.GetStatus()
Write-Host "[UpdatesWithClientErrorsCount = "$status.UpdatesWithClientErrorsCount"]" -NoNewline
Write-Host "[UpdatesWithServerErrorsCount = "$status.UpdatesWithServerErrorsCount"]" -NoNewline
Write-Host "[UpdatesNeedingFilesCount = "$status.UpdatesNeedingFilesCount"]" -NoNewline
Write-Host "[UpdatesNeededByComputersCount = "$status.UpdatesNeededByComputersCount"]" -NoNewline
Write-Host "[UpdatesUpToDateCount = "$status.UpdatesUpToDateCount"]"
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get WSUS updates informations.
=cut