WMF 4 pull server reporting

While earlier in the chapter we said that WMF 4 DSC Pull servers have been deprecated, if you are still using one, we have the ability to cobble together something with less information than WMF 5 that is still useful. 

We can get a simple status from the DSC pull server using the ComplianceServer endpoint we set up at the beginning of this chapter. While most of its functionality is not documented and not really exposed to the user for use, there are some public features of the DSC ComplianceServer we can take advantage of. We can interrogate the HTTP endpoint for information about our target nodes by issuing an HTTP request at http://localhost:9080/PSDSCComplianceServer.svc/Status. It returns JSON, and there are some credentials we need to use, so let's wrap this into a function we can use more than once:

Function Get-DscPullServerInformation
{
  [cmdletBinding()]
  Param (
    [string] $Uri = "http://localhost:9080/PSDSCComplianceServer.svc/Status"
  )
  Write-Verbose "Querying node information from pull server URI  = $Uri"
    
  $invokeParams = @{
    Uri                   = $Uri
    Method                = "Get"
    ContentType           = 'application/json'
    UseDefaultCredentials = $true
    Headers               = @{Accept = 'application/json'}
  }
  $response = Invoke-WebRequest @invokeParams
    
  if($response.StatusCode -ne 200){
    throw "Could not access $uri"
  }
    
  ConvertFrom-Json $response.Content
}

This example function assumes a lot about your setup, but it is a nice place to start. It is adapted from a blog post on the PowerShell blog here: http://blogs.msdn.com/b/powershell/archive/2014/05/29/how-to-retrieve-node-information-from-pull-server.aspx. If we run this against our DSC pull server, we get the following output:

PS C:vagrant> Get-DscPullServerInformation | select -expand value
TargetName         : 192.168.0.13
ConfigurationId    : 981c0096-a241-48ea-bbe7-15781c229459
ServerCheckSum     : 07E474F06E89FEC570647C85375FEEE1A3A61C854995AA3044E549C3A3EE70A8
TargetCheckSum     : 07E474F06E89FEC570647C85375FEEE1A3A61C854995AA3044E549C3A3EE70A8
NodeCompliant      : True
LastComplianceTime : 2015-08-01T21:06:16.5232617Z
LastHeartbeatTime  : 2015-08-01T21:06:16.5232617Z
Dirty              : True
StatusCode         : 0  

The important properties to note here are NodeCompliant and StatusCode. NodeCompliant tells us whether the state of the target node is in compliance with what the DSC pull server thinks it should be. StatusCode is a number that represents the result of the last pull operation performed by the DSC agent on the target node. StatusCode of 0 means that the last operation was successful; anything else most likely means an error. A list of the numbers and what they mean is provided in the blog post, but it comes with a warning that it reserves the right to change in future releases. This has held true, as we have seen with the additional output WMF 5 brings us.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset