Skip to content

Commit 7d156f6

Browse files
committed
Adds new Hyper-V data provider
1 parent f028ade commit 7d156f6

File tree

3 files changed

+120
-11
lines changed

3 files changed

+120
-11
lines changed

doc/100-General/10-Changelog.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2929
* [#544](https://github.com/Icinga/icinga-powershell-framework/issues/544) Adds support to configure the Icinga Director JSON string for registering hosts via self-service API
3030
* [#572](https://github.com/Icinga/icinga-powershell-framework/issues/572) Adds support to write the name of the repository synced/created into the local `ifw.repo.json` file
3131
* [#573](https://github.com/Icinga/icinga-powershell-framework/issues/573) Adds support to run command `icinga` with new argument `-NoNewInstance`, to use `-RebuildCache` as example to update the current PowerShell instance with all applied changes
32+
* [#613](https://github.com/Icinga/icinga-powershell-framework/pull/613) Adds a `-Version` parameter to the `Update-Icinga` command, to be able to update a component to a specified version [@log1-c]
3233
* [#619](https://github.com/Icinga/icinga-powershell-framework/pull/619) Adds feature to securely read enum provider values with new function `Get-IcingaProviderEnumData`
3334
* [#623](https://github.com/Icinga/icinga-powershell-framework/issues/623) Adds support to provide the Icinga service user written as `user@domain`
3435
* [#633](https://github.com/Icinga/icinga-powershell-framework/pull/633) Adds support for Icinga 2.14.0 native Icinga for Windows API communication
@@ -38,13 +39,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
3839
* [#640](https://github.com/Icinga/icinga-powershell-framework/issues/640) Adds support to set the flag `-NoSSLValidation` for Cmdlets `icinga` and `Install-Icinga`, to ignore errors on self-signed certificates within the environment
3940
* [#643](https://github.com/Icinga/icinga-powershell-framework/pull/643) Adds support for `-RebuildCache` flag on `icinga` cmd to rebuild component cache as well
4041
* [#644](https://github.com/Icinga/icinga-powershell-framework/pull/644) Adds progress bar output to repository interaction (sync, update, new) instead of plain text output
42+
* [#649](https://github.com/Icinga/icinga-powershell-framework/pull/649) Adds new basic data provider base for Hyper-V information
4143
* [#655](https://github.com/Icinga/icinga-powershell-framework/pull/655) Adds [IWKB](https://icinga.com/docs/icinga-for-windows/latest/doc/knowledgebase/IWKB000016/) and test/manage Cmdlets for SCOM intercept counters
4244
* [#656](https://github.com/Icinga/icinga-powershell-framework/pull/656) Adds new feature to write document content easier by storing it in memory first and then allowing to write it to disk at once with proper UTF8 encoding
4345

44-
### Enhancements
45-
46-
* [#613](https://github.com/Icinga/icinga-powershell-framework/pull/613) Adds a `-Version` parameter to the `Update-Icinga` command, to be able to update a component to a specified version [@log1-c]
47-
4846
## 1.10.1 (2022-12-20)
4947

5048
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/27?closed=1)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
function Get-IcingaProviderDataValuesHyperV()
2+
{
3+
param (
4+
[switch]$IncludeDetails = $FALSE
5+
);
6+
7+
$HyperVData = New-IcingaProviderObject -Name 'Hyper-V';
8+
9+
# Check if the Hyper-V is installed. If not, we will simply return an empty object
10+
if ($null -eq (Get-Service -Name 'vmms' -ErrorAction SilentlyContinue)) {
11+
$HyperVData.FeatureInstalled = $FALSE;
12+
13+
return $HyperVData;
14+
}
15+
16+
$HyperVData.Metrics | Add-Member -MemberType NoteProperty -Name 'ClusterData' -Value (New-Object PSCustomObject);
17+
$HyperVData.Metrics | Add-Member -MemberType NoteProperty -Name 'BlackoutTimes' -Value (New-Object PSCustomObject);
18+
$HyperVData.Metrics.BlackoutTimes | Add-Member -MemberType NoteProperty -Name 'Information' -Value (New-Object PSCustomObject);
19+
$HyperVData.Metrics.BlackoutTimes | Add-Member -MemberType NoteProperty -Name 'Warning' -Value (New-Object PSCustomObject);
20+
$HyperVData.Metrics.ClusterData | Add-Member -MemberType NoteProperty -Name 'NodeCount' -Value 1; # We always have at least 1 node
21+
$HyperVData.Metrics.ClusterData | Add-Member -MemberType NoteProperty -Name 'VMList' -Value (New-Object PSCustomObject);
22+
$HyperVData.Metrics.ClusterData.VMList | Add-Member -MemberType NoteProperty -Name 'Duplicates' -Value (New-Object PSCustomObject);
23+
$HyperVData.Metrics.ClusterData.VMList | Add-Member -MemberType NoteProperty -Name 'VMs' -Value (New-Object PSCustomObject);
24+
25+
try {
26+
if (Test-IcingaFunction 'Get-ClusterNode') {
27+
$ClusterInformation = Get-ClusterNode -Cluster '.' -ErrorAction Stop;
28+
29+
$HyperVData.Metrics.ClusterData.NodeCount = $ClusterInformation.Count;
30+
}
31+
32+
[array]$VMRessources = @();
33+
34+
if (Test-IcingaFunction 'Get-ClusterResource') {
35+
[array]$VMRessources = Get-ClusterResource -Cluster '.' -ErrorAction Stop | Where-Object ResourceType -EQ 'Virtual Machine';
36+
} else {
37+
[array]$VMRessources = Get-VM -ErrorAction Stop;
38+
}
39+
40+
if ($null -ne $VMRessources -And $VMRessources.Count -ne 0) {
41+
foreach ($VMRessource in $VMRessources) {
42+
if ((Test-PSCustomObjectMember -PSObject $HyperVData.Metrics.ClusterData.VMList.VMs -Name $VMRessource.Name) -eq $FALSE) {
43+
$HyperVData.Metrics.ClusterData.VMList.VMs | Add-Member -MemberType NoteProperty -Name $VMRessource.Name -Value 1;
44+
} else {
45+
$HyperVData.Metrics.ClusterData.VMList.VMs.($VMRessource.Name) += 1;
46+
47+
if ((Test-PSCustomObjectMember -PSObject $HyperVData.Metrics.ClusterData.VMList.Duplicates -Name $VMRessource.Name) -eq $FALSE) {
48+
$HyperVData.Metrics.ClusterData.VMList.Duplicates | Add-Member -MemberType NoteProperty -Name $VMRessource.Name -Value 0;
49+
}
50+
$HyperVData.Metrics.ClusterData.VMList.Duplicates.($VMRessource.Name) = $HyperVData.Metrics.ClusterData.VMList.VMs.($VMRessource.Name);
51+
}
52+
}
53+
}
54+
55+
# Blackout Times
56+
# => Info
57+
[array]$InformationBlackoutTimes = Get-WinEvent -FilterHashtable @{ 'LogName'='Microsoft-Windows-Hyper-V-VMMS-Admin'; 'Id' = '20415'; } -MaxEvents 300 -ErrorAction SilentlyContinue;
58+
59+
if ($null -ne $InformationBlackoutTimes -Or $InformationBlackoutTimes.Count -ne 0) {
60+
foreach ($event in $InformationBlackoutTimes) {
61+
$XMLEventData = ([xml]$event.ToXml()).Event;
62+
63+
if ((Test-PSCustomObjectMember -PSObject $HyperVData.Metrics.BlackoutTimes.Information -Name $XMLEventData.UserData.VmlEventLog.Parameter0) -eq $FALSE) {
64+
$EventObject = New-Object PSCustomObject;
65+
$EventObject | Add-Member -MemberType NoteProperty -Name 'Timestamp' -Value $event.TimeCreated;
66+
$EventObject | Add-Member -MemberType NoteProperty -Name 'BlackoutTime' -Value $XMLEventData.UserData.VmlEventLog.Parameter2;
67+
68+
$HyperVData.Metrics.BlackoutTimes.Information | Add-Member -MemberType NoteProperty -Name $XMLEventData.UserData.VmlEventLog.Parameter0 -Value $EventObject;
69+
}
70+
}
71+
}
72+
73+
# Blackout Times
74+
# => Warning
75+
[array]$WarningBlackoutTimes = Get-WinEvent -FilterHashtable @{ 'LogName'='Microsoft-Windows-Hyper-V-VMMS-Admin'; 'Id' = '20417'; } -MaxEvents 300 -ErrorAction SilentlyContinue;
76+
77+
if ($null -ne $WarningBlackoutTimes -Or $WarningBlackoutTimes.Count -ne 0) {
78+
foreach ($event in $WarningBlackoutTimes) {
79+
$XMLEventData = ([xml]$event.ToXml()).Event;
80+
81+
if ((Test-PSCustomObjectMember -PSObject $HyperVData.Metrics.BlackoutTimes.Warning -Name $XMLEventData.UserData.VmlEventLog.Parameter0) -eq $FALSE) {
82+
$EventObject = New-Object PSCustomObject;
83+
$EventObject | Add-Member -MemberType NoteProperty -Name 'Timestamp' -Value $event.TimeCreated;
84+
$EventObject | Add-Member -MemberType NoteProperty -Name 'BlackoutTime' -Value $XMLEventData.UserData.VmlEventLog.Parameter2;
85+
86+
[bool]$IsAcknowledged = $FALSE;
87+
88+
foreach ($InfoBlackoutTime in $HyperVData.Metrics.BlackoutTimes.Information.PSObject.Properties.Name) {
89+
if ($InfoBlackoutTime -eq $XMLEventData.UserData.VmlEventLog.Parameter0) {
90+
if($HyperVData.Metrics.BlackoutTimes.Information.$InfoBlackoutTime.Timestamp -gt $event.TimeCreated) {
91+
$IsAcknowledged = $TRUE;
92+
break;
93+
}
94+
}
95+
}
96+
97+
if ($IsAcknowledged) {
98+
continue;
99+
}
100+
101+
$HyperVData.Metrics.BlackoutTimes.Warning | Add-Member -MemberType NoteProperty -Name $XMLEventData.UserData.VmlEventLog.Parameter0 -Value $EventObject;
102+
}
103+
}
104+
}
105+
} catch {
106+
Exit-IcingaThrowException -ExceptionType 'Custom' -CustomMessage 'Hyper-V Error' -ExceptionThrown $_.Exception.Message -Force;
107+
}
108+
109+
return $HyperVData;
110+
}

lib/provider/core/New-IcingaProviderObject.psm1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ function New-IcingaProviderObject()
55
);
66

77
$ProviderObject = New-Object PSCustomObject;
8-
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value $Name;
9-
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Metadata' -Value (New-Object PSCustomObject);
10-
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Metrics' -Value (New-Object PSCustomObject);
11-
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'MetricsOverTime' -Value (New-Object PSCustomObject);
12-
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'MetricContainer' -Value (New-Object PSCustomObject);
13-
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'Cache' -Value (New-Object PSCustomObject);
14-
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'Compiled' -Value (New-Object PSCustomObject);
8+
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value $Name;
9+
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'FeatureInstalled' -Value $TRUE;
10+
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Metadata' -Value (New-Object PSCustomObject);
11+
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'Metrics' -Value (New-Object PSCustomObject);
12+
$ProviderObject | Add-Member -MemberType NoteProperty -Name 'MetricsOverTime' -Value (New-Object PSCustomObject);
13+
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'MetricContainer' -Value (New-Object PSCustomObject);
14+
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'Cache' -Value (New-Object PSCustomObject);
15+
$ProviderObject.MetricsOverTime | Add-Member -MemberType NoteProperty -Name 'Compiled' -Value (New-Object PSCustomObject);
1516

1617
return $ProviderObject;
1718
}

0 commit comments

Comments
 (0)