Skip to content
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [1.1.6] - 2026-03-04

### Changed

- Export-SplunkData: File generation in transient execution environments (e.g. Azure Automation runbooks) is susceptible to intermittent I/O failures. Added retry logic to handle cases where output files are not written due to short-lived environment instability.

## [1.1.5] - 2024-05-23

### Changed
Expand Down
40 changes: 32 additions & 8 deletions src/UofISplunkCloud/functions/public/Export-SplunkData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ function Export-SplunkData {
}
$Results = Invoke-RestMethod @IVRSplat

$Filename = "SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss)"

# Files are sometimes not generated correctly due to small transient issues in Azure Automation fabric infrastructure
function Write-WithRetry {
param(
[scriptblock]$WriteAction,
[string]$FilePath
)
for ($i = 1; $i -le 3; $i++) {
& $WriteAction
if (Test-Path -Path $FilePath) { return }
Start-Sleep -Seconds 2
}
throw "Failed to write $($FilePath) after 3 attempts."
}

#Return results
If(!($Results)){
Write-Output -InputObject "No results"
Expand All @@ -184,20 +200,28 @@ function Export-SplunkData {
$Results
}
ElseIf($OutputMode -eq 'csv'){
$Results | Out-File -Path ".\SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).csv"
Write-Output -InputObject "SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).csv"
Write-WithRetry -FilePath ".\$($Filename).csv" -WriteAction {
$Results | Out-File -Path ".\$($Filename).csv"
}
Write-Output -InputObject "$($Filename).csv"
}
ElseIf($OutputMode -like 'json*'){
$Results | ConverTo-Json -Depth 10 | Out-File -Path ".\SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).json"
Write-Output -InputObject "SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).json"
Write-WithRetry -FilePath ".\$($Filename).json" -WriteAction {
$Results | ConvertTo-Json -Depth 10 | Out-File -Path ".\$($Filename).json"
}
Write-Output -InputObject "$($Filename).json"
}
ElseIf($OutputMode -eq 'xml'){
$Results | Out-File -Path ".\SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).xml"
Write-Output -InputObject "SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss).xml"
Write-WithRetry -FilePath ".\$($Filename).xml" -WriteAction {
$Results | Out-File -Path ".\$($Filename).xml"
}
Write-Output -InputObject "$($Filename).xml"
}
else{
$Results | Out-File -Path ".\SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss)"
Write-Output -InputObject "SearchResults_$(Get-Date -Format yyyyMMdd-HHmmss)"
Write-WithRetry -FilePath ".\$($Filename)" -WriteAction {
$Results | Out-File -Path ".\$($Filename)"
}
Write-Output -InputObject "$($Filename)"
}
}
}
Expand Down