NewRelic.Configuration.psm1


<#
.Synopsis
  Retrieves a New Relic configuration from YAML
.Description
  Retrieves a New Relic configuration from YAML
.Example
  Get-NRConfigFromYAML -FilePath 'c:\path\to\myfile.yml'
  Retrieves a desired New Relic configuration state from YAML as an array of configuraiton objects.
.Parameter FilePath
  Can be the full path or a relative path to the YAML configuration file
#>

function Get-NRConfigFromYAML {
  [CMDLetBinding()]
  Param (
    [Parameter (Mandatory = $true)]
    [string]$ConfigurationFilePath,
    [hashtable]$Parameters = @{}
  )
  $file = Get-Content $ConfigurationFilePath
  Foreach ($line in $file) {
    If ($line -match '\${(.*)}') {
      $line = $line.replace($matches[0], ($Parameters[$matches[1]]))
    }
    $content += "`n" + $line
  }
  Return ConvertFrom-Yaml $content
}

<#
.Synopsis
    Gets the configuration used by the New Relic .NET Agent from its config file.
.Description
    Gets the configuration used by the New Relic .NET Agent from its config file (newrelic.config) as XML.
.Example
    Get-NRDotNetAgentConfig
    Gets the current configuration from the xml config file.
#>

Function Get-NRDotNetAgentConfig {
  [CMDLetBinding()]
  [OutputType([System.Xml.XmlDocument])]
  Param (
  )

  $configFile = "$env:ALLUSERSPROFILE\New Relic\.NET Agent\newrelic.config"

  if (!(Test-Path $configFile)) {
    Throw "New Relic .NET Agent Config file not found at $configFile. Make sure the agent is installed!"
  }

  return [xml](Get-Content $configFile)
}