-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch-job-logs.ps1
More file actions
58 lines (49 loc) · 2.37 KB
/
search-job-logs.ps1
File metadata and controls
58 lines (49 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
param([string]$JobId = "85605b87-b4fb-f011-8407-7c1e520aa4df")
Write-Host "=== Searching logs for Job ID: $JobId ===" -ForegroundColor Cyan
# Download logs
$null = az webapp log download --name spe-api-dev-67e2xz --resource-group spe-infrastructure-westus2 --log-file search-logs.zip 2>&1
# Extract eventlog.xml
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::OpenRead((Resolve-Path "search-logs.zip").Path)
$entry = $zip.Entries | Where-Object { $_.FullName -eq "LogFiles/eventlog.xml" }
if ($entry) {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, "search-eventlog.xml", $true)
}
$zip.Dispose()
if (Test-Path "search-eventlog.xml") {
$content = Get-Content "search-eventlog.xml" -Raw
# Search for job ID
if ($content -match $JobId) {
Write-Host "Found job ID in logs!" -ForegroundColor Green
# Extract relevant sections
$lines = $content -split "`n"
$relevantLines = $lines | Where-Object { $_ -match $JobId }
Write-Host "`nRelevant log entries:" -ForegroundColor Yellow
foreach ($line in $relevantLines | Select-Object -First 10) {
# Extract the data portion
if ($line -match '<Data>(.*?)</Data>') {
Write-Host $matches[1] -ForegroundColor Gray
Write-Host ""
}
}
} else {
Write-Host "Job ID NOT found in event logs" -ForegroundColor Red
Write-Host "This suggests the SaveEmail API call may have failed before logging" -ForegroundColor Yellow
}
# Search for recent "Upload finalization" or "Service Bus" messages
Write-Host "`n=== Recent Service Bus Activity ===" -ForegroundColor Cyan
if ($content -match "Upload finalization|ServiceBus|queue.*office") {
$sbLines = $lines | Where-Object { $_ -match "Upload finalization|ServiceBus|queue.*office" } | Select-Object -Last 5
foreach ($line in $sbLines) {
if ($line -match '<Data>(.*?)</Data>') {
Write-Host $matches[1] -ForegroundColor Gray
}
}
} else {
Write-Host "No Service Bus activity found in recent logs" -ForegroundColor Red
}
Remove-Item "search-eventlog.xml" -ErrorAction SilentlyContinue
Remove-Item "search-logs.zip" -ErrorAction SilentlyContinue
} else {
Write-Host "Could not extract event log" -ForegroundColor Red
}