Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to latest syntax for action groups #466

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions MMA Removal Utility/DeploymentFiles/MMARemovalUtilitySetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1734,13 +1734,24 @@ function Grant-AzTSMMARemediationIdentityAccessOnKeyVault
Write-Host "Creating monitoring alerts..." -ForegroundColor $([Constants]::MessageType.Info)
$EmailReceivers = @()
$SendAlertsToEmailIds | ForEach-Object {
$EmailReceivers += New-AzActionGroupReceiver -Name "Notify_$($_)" -EmailReceiver -EmailAddress $_
$EmailReceivers += New-AzActionGroupEmailReceiverObject -Name "Notify_$($_)" -EmailAddress $_
}

$keyVaultRGName = $ResourceId.Split("/")[4] # ResourceId is in format - /subscriptions/SubIdGuid/resourceGroups/RGName/providers/Microsoft.KeyVault/vaults/KeyVaultName
$alertActionGroupForKV = Set-AzActionGroup -Name 'MMARemovalUtilityActionGroupForKV' -ResourceGroupName $keyVault.ResourceGroupName -ShortName 'MMAKVAlert' -Receiver $EmailReceivers -WarningAction SilentlyContinue

$deploymentName = "MMARemovalenvironmentmonitoringsetupforkv-$([datetime]::Now.ToString("yyyymmddThhmmss"))"

$alertActionGroupForKV = Get-AzActionGroup -Name ‘MMARemovalUtilityActionGroupForKV’ -ResourceGroupName $keyVaultRGName -ErrorAction SilentlyContinue
if ($null -ne $alertActionGroupForKV)
{
Write-Verbose "Updating existing AzTSAlertActionGroupForKV..."
$alertActionGroupForKV = Update-AzActionGroup -Name ‘MMARemovalUtilityActionGroupForKV’ -ResourceGroupName $keyVaultRGName -GroupShortName ‘MMAKVAlert’ -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}
else
{
Write-Verbose "Creating new AzTSAlertActionGroupForKV..."
$alertActionGroupForKV = New-AzActionGroup -Name ‘MMARemovalUtilityActionGroupForKV’ -ResourceGroupName $keyVaultRGName -GroupShortName ‘MMAKVAlert’ -Location "Global" -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}

$deploymentName = "MMARemovalenvironmentmonitoringsetupforkv-$([datetime]::Now.ToString("yyyymmddThhmmss"))"

$alertQuery = [string]::Format([Constants]::UnintendedSecretAccessAlertQuery, $ResourceId, $IdentitySecretUri, $UserAssignedIdentityObjectId)
$deploymentOutput = New-AzResourceGroupDeployment -Name $deploymentName `
Expand Down
35 changes: 27 additions & 8 deletions TemplateFiles/DeploymentFiles/AzTSSetup.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Load all other scripts that are required by this script.
# Load all other scripts that are required by this script.
. "$PSScriptRoot\OnDemandScan.ps1"

# Standard configuration
Expand Down Expand Up @@ -1049,11 +1049,19 @@ function Set-AzTSMonitoringAlert

$EmailReceivers = @()
$SendAlertNotificationToEmailIds | ForEach-Object {
$EmailReceivers += New-AzActionGroupReceiver -Name "Notify_$($_)" -EmailReceiver -EmailAddress $_
$EmailReceivers += New-AzActionGroupEmailReceiverObject -Name "Notify_$($_)" -EmailAddress $_
}

$alertActionGroup = Set-AzActionGroup -Name ‘AzTSAlertActionGroup’ -ResourceGroupName $ScanHostRGName -ShortName ‘AzTSAlert’ -Receiver $EmailReceivers -WarningAction SilentlyContinue

$alertActionGroup = Get-AzActionGroup -Name ‘AzTSAlertActionGroup’ -ResourceGroupName $ScanHostRGName -ErrorAction SilentlyContinue
if ($null -ne $alertActionGroup)
{
Write-Verbose "Updating existing AzTSAlertActiongroup..."
$alertActionGroup = Update-AzActionGroup -Name ‘AzTSAlertActionGroup’ -ResourceGroupName $ScanHostRGName -GroupShortName ‘AzTSAlert’ -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}
else
{
Write-Verbose "Creating new AzTSAlertActiongroup..."
$alertActionGroup = New-AzActionGroup -Name ‘AzTSAlertActionGroup’ -ResourceGroupName $ScanHostRGName -GroupShortName ‘AzTSAlert’ -Location "Global" -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}

if($DeploymentResult.Outputs.ContainsKey('logAnalyticsResourceId') -and $DeploymentResult.Outputs.ContainsKey('applicationInsightsId'))
{
Expand Down Expand Up @@ -2098,11 +2106,22 @@ function Grant-AzSKAccessOnKeyVaultToUserAssignedIdentity
Write-Host "Creating monitoring alerts..." -ForegroundColor $([Constants]::MessageType.Info)
$EmailReceivers = @()
$SendAlertsToEmailIds | ForEach-Object {
$EmailReceivers += New-AzActionGroupReceiver -Name "Notify_$($_)" -EmailReceiver -EmailAddress $_
$EmailReceivers += New-AzActionGroupEmailReceiverObject -Name "Notify_$($_)" -EmailAddress $_
}

$keyVaultRGName = $ResourceId.Split("/")[4] # ResourceId is in format - /subscriptions/SubIdGuid/resourceGroups/RGName/providers/Microsoft.KeyVault/vaults/KeyVaultName
$alertActionGroupForKV = Set-AzActionGroup -Name ‘AzTSAlertActionGroupForKV’ -ResourceGroupName $keyVaultRGName -ShortName ‘AzTSKVAlert’ -Receiver $EmailReceivers -WarningAction SilentlyContinue

$alertActionGroupForKV = Get-AzActionGroup -Name ‘AzTSAlertActionGroupForKV’ -ResourceGroupName $keyVaultRGName -ErrorAction SilentlyContinue
if ($null -ne $alertActionGroupForKV)
{
Write-Verbose "Updating existing AzTSAlertActionGroupForKV..."
$alertActionGroupForKV = Update-AzActionGroup -Name ‘AzTSAlertActionGroupForKV’ -ResourceGroupName $keyVaultRGName -GroupShortName ‘AzTSKVAlert’ -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}
else
{
Write-Verbose "Creating new AzTSAlertActionGroupForKV..."
$alertActionGroupForKV = New-AzActionGroup -Name ‘AzTSAlertActionGroupForKV’ -ResourceGroupName $keyVaultRGName -GroupShortName ‘AzTSKVAlert’ -Location "Global" -EmailReceiver $EmailReceivers -WarningAction SilentlyContinue
}

$deploymentName = "AzTSenvironmentmonitoringsetupforkv-$([datetime]::Now.ToString("yyyymmddThhmmss"))"

Expand Down Expand Up @@ -2943,4 +2962,4 @@ function Enable-ByDesignExceptionFeature
return;
}
}
}
}