Created
February 18, 2021 16:42
-
-
Save hkarthik7/c1ca2e22063b7a0df7e1096447764358 to your computer and use it in GitHub Desktop.
LogParser script to parse http logs from azure web app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LogParser { | |
# this comes in analysis section; So, need a place to store the files. | |
# We need a separate function to list this. | |
# Intended to run in pipeline | |
$report = @() | |
$files = Get-ChildItem -Path $PWD.Path -Filter "*.log" | |
foreach ($file in $files) { | |
$contents = Get-Content -Path $file.FullName | Select-Object -Skip 2 | |
for ($i = 0; $i -lt $contents.Count; $i++) { | |
$value = $contents[$i].Split() | |
if ($value[-6] -notlike "*20*" -and $value[-6] -notlike "*30*") { | |
$h = [PSCustomObject]@{ | |
"Date Time" = $value[0] + " " + $value[1] | |
"AppName" = $value[2] | |
"Method" = $value[3] | |
"Endpoint" = $value[4] | |
"IP" = $value[8] | |
"StatusCode" = $value[-6] | |
"Host" = $value[-7] | |
} | |
$report += $h | |
} | |
} | |
} | |
return $report | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment