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

Add DisableIncidentCreation parameter and test case #33

Merged
merged 3 commits into from
Mar 26, 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
2 changes: 1 addition & 1 deletion src/SentinelARConverter.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'SentinelARConverter.psm1'

# Version number of this module.
ModuleVersion = '2.2.3'
ModuleVersion = '2.2.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
17 changes: 16 additions & 1 deletion src/public/Convert-SentinelARYamlToArm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Set the startTimeUtc property of the ARM template. Default is empty
To successfully deploy the ARM template the startTimeUtc property must be set to a future date.
Start time must be between 10 minutes and 30 days from now. This is not validated by the cmdlet.

.PARAMETER DisableIncidentCreation
If set, the incidentCreation property of the ARM template will be set to false. Default is to keep the value from the YAML file.

.EXAMPLE
Convert-SentinelARYamlToArm -Filename "C:\Temp\MyRule.yaml" -OutFile "C:\Temp\MyRule.json"

Expand Down Expand Up @@ -101,7 +104,10 @@ function Convert-SentinelARYamlToArm {
[string]$Severity,

[Parameter()]
[datetime]$StartRunningAt
[datetime]$StartRunningAt,

[Parameter()]
[switch]$DisableIncidentCreation
)

begin {
Expand Down Expand Up @@ -303,6 +309,15 @@ function Convert-SentinelARYamlToArm {
Write-Warning "StartRunningAt parameter is only supported for scheduled rules. Ignoring parameter."
}

# Disable incident creation if specified
if ($DisableIncidentCreation) {
# Remove existing createIncident property
if ("createIncident" -in $ARMTemplate.incidentConfiguration.Keys) {
$ARMTemplate.incidentConfiguration.Remove("createIncident")
}
$ARMTemplate.incidentConfiguration.Add("createIncident", $false)
}

# Convert hashtable to JSON
$JSON = $ARMTemplate | ConvertTo-Json -Depth 99
# Use ISO8601 format for timespan values
Expand Down
18 changes: 18 additions & 0 deletions tests/Convert-SentinelARYamlToArm.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,24 @@ Describe "Convert-SentinelARYamlToArm" {
}
}

Context "Scheduled with disabled incident creation" {
BeforeAll {
Copy-Item -Path $exampleScheduledFilePath -Destination "TestDrive:/Scheduled.yaml" -Force
Convert-SentinelARYamlToArm -Filename "TestDrive:/Scheduled.yaml" -OutFile "TestDrive:/Scheduled.json" -DisableIncidentCreation
$armTemplate = Get-Content -Path "TestDrive:/Scheduled.json" -Raw | ConvertFrom-Json
}

AfterEach {
if ( -not $RetainTestFiles) {
Remove-Item -Path "TestDrive:/*" -Include *.json -Force
}
}

It "Should have the incident creation disabled" {
$armTemplate.resources[0].properties.incidentConfiguration.createIncident | Should -Be $false
}
}

AfterAll {
Remove-Module SentinelARConverter -Force
}
Expand Down
Loading