2024-02-08 22:08:33 +01:00
|
|
|
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 =@{}
|
2024-02-08 22:54:01 +01:00
|
|
|
foreach ($elem in $Elements){
|
|
|
|
$indexOfFirst = $elem.IndexOf(" ")
|
|
|
|
if($indexOfFirst -le 0){
|
|
|
|
continue
|
2024-02-08 22:08:33 +01:00
|
|
|
}
|
2024-02-08 22:54:01 +01:00
|
|
|
$date = $elem.SubString(0,$elem.IndexOf(" ",($indexOfFirst + 1)))
|
|
|
|
$rest = $elem.Substring($elem.IndexOf(" ",($indexOfFirst + 1))+1)
|
|
|
|
$vmName = GetVMName($rest)
|
|
|
|
$backUpState = DeterminState($rest)
|
|
|
|
$timeStamp
|
|
|
|
if($HashTable.ContainsKey($vmName)){
|
|
|
|
$array = $HashTable[$vmName]
|
2024-02-08 23:19:09 +01:00
|
|
|
$lastState=($array[$array.Count-1]).state
|
2024-02-08 23:23:36 +01:00
|
|
|
#Write-Host $lastState
|
|
|
|
#Write-Host $backUpState
|
2024-02-08 23:34:31 +01:00
|
|
|
if (($lastState -eq $backUpState) -or ($backUpState -eq 'Finished' -and $lastState -ne 'Started') -or ($backUpState -eq 'Failed' -and $lastState -ne 'Started')) {
|
2024-02-08 23:23:36 +01:00
|
|
|
#Write-Host "skipping"
|
2024-02-08 23:19:09 +01:00
|
|
|
continue
|
|
|
|
}
|
2024-02-08 23:23:36 +01:00
|
|
|
#Write-Host "continuing"
|
2024-02-08 22:54:01 +01:00
|
|
|
try {
|
|
|
|
$timeStamp = ConvertDate($date)
|
|
|
|
$array += New-Object psobject -Property @{
|
|
|
|
state = $backUpState
|
|
|
|
ts = $timeStamp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
2024-02-08 23:28:05 +01:00
|
|
|
$timeStamp = ($array[$array.Count-1]).ts
|
2024-02-08 22:54:01 +01:00
|
|
|
$array += New-Object psobject -Property @{
|
|
|
|
state = $backUpState
|
|
|
|
ts = $timeStamp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$HashTable[$vmName]=$array
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$timeStamp = ConvertDate($date)
|
|
|
|
$HashTable += @{$vmName=@(New-Object psobject -Property @{
|
|
|
|
state = $backUpState
|
|
|
|
ts = $timeStamp
|
|
|
|
})}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
<#Do nothing as key is empty and failed state#>
|
|
|
|
}
|
|
|
|
}
|
2024-02-08 22:08:33 +01:00
|
|
|
}
|
2024-02-08 22:54:01 +01:00
|
|
|
return $HashTable
|
2024-02-08 22:08:33 +01:00
|
|
|
}
|
|
|
|
|
2024-02-08 22:20:38 +01:00
|
|
|
function getElems {
|
|
|
|
param (
|
|
|
|
$Path
|
|
|
|
)
|
|
|
|
$lines = Get-Content -Path $Path | ForEach-Object {$_.SubString($_.IndexOf(":")+1)}
|
|
|
|
$elems = $lines | Out-String -Stream | Select-String -Pattern "VMware-Maschine" | Out-String -Stream
|
|
|
|
return $elems
|
|
|
|
}
|
|
|
|
|
|
|
|
function ProcessLogToHash {
|
|
|
|
param (
|
|
|
|
$Path
|
|
|
|
)
|
|
|
|
ProduceHashMap -Elements $(getElems -Path $Path)
|
2024-02-08 23:54:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function buildIntervals {
|
|
|
|
param (
|
|
|
|
$hash
|
|
|
|
)
|
|
|
|
$array = @()
|
|
|
|
foreach ($key in $hash.Keys){
|
2024-02-08 23:56:56 +01:00
|
|
|
#Write-Host $key
|
2024-02-08 23:54:24 +01:00
|
|
|
$list = $hash.$key
|
2024-02-08 23:56:56 +01:00
|
|
|
#Write-Host $list
|
2024-02-08 23:54:24 +01:00
|
|
|
$lastState = $null
|
|
|
|
$lastTS = $null
|
|
|
|
foreach ($elem in $list){
|
2024-02-08 23:56:56 +01:00
|
|
|
#Write-Host $elem
|
2024-02-08 23:54:24 +01:00
|
|
|
if (($elem.state -eq 'Started') -and ($null -eq $lastState)) {
|
|
|
|
$lastState=$elem.state
|
|
|
|
$lastTS=$elem.ts
|
|
|
|
}
|
|
|
|
if (($elem.state -ne 'Started') -and ($lastState -eq 'Started')) {
|
|
|
|
$array += @(New-Object psobject -Property @{
|
|
|
|
begining=$lastTS
|
|
|
|
ending=$elem.ts
|
|
|
|
state=$elem.state
|
|
|
|
vm=$key
|
|
|
|
})
|
|
|
|
$lastState=$null
|
|
|
|
$lastTS=$null
|
|
|
|
}
|
2024-02-08 23:56:56 +01:00
|
|
|
#Write-Host "$array"
|
2024-02-08 23:54:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $array
|
2024-02-09 00:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function PrintAffected {
|
|
|
|
param (
|
|
|
|
$listOfIntervals,
|
|
|
|
[datetime]$point
|
|
|
|
)
|
|
|
|
foreach ($elem in $listOfIntervals){
|
|
|
|
if ($point -le $elem.ending -and $point -ge $elem.begining){
|
|
|
|
Write-Host "$point : $($elem.vm) $($elem.state)"
|
|
|
|
}
|
|
|
|
}
|
2024-02-08 23:19:09 +01:00
|
|
|
}
|