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

Update Policy File names #300

Merged
merged 2 commits into from
Aug 2, 2024
Merged
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
6 changes: 3 additions & 3 deletions tooling/generate-templates/generate-policies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ process {
# Process each alert in the yaml file
foreach ($alert in $alertJsonObject) {
$policyPathName = $_.FullName -replace "alerts.yaml", ""
$policyFileName = "$($alert.properties.metricName)" -replace "[^a-zA-Z_]", ""
$policyFileName = $alert.name -replace "[^a-zA-Z0-9-]", ""
$policyDirectory = "$($policyPathName)templates\policy"
# Check if the alert has a deployment template and has a deployment tag of "alz"
if ((Test-Path -Path "$($policyPathName)$($alert.deployments.template)") -and $alert.deployments.tags -eq "alz") {
if (-not (Test-Path -Path $policyDirectory)) {
New-Item -ItemType Directory -Path $policyDirectory -Force
}
if ($policyFileName -eq "") {
$policyFileName = $alert.name -replace "[^a-zA-Z_]", ""
$policyFileName = $alert.name -replace "[^a-zA-Z0-9-]", ""
}
# Copy the deployment template to the policy directory
Copy-Item -Path "$($policyPathName)$($alert.deployments.template)" -Destination "$($policyPathName)templates\policy\$($policyFileName)_$($alert.guid).json"
Expand Down Expand Up @@ -102,7 +102,7 @@ process {
New-Item -ItemType Directory -Path $policyDirectory -Force
}
if ($policyFileName -eq "") {
$policyFileName = $alert.name -replace "[^a-zA-Z_]", ""
$policyFileName = $alert.name -replace "[^a-zA-Z0-9-]", ""
}
# Write the policy template to a file
Out-File -FilePath "$($policyPathName)templates\policy\$($policyFileName)_$($alert.guid).json" -InputObject $alertTemplate
Expand Down
Loading