Skip to content

Commit 6ee6012

Browse files
authored
Merge pull request #649 from Icinga:feature/adds_hyperv_provider
Feature: Adds new Hyper-V data provider Adds new basic data provider base for Hyper-V information
2 parents 3f6d589 + 7d156f6 commit 6ee6012

File tree

3 files changed

+119
-7
lines changed

3 files changed

+119
-7
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
4040
* [#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
4141
* [#643](https://github.com/Icinga/icinga-powershell-framework/pull/643) Adds support for `-RebuildCache` flag on `icinga` cmd to rebuild component cache as well
4242
* [#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
43+
* [#649](https://github.com/Icinga/icinga-powershell-framework/pull/649) Adds new basic data provider base for Hyper-V information
4344
* [#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
4445
* [#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
4546

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)