From 8f8da682d213525a083031960a8f11fd485adcca Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Thu, 8 Feb 2024 22:08:33 +0100 Subject: [PATCH] adde extractor --- Extractor.ps1 | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Extractor.ps1 diff --git a/Extractor.ps1 b/Extractor.ps1 new file mode 100644 index 0000000..1d9ef52 --- /dev/null +++ b/Extractor.ps1 @@ -0,0 +1,97 @@ +enum State { + Started + Finished + Failed +} + +function GetVMName { + param ( + [string]$Rest + ) + $tokens = $Rest -split "'" + return $tokens[1] +} + +function ConvertDate { + param ( + [string]$DateString + ) + return [DateTime]$DateString +} + +function DeterminState { + param ( + [String]$Rest + ) + if($Rest.IndexOf("Erfolgreiche") -cge 0){ + return 'Finished' + } elseif ($Rest.IndexOf("gestartet") -cge 0) { + return 'Started' + } else { + return 'Failed' + } +} + +function ProduceHashMap { + param ( + $Elements + ) + $HashTable =@{} +foreach ($elem in $Elements){ + $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 +} + +$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