Notices: This section not yet converted to new layout. Download stats are rolling back out.

This is not the latest version of Posh Puppet Reports available.

Posh Puppet Reports

0.9.51

There are no package test results for this package

This package was submitted prior to moderation and has not been approved. While it is likely safe for you, there is more risk involved.

Powershell scripts to convert Puppet YAML reports into different formats (HTML, TeamCity events), and includes a GUI to convert reports on the fly

To install Posh Puppet Reports, run the following command from the command line or from PowerShell:

C:\> choco install poshpuppetreports --version 0.9.51

To upgrade Posh Puppet Reports, run the following command from the command line or from PowerShell:

C:\> choco upgrade poshpuppetreports --version 0.9.51

Files

Hide
  • tools\chocolateyInstall.ps1 Show
    $packageName = 'poshpuppetreports' # arbitrary name for the package, used in messages
    
    try { 
      $installDir = Join-Path (Join-Path $PSHome "Modules") "POSHPuppetReports"
    
      $sourceDir = Join-Path (Split-Path -parent $MyInvocation.MyCommand.Definition) "module"
    
      # Copy the folder to the powershell modules directory
      [void] (Copy-Item -Path $sourceDir -Destination $installDir -Recurse -Confirm:$false -Force -ErrorAction 'Stop')
      
      # Create a shortcut for the reports into the "Start Menu"
      $shortcutPath = ([Environment]::GetFolderPath('CommonStartMenu')) + '\POSH Puppet Reports\Report GUI.lnk'
      if (! (Test-Path $shortcutPath)) {
        Write-Debug 'Creating shortcut folder...'
        [void](New-Item -Path $shortcutPath -ItemType Directory -Force)
      }
      $shortcutFile = $shortcutPath + '\Puppet Report GUI.lnk'  
      $targetPath = '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'  
    
      # TODO: Waiting on FerventCoder to release new chocolatey package with the Install-ChocolateyShortcut function available. Until then, use old-school WScript.
      #Install-ChocolateyShortcut -shortcutFilePath $shortcutPath -targetPath $targetPath  
      $WshShell = New-Object -ComObject WScript.Shell
      $Shortcut = $WshShell.CreateShortcut($shortcutFile)
      $Shortcut.TargetPath = $targetPath
      $Shortcut.Arguments = "`"& { . '$($installDir)\reportgui\reportgui.ps1'}`""
      $Shortcut.Save()
        
      Write-ChocolateySuccess "$packageName"
    } catch {
      Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
      throw 
    }
    
    
  • tools\module\Write-ResourceStatusSummary.ps1 Show
    function Write-ResourceStatusSummary($objYaml, $xmlDoc) {
      $reportInfoNode = $xmlDoc.createElement('reportinformation')  
      $node = $xmlDoc.createElement('host'); $node.innerText = $objYaml.host; [void]($reportInfoNode.appendChild($node))
      $node = $xmlDoc.createElement('time'); $node.innerText = $objYaml.time; [void]($reportInfoNode.appendChild($node))
      $node = $xmlDoc.createElement('reportformat'); $node.innerText = $objYaml.report_format; [void]($reportInfoNode.appendChild($node))
      $node = $xmlDoc.createElement('puppetversion'); $node.innerText = $objYaml.puppet_version; [void]($reportInfoNode.appendChild($node))
      $node = $xmlDoc.createElement('status'); $node.innerText = $objYaml.status; [void]($reportInfoNode.appendChild($node))
      $node = $xmlDoc.createElement('environment'); $node.innerText = $objYaml.environment; [void]($reportInfoNode.appendChild($node))
      [void]($xmlDoc.DocumentElement.appendChild($reportInfoNode))
    
      $statuses = @{}
      $resourceMetrics = $objYaml.metrics['resources'].values
      $total = 0
      for($index = $resourceMetrics.GetLowerBound(0); $index -lt $resourceMetrics.GetUpperBound(0); $index = $index + 3) {
        
        if ($resourceMetrics[$index] -eq 'total')
        {
          $total = $resourceMetrics[$index + 2]
        } 
        else
        {
          $statusInfo = @{}
          $statusInfo['count'] = $resourceMetrics[$index + 2]
          $statusInfo['id'] = $resourceMetrics[$index]
          $statuses[$resourceMetrics[$index + 1]] = $statusInfo
        } 
      }
      $statusInfo = @{}
        
      $summaryNode = $xmlDoc.createElement('resourcesummary')
      [void]($summaryNode.SetAttribute('total',$total))
      
      $statuses.Keys | ForEach-Object {
        $node = $xmlDoc.createElement('status')
        $node.SetAttribute('name',$_)
        $node.SetAttribute('id',$statuses[$_].id)
        $node.SetAttribute('count',$statuses[$_].count)
        if ($total -gt 0)
        { $node.SetAttribute('percent',[int](($statuses[$_].count / $total)*100)) }
        else
        { $node.SetAttribute('percent',0) }
    
        [void]($summaryNode.AppendChild($node))
        
      }
      [void]($xmlDoc.DocumentElement.AppendChild($summaryNode))
    }
    
  • tools\module\Write-ResourceStatus.ps1 Show
    function Write-ResourceStatus($objYaml, $xmlDoc) {
      $resourcesNode = $xmlDoc.createElement('resources')
    
      $objYaml.resource_statuses.Keys | % {
        $resourceNode = $xmlDoc.createElement('resource')
        [void]($resourceNode.SetAttribute('name',$_))
        $resource = $objYaml.resource_statuses[$_]
    
        $resource.Keys | % {
          $eventsObject = $resource[$_]
          if ($_ -eq 'events')
          {
            # The events resource is special as it can come in as null, an array or hashtable. Need to tailor the XML rendering based on object type
            $eventsNode = $xmlDoc.createElement('events')
            if ($eventsObject -ne $null) {        
              switch ($eventsObject.GetType().ToString() ) {
                "System.Collections.Hashtable" {
                  Write-HashTableToXML 'event' $eventsObject $eventsNode
                  break;
                }
                "System.Object[]" {
                  $eventsObject | % {
                    Write-HashTableToXML 'event' $_ $eventsNode
                  }
                  break;
                }
                default { Throw "Write-ResourceStatus: Unknown object type $($eventsObject.GetType().ToString())"; return $null; }
              }
            }
            [void]($resourceNode.AppendChild($eventsNode))
          }
          else
          {    
            Write-HashTableToXML $_ $eventsObject $resourceNode
          }
        }
        [void]($resourcesNode.AppendChild($resourceNode))
      }
      [void]($xmlDoc.DocumentElement.AppendChild($resourcesNode))
    }
    
  • tools\module\Write-HashTableToXML.ps1 Show
    function Write-HashTableToXML($attrName, $attrValue, $rootNode) {
      $xmlNode = $rootNode.OwnerDocument.createElement($attrName)
      if ($attrValue -ne $null) {
        switch ($attrValue.GetType().ToString()) {
          'System.String' {
            # Special property.  Convert it to ms as well
            if ($attrName -eq 'evaluation_time') {
              $xmlMSnode = $rootNode.OwnerDocument.createElement($attrName + '_ms')
              $xmlMSnode.innerText = [int](([float]$attrValue)*1000)
              [void]($rootNode.appendChild($xmlMSnode))
            }
            $xmlNode.innerText = $attrValue;
            break ;
          }
          'System.Object[]' {
            if ( ($attrValue[0]).GetType().ToString() -eq 'System.Collections.HashTable' ) {
              $attrValue | % { Write-HashTableToXML $attrName $_ $xmlNode }
            } else {
              $xmlNode.innerText = $attrValue;
            }
            break ;
          }
          'System.Collections.Hashtable' { $attrValue.Keys | % { Write-HashTableToXML $_ $attrValue[$_] $xmlNode }; break ; }
          default { $xmlNode.innerText = ('Unknown type ' + $attrValue.GetType().ToString()); break ; }
        }
        
      }
      [void]($rootNode.appendChild($xmlNode))
    }
  • tools\module\transforms\teamcity.tests.stdout.xsl
  • tools\module\transforms\detailed.report.html.xsl
  • tools\module\transforms\basic.report.html.xsl
  • tools\module\Transform-XML.ps1 Show
    function Transform-XML($xmlDocument, $transformFilename) {
    	$xmlContentReader = ([System.Xml.XmlReader]::Create( (New-Object System.IO.StringReader($xmlDocument.innerXML))))
    
    	$StyleSheet = New-Object System.Xml.Xsl.XslCompiledTransform
    	$StyleSheet.Load($transformFile)
    
    	$stringWriter = New-Object System.IO.StringWriter
    	$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter 
    		
    	$StyleSheet.Transform( [System.Xml.XmlReader]$xmlContentReader, [System.Xml.XmlWriter]$XmlWriter)
    	Write-Output $stringWriter.ToString()
    }
  • tools\module\reportgui\reportgui.xaml
  • tools\module\reportgui\reportgui.readme.html
  • tools\module\reportgui\reportgui.ps1 Show
    # Setup script defaults
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    
    # Bootstrap
    function Get-ScriptDirectory
    {
      $Invocation = (Get-Variable MyInvocation -Scope 1).Value
      $global:ScriptDirectory = (Split-Path ($Invocation.MyCommand.Path))
      $global:ScriptDirectory
    }
    [void] (Get-ScriptDirectory)
    
    $transformPath = (Join-Path -Path $global:ScriptDirectory -ChildPath '..\transforms')
    
    #Load Required Assemblies
    Write-Verbose 'Loading WPF assemblies'
    Add-Type �assemblyName PresentationFramework
    Add-Type �assemblyName PresentationCore
    Add-Type �assemblyName WindowsBase
    Write-Verbose 'Loading the POSHPuppetReports module'
    Import-Module "$PSScriptRoot\..\POSHPuppetReports.psd1"
    
    # Load other PS1 files
    Get-ChildItem -Path $global:ScriptDirectory | Where-Object { ($_.Name -imatch '\.ps1$') -and ($_.Name -ne 'reportgui.ps1') } | % {
      Write-Verbose "Importing $($_.Name)..."
      . ($_.Fullname)
    }
    
    # Load XAML from the external file
    Write-Verbose "Loading the window XAML..."
    [xml]$xaml = (Get-Content (Join-Path -Path $global:ScriptDirectory -ChildPath 'reportgui.xaml'))
    
    # Build the GUI
    Write-Verbose "Parsing the window XAML..."
    $reader = (New-Object System.Xml.XmlNodeReader $xaml)
    $Global:wpfWindow = [Windows.Markup.XamlReader]::Load($reader)
    
    # Wire up the XAML
    Write-Verbose "Adding XAML event handlers..."
    (Get-WPFControl 'buttonConnect').Add_Click({
      $serverName = ((Get-WPFControl 'textServerName').Text)
      $userName = ((Get-WPFControl 'textUsername').Text)
      $location = ((Get-WPFControl 'textReportLocation').Text)
          
      [void]( Open-Location -ServerName $serverName -ConnectAs $userName -TargetDirectory $location )
    
      # Populate the list box
      Write-Verbose 'Populating the report list...'
      [xml]$xmlDoc = '<reports xmlns=""></reports>'
     	Get-Item -Path 'PuppetReports:\*.yaml' | Sort-Object ($_.LastWriteTime) -Descending | % {
     	  $xmlNode = $xmlDoc.CreateElement('report')
     	  $xmlNode.SetAttribute('name',$_.name.ToString())
     	  $xmlNode.SetAttribute('datemodified',($_.LastWriteTime.ToString('dd MMM yyyy HH:mm:ss')))
     	  $xmlNode.innerText = ($_.FullName)
     	  $xmlDoc.reports.AppendChild($xmlNode)
      }
      # Write the xml document to the XAML for databinding
      (Get-WPFControl 'xmlReportList').Document = $xmlDoc
    
      Write-Verbose 'Expanding the report list'
      # Expand the Reports List
      (Get-WPFControl 'expandReportList').IsExpanded = $true   
      # Contract the Report Location
      (Get-WPFControl 'expandReportLocation').IsExpanded = $false
    })
    (Get-WPFControl 'listReports').Add_MouseDoubleClick({
      param($sender,$e)
    
      # Parse the control tree looking for the descendant ListViewItem
    	$originalSource = [System.Windows.DependencyObject]$e.OriginalSource;
      while ( ($originalSource -ne $null) -and ($originalSource.GetType().ToString() -ne 'System.Windows.Controls.ListViewItem') )  {
      	$originalSource = [System.Windows.Media.VisualTreeHelper]::GetParent($originalSource)
      }
      if ($originalSource -eq $null) { return; }
      
      # Get the data context (XMLElement)
      $dc = $originalSource.DataContext
      $reportName = ($dc."#text")
    	
      # Get the template name
      $index = (Get-WPFControl 'comboReportList').selectedIndex
      if ($index -eq -1) {  # No transform has been selected
        [void] ([System.Windows.MessageBox]::Show('Please select a Report Type to use','Error','Ok','Information'))
        return;
      }
      $transformName = (Get-WPFControl 'comboReportList').Items[$index]
      
      # Actually do the conversion
      Write-Verbose "Parsing report $($reportName) with transform $($transformName)..."
      Invoke-ConvertReport -YAMLFilename $reportName -TransformFilename $transformName -TransformParentPath $transformPath
      Write-Verbose "Conversion finished..."
    })
    
    # Populate XAML items
    Write-Verbose "Populating XAML controls..."
    Get-ChildItem -Path $transformPath | % {
      $transfromName = ($_.Name) -replace '.xsl',''
      [void]( (Get-WPFControl 'comboReportList').Items.Add($transfromName) )
    }
    $readMe = $global:ScriptDirectory + '\reportgui.readme.html'
    if (Test-Path -Path $readMe) {
      Write-Verbose "Displaying ReadMe..."
      (Get-WPFControl 'reportBrowser').NavigateToString( ([IO.File]::ReadAllText($readMe) ) )
    }
    
    # Show the GUI
    Write-Verbose "Showing the window..."
    [void]($wpfWindow.ShowDialog())
    Write-Verbose "Cleanup..."
    $wpfWindow.Close()
    $wpfWindow = $null
    
  • tools\module\reportgui\Invoke-ConvertReport.ps1 Show
    Function Invoke-ConvertReport() {
      [cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Low')]
      param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$YAMLFilename
    
        ,[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$TransformFilename
    
        ,[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$TransformParentPath
      )  
      Process {
        $outputDir = ($Env:Temp)
        
        $resultContent = (ConvertFrom-PuppetReport -Report $YAMLFilename -Transform $TransformFilename -TransformDir $TransformParentPath -OutputDir $outputDir -Verbose:($VerbosePreference -eq 'Continue'))
        $fileContent = [IO.File]::ReadAllText($resultContent)
    
        if ($TransformFilename.EndsWith('.stdout')) {
          $fileContent = "<html><body><pre>" + $fileContent + "</pre></body></html>"
        }
        (Get-WPFControl 'reportBrowser').NavigateToString($fileContent)
        Write-Verbose "Removing temporary file $resultContent ..."
        [void](Remove-Item -Path $resultContent -Force -Confirm:$false)
      }
    }
    
  • tools\module\reportgui\Get-WPFControl.ps1 Show
    function Get-WPFControl {
      [cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Low')]
      param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [string]$ControlName
    
        ,[Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [System.Windows.Window]$Window = $Global:wpfWindow
      )  
      Process {
        Write-Output $Window.FindName($ControlName)
      }
    }
    
    
  • tools\module\reportgui\Connect-Location.ps1 Show
    function Open-Location {
      [cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Low')]
      param(
        [Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [string]$Servername
    
        ,[Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [string]$ConnectAs
    
       ,[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$TargetDirectory
    
      )
      Begin {
        [void] (Get-PSDrive 'PuppetReports' -ErrorAction 'SilentlyContinue' | Remove-PSDrive)
      }
      
      Process {
        if (($ServerName -eq '') -or ($ServerName -eq 'localhost'))
        {
          Write-Verbose 'Connecting to local filesystem...'
          [void](New-PSDrive -Name 'PuppetReports' -PSProvider FileSystem -Root $TargetDirectory -Scope Script)
        }
        else
        {
          Write-Verbose "Connecting to $($ServerName) ..."
        }
      }
    }
    
  • tools\module\POSHPuppetReports.psm1 Show
    # Import this modules functions etc.
    Get-ChildItem -Path $PSScriptRoot | Unblock-File
    Get-ChildItem -Path $PSScriptRoot\*.ps1 | ForEach-Object {
      Write-Verbose "Importing $($_.Name)..."
      . ($_.Fullname)
    }
    
  • tools\module\POSHPuppetReports.psd1
  • tools\module\ConvertFrom-PuppetReport.ps1 Show
    function ConvertFrom-PuppetReport {
      [cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Low')]
      param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [string[]]$Report
    
        ,[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string[]]$Transform
    
        ,[Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [string]$TransformDir = ''
    
        ,[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$OutputDir
    
        ,[Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [switch]$OutputXML = $false
    
        ,[Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [switch]$TeeToWriteHost = $false
    
      )
      
      Begin {
        # References
        # Report v3/4 Reference for Puppet 2.7.x and 3.x
        # http://docs.puppetlabs.com/puppet/3/reference/format_report.html
    
        # Fatal Sanity Checks
        #   Can't check for piped output until the Process section
        if ($TransformDir -eq '') { $TransformDir = "$PSScriptRoot\..\transforms" }
        if ($Transform -eq '') { Throw 'No transform was specified'; return; }
        $Transform | % {
          if (!(Test-Path "$TransformDir\$($_).xsl")) { Throw ('Transform file ' + $_ + '.xsl does not exist'); return; }
        }
        if ($OutputDir -ne '') {
          if (!(Test-Path $OutputDir)) { Throw ('Output directory of ' + $OutputDir + ' does not exist'); return; }
        }
      }
      
      Process {
        # Somewhat fatal Sanity Checks
        if ($Report -eq '') { Throw 'No puppet report file was specified'; return; }
        if (!(Test-Path $Report)) { Throw ('Report file ' + $Report + ' does not exist'); return; }
    
        # Process the report and transforms...
        $yamlFile = $Report
    
        try {
          Write-Verbose "Reading $yamlFile ..."
          $objYaml = Get-Yaml -FromFile $yamlFile -ErrorAction Stop
      
          $xmlDoc = [xml]"<report />"
          Write-Verbose "Creating Resource Status Summary XML..."
          Write-ResourceStatusSummary $objYaml $xmlDoc
          
          # TODO: Write out the Metric.Time table to determine the total time
          
          Write-Verbose "Creating Resource Status XML..."
          Write-ResourceStatus $objYaml $xmlDoc
      
          if ($OutputXML) {    
            $filename = Join-Path -Path $OutputDir -ChildPath ( (Get-ChildItem $yamlFile).BaseName + '.xml')
            Write-Verbose "Writing XML to $filename ..."
            $xmlDoc.innerXml | Out-File $filename -Encoding ASCII -Force -Confirm:$false
          }
      
          $Transform | % {
            $transformFile = "$TransformDir\$($_).xsl"
            $filename = Join-Path -Path $OutputDir -ChildPath ( (Get-ChildItem $yamlFile).BaseName + '.' + $_)
            Write-Verbose "Applying transform $transformFile , output to $filename ..."
            [void] (Transform-XML -XMLDocument $xmlDoc -transformFilename $transformFile | Out-File $filename -Force -Confirm:$false )
            
            if ($TeeToWriteHost) {
              # TODO Write out the file content to Write-Host.  Useful if the caller is trapping Stdout
            }
      
            Write-Output $filename
          }
        }
        catch
        {
          Write-Verbose ("ERROR " + $_.ToString())
          Throw $_
          return ;
        }
      }
      
      End {
      }
      
     }
    
  • tools\chocolateyUninstall.ps1 Show
    $packageName = 'poshpuppetreports' # arbitrary name for the package, used in messages
    
    try { 
      $installDir = Join-Path (Join-Path $PSHome "Modules") "POSHPuppetReports"
    
      # Remove the folder from the powershell modules directory
      if (Test-Path  $installDir) {
        [void] (Remove-Item $installDir -Recurse -Confirm:$false -Force -ErrorAction 'Stop')
      }
      else
      {
        Write-Debug "Installation directory doesn't exist"
      }
    
      # Removing shortcuts for the reports into the "Start Menu"
      $shortcutPath = ([Environment]::GetFolderPath('CommonStartMenu')) + '\POSH Puppet Reports\Report GUI.lnk'
      if (Test-Path $shortcutPath) {
        [void] (Remove-Item $shortcutPath -Recurse -Confirm:$false -Force -ErrorAction 'Stop')
      }
    
      Write-ChocolateySuccess "$packageName"
    } catch {
      Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
      throw 
    }
    
    

Virus Scan Results

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Dependencies

This package has no dependencies.

Package Maintainer(s)

Software Author(s)

  • Glenn Sarti

Tags

Release Notes

Full list of changes are available on GitHub; https://github.com/glennsarti/Puppet-Reports-in-Powershell/commits/master

### BUG FIXES:
* Fix - Incorrectly thought the resource status were mutually exclusive however a resource can be counted as both out-of-sync and changed. Removed this logic for the moment until I can come up with a better definition of unchanged
* Fix - The events resource is special as it can come in as null, an array or hashtable. I changed the rendering based on the object type. So now there will always be one 'events' xml node with zero or more 'event' nodes as children. This makes the stylesheet much easier to write and makes more sense in the long run.

### IMPROVEMENTS:
* Added better event output to the stylesheet. Failed resources are now coloured red.
* Added creating a shortcut called "Puppet Report GUI" to the 'Start Menu'. This functionality only works in .Net Framework 4.0 or above for the moment.

Version History

Version Downloads Last updated Status
Posh Puppet Reports 0.9.53 357 Saturday, November 8, 2014 approved
Posh Puppet Reports 0.9.51 305 Saturday, September 27, 2014  
Posh Puppet Reports 0.9.47 246 Sunday, September 14, 2014  

Discussion for the Posh Puppet Reports Package

Ground rules:

  • This discussion is only about Posh Puppet Reports and the Posh Puppet Reports package. If you have feedback for Chocolatey, please contact the google group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or Posh Puppet Reports, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.

comments powered by Disqus
Chocolatey.org uses cookies to enhance the user experience of the site.
Ok