From f09e904fe3e494a8096edb994d0f03c64d64e14a Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Thu, 8 Feb 2024 23:19:09 +0100 Subject: [PATCH] added autoskip for consecutive fails, corrected hash map addressing for pairs, should solve issue #1 --- Extractor.ps1 | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/Extractor.ps1 b/Extractor.ps1 index e8ce673..c2e4f0b 100644 --- a/Extractor.ps1 +++ b/Extractor.ps1 @@ -49,6 +49,14 @@ function ProduceHashMap { $timeStamp if($HashTable.ContainsKey($vmName)){ $array = $HashTable[$vmName] + $lastState=($array[$array.Count-1]).state + Write-Host $lastState + Write-Host $backUpState + if (($lastState -eq 'Failed') -and ($backUpState -eq 'Failed')) { + Write-Host "skipping" + continue + } + Write-Host "continuing" try { $timeStamp = ConvertDate($date) $array += New-Object psobject -Property @{ @@ -58,10 +66,10 @@ function ProduceHashMap { } catch { foreach ($i in (($array.Count-1)..0)){ - Write-Host $array[$i] + #Write-Host $array[$i] if ($array[$i]["state"] -eq 'Started') { - Write-Host "found started" - $timeStamp = $array[$i]['ts'] + #Write-Host "found started" + $timeStamp = ($array[$i]).ts } } $array += New-Object psobject -Property @{ @@ -100,35 +108,4 @@ function ProcessLogToHash { $Path ) ProduceHashMap -Elements $(getElems -Path $Path) -} - -<#$lines = Get-Content -Path .\log.txt | ForEach-Object {$_.SubString($_.IndexOf(":")+1)} -$elems = $lines | Out-String -Stream | Select-String -Pattern "VMware-Maschine" | Out-String -Stream -ProduceHashMap($elems)#> -<#$HashTable =@{} -foreach ($elem in $Elems){ - $indexOfFirst = $elem.IndexOf(" ") - if($indexOfFirst -le 0){ - continue - } - $date = $elem.SubString(0,$elem.IndexOf(" ",($indexOfFirst + 1))) - $timeStamp = ConvertDate($date) - $rest = $elem.Substring($elem.IndexOf(" ",($indexOfFirst + 1))+1) - $vmName = GetVMName($rest) - $backUpState = DeterminState($rest) - - if($HashTable.ContainsKey($vmName)){ - $array = $HashTable[$vmName] - $array += New-Object psobject -Property @{ - state = $backUpState - ts = $timeStamp - } - $HashTable[$vmName]=$array - } else{ - $HashTable += @{$vmName=@(New-Object psobject -Property @{ - state = $backUpState - ts = $timeStamp - })} - } -} -$HashTable#> \ No newline at end of file +} \ No newline at end of file