fix pending reboot

This commit is contained in:
qgarnier 2017-09-15 15:11:05 +02:00
parent 7ddbe8efa4
commit c455dd7668
2 changed files with 13 additions and 12 deletions

View File

@ -49,26 +49,26 @@ Try {
## Making registry connection to the local/remote computer
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\$ComputerName\root\default:StdRegProv"
$WMI_Reg = [WMIClass] "\\\\$ComputerName\\root\\default:StdRegProv"
## If Vista/2008 & Above query the CBS Reg Key
If ([Int32]$WMI_OS.BuildNumber -ge 6001) {
$RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
$RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\")
$CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"
}
## Query WUAU from the registry
$RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
$RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\")
$WUAURebootReq = $RegWUAURebootReq.sNames -contains "RebootRequired"
## Query PendingFileRenameOperations from the registry
$RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
$RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\","PendingFileRenameOperations")
$RegValuePFRO = $RegSubKeySM.sValue
## Query ComputerName and ActiveComputerName from the registry
$ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\","ComputerName")
$CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\","ComputerName")
If ($ActCompNm -ne $CompNm) {
$ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName\\","ComputerName")
$CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName\\","ComputerName")
If ($ActCompNm -ne $CompNm) {
$CompPendRen = $true
}
@ -81,7 +81,7 @@ Try {
## To avoid nested "if" statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0
$CCMClientSDK = $null
$CCMSplat = @{
NameSpace="ROOT\ccm\ClientSDK"
NameSpace="ROOT\\ccm\\ClientSDK"
Class="CCM_ClientUtilities"
Name="DetermineIfRebootPending"
ComputerName=$ComputerName
@ -138,3 +138,4 @@ __END__
Method to get pending reboot informations.
=cut

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::common::powershell::windows::pendingreboot
use centreon::common::powershell::windows::pendingreboot;
my $instance_mode;
@ -74,9 +74,9 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'vm', type => 1, },
{ name => 'pendingreboot', type => 0 },
];
$self->{maps_counters}->{vm} = [
$self->{maps_counters}->{pendingreboot} = [
{ label => 'status', , threshold => 0, set => {
key_values => [ { name => 'CBServicing' }, { name => 'RebootPending' }, { name => 'WindowsUpdate' },
{ name => 'CCMClientSDK' } ],
@ -148,7 +148,7 @@ sub manage_selection {
#[CBServicing=False][WindowsUpdate=False][CCMClientSDK=][PendComputerRename=False][PendFileRename=False][PendFileRenVal=][RebootPending=False]
$self->{pendingreboot} = {};
while ($line =~ /\[(.*?)=\s*(.*?)\s*\]/mg) {
while ($stdout =~ /\[(.*?)=\s*(.*?)\s*\]/mg) {
$self->{pendingreboot}->{$1} = $2;
}
}