53 lines
1.5 KiB
PowerShell
53 lines
1.5 KiB
PowerShell
function Add-OverflowCustomAttribute {
|
|
<#
|
|
.SYNOPSIS
|
|
Adds Overflow: true or false as custom node attributes in newrelic-infra.yml
|
|
|
|
.DESCRIPTION
|
|
If a server is an overflow server, Perf wants to know via new relic custom attribute.
|
|
This affects the server that this function is being run on.
|
|
|
|
.PARAMETER IsOverflow
|
|
IsOverflow sets the value to true or false
|
|
|
|
.EXAMPLE
|
|
Add-OverflowCustomAttribute -IsOverflow $true
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory = $true)]
|
|
[bool]$IsOverflow
|
|
)
|
|
|
|
$logLead = Get-LogLeadName
|
|
|
|
$isDirty = $false
|
|
Import-Module powershell-yaml
|
|
|
|
$Path = Get-NewRelicYamlPath
|
|
# Returning/stopping exactly where the error is
|
|
if (Test-StringIsNullOrWhitespace $Path) { return }
|
|
|
|
$fileContent = Get-Content $Path -Raw
|
|
$yaml = ConvertFrom-Yaml -Yaml $fileContent -Ordered
|
|
|
|
# This will add the custom_attribute field if it isn't already present
|
|
# Otherwise it will update the Overflow value
|
|
if (!($yaml.custom_attributes)) {
|
|
$yaml.custom_attributes = @{Overflow = $IsOverflow }
|
|
$isDirty = $true
|
|
} elseif ($yaml.custom_attributes.Overflow -ne $IsOverflow) {
|
|
$yaml.custom_attributes.Overflow = $IsOverflow
|
|
$isDirty = $true
|
|
}
|
|
|
|
if ($isDirty) {
|
|
Write-Host "$loglead : Setting Overflow Attribute to $IsOverflow"
|
|
Write-Host "$loglead : Saving to path: $Path"
|
|
ConvertTo-Yaml -Data $yaml -Outfile $Path -Force
|
|
} else {
|
|
Write-Host "$loglead : Nothing to change in the config file"
|
|
}
|
|
|
|
} |