-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dashboard.ps1
164 lines (142 loc) · 6.11 KB
/
Dashboard.ps1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# under construction
# Functions
function Dashboard-Vester {
<#
.SYNOPSIS
.EXAMPLE
PS> New-AdvancedFunction -Param1 MYPARAM
This example does something to this and that.
.PARAMETER Param1
This param does this thing.
.PARAMETER
.PARAMETER
.PARAMETER
#>
[CmdletBinding()]
param (
[string]$Param1
)
# Run Invoke-Vester
[Array]$Vesters = @()
[Array]$DateTimes = @()
$i = 0
foreach ($VC in $VCs) {
if (!$creds) {$creds = Get-Credential }
# try catch
Connect-VIServer -Server $VC -Credential $creds
# For testing, with limited Scope
# $Vester = @(Invoke-Vester -Config $Configs[$i] -Test (Get-VesterTest -Scope vCenter) -PassThru)
$Vester = Invoke-Vester -Config $Configs[$i] -PassThru
$DateTimes += Get-Date
Disconnect-VIServer -Server $VC -Force -Confirm:$false
# Last line
#$Vesters += $vester
$Vesters = $Vesters,$Vester
$i++
}
# Process Data
$VCColors = @()
[Array]$GridDatas = @()
foreach ($Vester in $Vesters) {
# Dashboard Color
if ($Vester.FailedCount -ne 0) {
$VCColor = 'yellow'
} else {
$VCColor = 'green'
}
$VCColors += $VCColor
# Create DataGrid
$GridData = $Vester.TestResult | Where-Object {$_.Passed -eq $false} |
ForEach-Object {
[pscustomobject]@{
# Split Name field
Type = $_.Name.Split(" ")[0]
Name = $_.Name.Split(" ")[1]
Test = $_.Name.Split("-")[1].Substring(1)
# Convert Errorcode to String, Split on linebreak and remove first part
Desired = $_.ErrorRecord.ToString().Split([Environment]::NewLine)[0].Substring(11)
Actual = $_.ErrorRecord.ToString().Split([Environment]::NewLine)[1].Substring(11)
Synopsis = $_.ErrorRecord.ToString().Split([Environment]::NewLine)[2].Substring(11)
}
}
#$GridDatas += @($GridData)
$GridDatas = $GridDatas,$GridData
}
# Stop old dashboard
Get-UDDashboard -Name 'VesterDashboard' | Stop-UDDashboard
# Create New Dashboard
$FontColor = 'Black'
# Footer
$NavBarLinks = @((New-UDLink -Text "About" -Url "https://paulgrevink.wordpress.com/2018/11/29/about-configuration-drift-pester-and-vester/" -Icon question_circle),
(New-UDLink -Text "More info" -Url "https://paulgrevink.wordpress.com/2018/11/29/about-configuration-drift-pester-and-vester/" -Icon book))
$Footer = New-UDFooter -Copyright "Copyright: Paul Grevink"
# Index
$i = 0
$HomePage = New-UDPage -Name "Home" -Icon home -DefaultHomePage -Content {
New-UDRow {
New-UDColumn -Size 12 {
New-UDLayout -Columns 2 -Content {
New-UDCard -Title $VCs[$i] -Content {
New-UDParagraph -Text "Config: $($Configs[$i])" -Color $FontColor
New-UDParagraph -Text "=== Test Results of $($DateTimes[$i]) ===" -Color $FontColor
New-UDParagraph -Text "Total : $($Vesters[$i].TotalCount)" -Color 'Black'
New-UDParagraph -Text "Passed : $($Vesters[$i].PassedCount)" -Color 'Green'
New-UDParagraph -Text "Failed : $($Vesters[$i].FailedCount)" -Color 'Red'
New-UDParagraph -Text "Skipped : $($Vesters[$i].SkippedCount)" -Color 'Black'
New-UDParagraph -Text "Pending : $($Vesters[$i].PendingCount)" -Color 'Black'
} -FontColor $FontColor -BackgroundColor $VCColors[$i] -Links (New-UDLink -Text "See Errors" -Url $VCs[$i] -Icon book)
$i ++
New-UDCard -Title $($VCs[$i]) -Content {
New-UDParagraph -Text "Config: $($Configs[$i])" -Color $FontColor
New-UDParagraph -Text "=== Test Results of $($DateTimes[$i]) ===" -Color $FontColor
New-UDParagraph -Text "Total : $($Vesters[$i].TotalCount)" -Color 'Black'
New-UDParagraph -Text "Passed : $($Vesters[$i].PassedCount)" -Color 'Green'
New-UDParagraph -Text "Failed : $($Vesters[$i].FailedCount)" -Color 'Red'
New-UDParagraph -Text "Skipped : $($Vesters[$i].SkippedCount)" -Color 'Black'
New-UDParagraph -Text "Pending : $($Vesters[$i].PendingCount)" -Color 'Black'
} -FontColor $FontColor -BackgroundColor $VCColors[$i] -Links (New-UDLink -Text "See Errors" -Url $VCs[$i] -Icon book)
$i++
New-UDCard
}
}
}
}
# Index
$i = 0
$VC0 = New-UDPage -Name $VCs[$i] -Icon grav -Content {
New-UDRow {
New-UDColumn -Size 12 {
New-UDGrid -Title "Errors $($VCs[$i])" -Headers @("Type", "Name", "Test", "Desired", "Actual", "Synopsis") -Properties @("Type", "Name", "Test", "Desired", "Actual", "Synopsis") -Endpoint {
$GridDatas[$i] | Out-UDGridData
} -FontColor "black"
}
}
}
$i ++
$VC1 = New-UDPage -Name $VCs[$i] -Icon grav -Content {
New-UDRow {
New-UDColumn -Size 12 {
New-UDGrid -Title "Errors $($VCs[$i])" -Headers @("Type", "Name", "Test", "Desired", "Actual", "Synopsis") -Properties @("Type", "Name", "Test", "Desired", "Actual", "Synopsis") -Endpoint {
$GridDatas[$i] | Out-UDGridData
} -FontColor "black"
}
}
}
$i ++
#Next page
#Start presenting Dashboard
Start-UDDashboard -Content {
New-UDDashboard -NavbarLinks $NavBarLinks -Title "Vester Dashboard" -NavBarColor 'Orange' -NavBarFontColor 'Ẃhite' -BackgroundColor "#FF333333" -FontColor "#FFFFFFF" -Pages @(
$HomePage,
$VC0,
$VC1
) -Footer $Footer
} -Port 10000 -Name 'VesterDashboard'
Write-Host "VesterCount" $Vesters.count
} # eof function
# Main
$VCs = @("vc06.virtual.local",
"192.168.100.106")
$Configs = @("C:\Program Files\WindowsPowerShell\Modules\Vester\1.2.0\Configs\Config.json",
"C:\Program Files\WindowsPowerShell\Modules\Vester\1.2.0\Configs\Config2.json")
Dashboard-Vester