-
Notifications
You must be signed in to change notification settings - Fork 6
/
VSAN-HealthChecks.psm1
213 lines (144 loc) · 5.67 KB
/
VSAN-HealthChecks.psm1
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Function Get-VsanHealthSilentChecks {
<#
.SYNOPSIS
Function : Get-VsanHealthSilentChecks
EMail : [email protected]
Date : 25/04/2018
Info : Display all health checks that have been silenced.
.DESCRIPTION
Display all health checks that have been silenced.
.PARAMETER Cluster
Specify a Cluster object (Get-Cluster)
#>
param(
[parameter(ValueFromPipeline=$True,Mandatory=$True)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl]
$Cluster
)
Process {
$VsanView = Get-VsanView | Where MoRef -eq "VsanVcClusterHealthSystem-vsan-cluster-health-system"
$SilentCheckId = $vsanview.VsanHealthGetVsanClusterSilentChecks($cluster.id)
$vsanview.VsanQueryAllSupportedHealthChecks() | where testid -in $SilentCheckId
}
}
Function Set-VsanHealthSilentChecks {
<#
.SYNOPSIS
Function : Set-VsanHealthSilentChecks
EMail : [email protected]
Date : 25/04/2018
Info : Silence or unsilence a VSAN Health check
.DESCRIPTION
Silencing and unsilencing of VSAN health checks cannot be done in the web ui.
For example, a health check can be in a warning state if no internet connection exists which may be by design.
.PARAMETER Cluster
Specify a Cluster object (Get-Cluster)
.PARAMETER TestId
Id(s) of the health check(s) to silence or unsilence.
This can be found with the Get-VsanHealthChecks function.
.PARAMETER CheckState
Silence of Unsilence. Will be applied to all healthchecks specified in TestId.
#>
param(
[parameter(ValueFromPipeline=$True,Mandatory=$True)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl]
$Cluster,
[parameter(Mandatory=$True)]
[string[]]
$HealthCheckId,
[parameter(Mandatory=$True)]
[validateset("Silence","Unsilence")]
[string[]]
$CheckState
)
Process {
switch ($CheckState) {
"Silence" {$add = $HealthCheckId; $remove = $null}
"Unsilence" {$remove = $HealthCheckId; $add = $null}
}
$VsanView = Get-VsanView | Where MoRef -eq "VsanVcClusterHealthSystem-vsan-cluster-health-system"
$vsanview.VsanHealthSetVsanClusterSilentChecks($cluster.id,$add,$remove) | Out-Null
$SilentCheckId = $vsanview.VsanHealthGetVsanClusterSilentChecks($cluster.id)
$vsanview.VsanQueryAllSupportedHealthChecks() | where testid -in $SilentCheckId
}
}
Function Get-VsanHealthChecks {
<#
.SYNOPSIS
Function : Get-VsanHealthChecks
EMail : [email protected]
Date : 25/04/2018
Info : Display the health state of objects for a VSAN cluster
.DESCRIPTION
Health of checks for a VSAN cluster.
Equivalent in vSphere web client to Cluster>Monitor>VSAN>Health (expanded view)
.PARAMETER Cluster
Specify a Cluster object (Get-Cluster)
.PARAMETER Health
Filter checks by Green, Yellow or Red state.
.PARAMETER DontFetchFromCache
By default if this switch is not set, the Health status will be pulled from the latest cached ones.
If it is set to $true the execution will take more time but will be up to date.
#>
param(
[parameter(ValueFromPipeline=$True,Mandatory=$True)]
$Cluster,
[validateset("Green","Yellow","Red","skipped")]
[string[]]
$Health = @("Green","Yellow","Red","skipped"),
[switch]
$DontFetchFromCache
)
Process {
$VsanView = Get-VsanView | Where MoRef -eq "VsanVcClusterHealthSystem-vsan-cluster-health-system"
$status = $vsanview.VsanQueryVcClusterHealthSummary($cluster.id,$null,$check.testid,$true,"groups",!$DontFetchFromCache,"defaultView")
foreach ($group in $status.Groups) {
$group.grouptests | where TestHealth -in $Health | select TestHealth,@{l="TestId";e={$_.testid.split(".") | select -last 1}},TestName,TestShortDescription,@{l="Group";e={$group.GroupName}}
}
}
}
Function Get-VsanHealthGroups {
<#
.SYNOPSIS
Function : Get-VsanHealthGroups
EMail : [email protected]
Date : 25/04/2018
Info : Display the health state per groups for a VSAN cluster
.DESCRIPTION
Health of group of checks for a VSAN cluster.
Equivalent in vSphere web client to Cluster>Monitor>VSAN>Health (collapsed view)
.PARAMETER Cluster
Specify a Cluster object (Get-Cluster)
.PARAMETER Health
Filter checks by Green, Yellow or Red state.
.PARAMETER DontFetchFromCache
By default if this switch is not set, the Health status will be pulled from the latest cached ones.
If it is set to $true the execution will take more time but will be up to date.
#>
param(
[parameter(ValueFromPipeline=$True,Mandatory=$True)]
$Cluster,
[validateset("Green","Yellow","Red")]
[string[]]
$Health = @("Green","Yellow","Red"),
[switch]
$DontFetchFromCache
)
Process {
$VsanView = Get-VsanView | Where MoRef -eq "VsanVcClusterHealthSystem-vsan-cluster-health-system"
$VsanHealthChecks = $vsanview.VsanQueryVcClusterHealthSummary($cluster.id,$null,$check.testid,$true,"groups",!$DontFetchFromCache,"defaultView")
foreach ($group in $VsanHealthChecks.groups) {
$Green = $group.GroupTests | where testhealth -eq "green"
$Yellow = $group.GroupTests | where testhealth -eq "Yellow"
$Red = $group.GroupTests | where testhealth -eq "Red"
[pscustomobject]@{
GroupId = $Group.GroupId.replace("com.vmware.vsan.health.test.","")
GroupName = $group.GroupName
GroupHealth = $group.GroupHealth
ChecksGreen = $Green.Count
ChecksYellow = $Yellow.Count
ChecksRed = $red.Count
}
}
}
}