-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from dsccommunity/CMHeartbeatDiscovery
Initial CMHeartbeat Discovery module creation
- Loading branch information
Showing
12 changed files
with
780 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
242 changes: 242 additions & 0 deletions
242
source/DSCResources/DSC_CMHeartbeatDiscovery/DSC_CMHeartbeatDiscovery.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
$script:dscResourceCommonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\DscResource.Common' | ||
$script:configMgrResourcehelper = Join-Path -Path $PSScriptRoot -ChildPath '..\..\Modules\ConfigMgrCBDsc.ResourceHelper' | ||
|
||
Import-Module -Name $script:dscResourceCommonPath | ||
Import-Module -Name $script:configMgrResourcehelper | ||
|
||
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' | ||
|
||
<# | ||
.SYNOPSIS | ||
This will return a hashtable of results. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER Enabled | ||
Specifies the enablement of the Heatbeat discovery method. | ||
Not used in Get-TargetResource. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[Boolean] | ||
$Enabled | ||
) | ||
|
||
Write-Verbose -Message $script:localizedData.RetrieveSettingValue | ||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
|
||
$heartbeat = (Get-CMDiscoveryMethod -Name HeartbeatDiscovery -SiteCode $SiteCode).Props | ||
$state = ($heartbeat | Where-Object -FilterScript {$_.PropertyName -eq 'Enable Heartbeat DDR'}).Value | ||
$heartbeatSchedule = ($heartbeat | Where-Object -FilterScript {$_.PropertyName -eq 'DDR Refresh Interval'}).Value2 | ||
|
||
$scheduleConvert = ConvertTo-ScheduleInterval -ScheduleString $heartbeatSchedule | ||
|
||
return @{ | ||
SiteCode = $SiteCode | ||
Enabled = $state | ||
ScheduleInterval = $scheduleConvert.Interval | ||
ScheduleCount = $scheduleConvert.Count | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will set the desired state. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER Enabled | ||
Specifies the enablement of the Heatbeat discovery method. | ||
.PARAMETER ScheduleInterval | ||
Specifies the time when the scheduled event recurs in hours and days. | ||
.PARAMETER ScheduleCount | ||
Specifies how often the recur interval is run. If hours are specified the max value | ||
is 23. Anything over 23 will result in 23 to be set. If days are specified the max value | ||
is 31. Anything over 31 will result in 31 to be set. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[Boolean] | ||
$Enabled, | ||
|
||
[Parameter()] | ||
[ValidateSet('Hours','Days')] | ||
[String] | ||
$ScheduleInterval, | ||
|
||
[Parameter()] | ||
[UInt32] | ||
$ScheduleCount | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
|
||
try | ||
{ | ||
$state = Get-TargetResource -SiteCode $SiteCode -Enabled $Enabled | ||
|
||
if ($Enabled -ne $state.Enabled) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SettingEnable -f $state.Enabled, $Enabled) | ||
$buildingParams = @{ | ||
Enabled = $Enabled | ||
} | ||
} | ||
|
||
if ($Enabled -eq $true) | ||
{ | ||
if (($PSBoundParameters.ContainsKey('ScheduleInterval') -and -not $PSBoundParameters.ContainsKey('ScheduleCount')) -or | ||
($PSBoundParameters.ContainsKey('ScheduleCount') -and -not $PSBoundParameters.ContainsKey('ScheduleInterval'))) | ||
{ | ||
throw $script:localizedData.IntervalCount | ||
} | ||
|
||
if ($PSBoundParameters.ContainsKey('ScheduleInterval')) | ||
{ | ||
if ($ScheduleInterval -ne $state.ScheduleInterval) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SIntervalSet -f $ScheduleInterval) | ||
$setSchedule = $true | ||
} | ||
|
||
if ($ScheduleCount -ne $state.ScheduleCount) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SCountSet -f $ScheduleCount) | ||
$setSchedule = $true | ||
} | ||
|
||
if ($setSchedule -eq $true) | ||
{ | ||
$pScheduleSet = @{ | ||
RecurInterval = $ScheduleInterval | ||
RecurCount = $ScheduleCount | ||
} | ||
|
||
$pschedule = New-CMSchedule @pScheduleSet | ||
|
||
$buildingParams += @{ | ||
PollingSchedule = $pSchedule | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($buildingParams) | ||
{ | ||
Set-CMDiscoveryMethod -Heartbeat -SiteCode $SiteCode @buildingParams | ||
} | ||
} | ||
catch | ||
{ | ||
throw $_ | ||
} | ||
finally | ||
{ | ||
Set-Location -Path "$env:temp" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
This will test the desired state. | ||
.PARAMETER SiteCode | ||
Specifies the site code for Configuration Manager site. | ||
.PARAMETER Enabled | ||
Specifies the enablement of the Heatbeat discovery method. | ||
.PARAMETER ScheduleInterval | ||
Specifies the time when the scheduled event recurs in hours and days. | ||
.PARAMETER ScheduleCount | ||
Specifies how often the recur interval is run. If hours are specified the max value | ||
is 23. Anything over 23 will result in 23 to be set. If days are specified the max value | ||
is 31. Anything over 31 will result in 31 to be set. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$SiteCode, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[Boolean] | ||
$Enabled, | ||
|
||
[Parameter()] | ||
[ValidateSet('Hours','Days')] | ||
[String] | ||
$ScheduleInterval, | ||
|
||
[Parameter()] | ||
[UInt32] | ||
$ScheduleCount | ||
) | ||
|
||
Import-ConfigMgrPowerShellModule -SiteCode $SiteCode | ||
Set-Location -Path "$($SiteCode):\" | ||
$state = Get-TargetResource -SiteCode $SiteCode -Enabled $Enabled | ||
$result = $true | ||
|
||
if ($Enabled -ne $state.Enabled) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.EnableStatus -f $Enabled, $state.Enabled) | ||
$result = $false | ||
} | ||
|
||
if (($PSBoundParameters.ContainsKey('ScheduleInterval') -and -not $PSBoundParameters.ContainsKey('ScheduleCount')) -or | ||
($PSBoundParameters.ContainsKey('ScheduleCount') -and -not $PSBoundParameters.ContainsKey('ScheduleInterval'))) | ||
{ | ||
Write-Verbose -Message $script:localizedData.IntervalCountTest | ||
$result = $false | ||
} | ||
|
||
if ($PSBoundParameters.ContainsKey('ScheduleInterval') -and $PSBoundParameters.ContainsKey('ScheduleCount')) | ||
{ | ||
if ($ScheduleInterval -ne $state.SCheduleInterval) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SIntervalTest -f $ScheduleInterval, $State.ScheduleInterval) | ||
$result = $false | ||
} | ||
|
||
if (($ScheduleInterval -ne 'None') -and ($ScheduleCount -ne $state.ScheduleCount)) | ||
{ | ||
Write-Verbose -Message ($script:localizedData.SCountTest -f $ScheduleCount, $State.ScheduleCount) | ||
$result = $false | ||
} | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.TestState -f $result) | ||
return $result | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
8 changes: 8 additions & 0 deletions
8
source/DSCResources/DSC_CMHeartbeatDiscovery/DSC_CMHeartbeatDiscovery.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ClassVersion("1.0.0"), FriendlyName("CMHeartbeatDiscovery")] | ||
class DSC_CMHeartbeatDiscovery : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the SiteCode for the Configuration Manager site.")] String SiteCode; | ||
[Required, Description("Specifies the enablement of the heartbeat discovery method.")] Boolean Enabled; | ||
[Write, Description("Specifies the recur interval of days, hours"),ValueMap{"Days","Hours"},Values{"Days","Hours"}] String ScheduleInterval; | ||
[Write, Description("Specifies how often the recur interval is run. If hours are specified the max value is 23. Anything over 23 will result in 23 to be set. If days are specified the max value is 31. Anything over 31 will result in 31 to be set.")] UInt32 ScheduleCount; | ||
}; |
12 changes: 12 additions & 0 deletions
12
source/DSCResources/DSC_CMHeartbeatDiscovery/en-US/DSC_CMHeartbeatDiscovery.strings.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ConvertFrom-StringData @' | ||
RetrieveSettingValue = Getting results for Configuration Manager heartbeat discovery method. | ||
EnableStatus = Heartbeat discovery is set to {0} return {1}. | ||
IntervalCountTest = Missing ScheduleInterval or ScheduleCount unable to evaluate schedule. | ||
SIntervalTest = NOT MATCH: Schedule interval expected: {0} returned {1}. | ||
SCountTest = NOT MATCH: Schedule count expected: {0} returned {1}. | ||
TestState = Test-TargetResource compliance check returned: {0}. | ||
SettingEnable = Heartbeat discovery is currently {0}, setting to {1}. | ||
IntervalCount = Invalid parameter usage must specify ScheduleInterval and ScheduleCount. | ||
SIntervalSet = Setting Schedule interval to {0}. | ||
SCountSet = Setting Schedule count to {0}. | ||
'@ |
17 changes: 17 additions & 0 deletions
17
source/Examples/Resources/CMHeartbeatDiscovery/CMHeartbeatDiscovery_Disabled.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<# | ||
.SYNOPSIS | ||
A DSC configuration script to disable heartbeat discovery in Configuration Manager. | ||
#> | ||
Configuration Example | ||
{ | ||
Import-DscResource -ModuleName ConfigMgrCBDsc | ||
|
||
Node localhost | ||
{ | ||
CMHeartbeatDiscovery ExampleSettings | ||
{ | ||
SiteCode = 'Lab' | ||
Enabled = $false | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
source/Examples/Resources/CMHeartbeatDiscovery/CMHeartbeatDiscovery_Enabled.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<# | ||
.SYNOPSIS | ||
A DSC configuration script to enable heartbeat discovery in Configuration Manager. | ||
#> | ||
Configuration Example | ||
{ | ||
Import-DscResource -ModuleName ConfigMgrCBDsc | ||
|
||
Node localhost | ||
{ | ||
CMHeartbeatDiscovery ExampleSettings | ||
{ | ||
SiteCode = 'Lab' | ||
Enabled = $true | ||
ScheduleInterval = 'Days' | ||
ScheduleCount = '4' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.