NewRelicPS.Configuration.Update.psm1
Using module '.\NewRelicPS.Configuration.GetFromYAML.psm1' Using module '.\NewRelicPS.Configuration.Channel.psm1' Using module '.\NewRelicPS.Configuration.Policy.psm1' Using module '.\NewRelicPS.Configuration.NRQLCondition.psm1' Using module '.\NewRelicPS.Configuration.SyntheticLocationCondition.psm1' Using module '.\NewRelicPS.Configuration.SyntheticMonitor.psm1' Using module '.\NewRelicPS.Configuration.SyntheticSecureCredential.psm1' <# .Synopsis Idempotently applies New Relic configurations to an account .Description Provide the location to the yaml file which declares the configuration and this CMDLet will idempotently apply those New Relic configurations. View the module's readme for more information on building the yaml configuration file. .Example Update-NRConfig -AccountID '1234567' -AdminAPIKey $MyAdminKey -PersonalAPIKey $MyPersonalKey -FilePath C:\Path\To\config.yml Uses New Relic APIs to idempotently update the New Relic configuration to match what is defined in the file provided. Any existing supported resources that are not defined will be removed. For a list of supported resources and more information on building the yaml configuration file view the module's readme. .Example Update-NRConfig -AccountID '1234567' -AdminAPIKey $MyAdminKey -PersonalAPIKey $MyPersonalKey -FilePath C:\Path\To\config.yml -Parameters $Parameters This command passes a hash table of custom parameters to the configuration file. This is done so that secrets are not stored in plain text. .Parameter AccountId The New Relic account Id where resources will be configured. .Parameter AdminAPIKey Must be an admin user's API Key, not an account-level REST API Key. See more here: https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys .Parameter ConfigurationFilePath Can be the full path or a relative path to the YAML configuration file. .Parameter Parameters A hash table of parameters that can be passed into the configuration file to be used in place of secrets. Parameters are wrapped with ${} in the configuration file (i.e. ${MySecret}). .Parameter PersonalAPIKey Must be a personal API Key, not an account-level REST API Key. See more here: https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys #> function Update-NRConfiguration { [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", '', Justification = "All CMDLets being called have ShouldProcess in place and the preference is passed to them." )] [CMDLetBinding(SupportsShouldProcess=$true)] Param ( [Parameter (Mandatory = $true)] [string] $AccountId, [Parameter (Mandatory = $true)] [string] $AdminAPIKey, [Parameter (Mandatory = $true)] [string] $ConfigurationFilePath, [Parameter (Mandatory = $true)] [string] $PersonalAPIKey, [hashtable] $Parameters = @{}, [switch] $Force ) Write-Verbose "Getting desired state configuration from $ConfigurationFilePath" $config = Get-NRConfigFromYAML -ConfigurationFilePath $ConfigurationFilePath -Parameters $Parameters # Exit if the configuration is blank If (-Not $Config) { Write-Warning "The file at $ConfigurationFilePath does not contain a configuration, no actions performed. To remove all supported resources, add any item to the yml configuration and specify the Force parameter." Return } Foreach ($key in $config.keys) { Write-Verbose "Defined $key count: $($config[$key].count)" } # Configure the environment If ($Force) { Write-Warning "Force has been specified, removing all supported resources types without a declaration. Hope you know what you are doing!" } # Synthetic Secure Credentials should be processed before Synthetic Monitors If ($config.SyntheticSecureCredentials -or $Force) { Write-Verbose 'Updating Synthetic Secure Credentials' Set-NRSyntheticSecureCredentialConfiguration -AdminAPIKey $AdminAPIKey -DefinedSyntheticSecureCredentials $config.SyntheticSecureCredentials -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Updating Secure Credentials' } # Synthetic Monitors must be processed before Synthetic conditions If ($config.SyntheticMonitors -or $Force) { Write-Verbose 'Updating Synthetic Monitors' Set-NRSyntheticLocationMonitorConfiguration -AdminAPIKey $AdminAPIKey -DefinedSyntheticMonitors $config.SyntheticMonitors -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Updating Synthetic Monitors' } If ($config.AlertPolicies -or $Force) { Write-Verbose 'Updating Policy Configuration' Set-NRPolicyConfiguration -APIKey $AdminAPIKey -DefinedPolicies $config.AlertPolicies -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Policy Configuration' Write-Verbose 'Updating NRQL Condition Configurations' Set-NRQLConditionConfiguration -AdminAPIKey $AdminAPIKey -PersonalAPIKey $PersonalAPIKey -DefinedPolicies $config.AlertPolicies -AccountId $AccountId -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finshed Updating NRQL Condition Configurations' Write-Verbose 'Updating Synthetic Condition Configuration' Set-NRSyntheticLocationConditionConfiguration -AdminAPIKey $AdminAPIKey -DefinedPolicies $config.AlertPolicies -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Updating Synthetic Condition Configuration' } If ($config.NotificationChannels -or $Force) { Write-Verbose 'Updating Notification Channel Configuration' Set-NRChannelConfiguration -APIKey $AdminAPIKey -DefinedChannels $config.NotificationChannels -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Updating Channel Configuration' } # Channel policy links need to be processed following policies and channels If ($config.AlertPolicies -or $Force) { Write-Verbose 'Updating Channel-Policy links' Set-NRChannelPolicyLink -APIKey $AdminAPIKey -DefinedPolicies $config.AlertPolicies -Verbose:$VerbosePreference -WhatIf:$WhatIfPreference Write-Verbose 'Finished Updating Channel-Policy links' } Write-Output 'Configuration Update Complete.' } |