Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell Errors on Hyper-V Hosts running Windows Storage Spaces #75

Open
audiocoach opened this issue Jan 15, 2024 · 4 comments
Open

Comments

@audiocoach
Copy link

audiocoach commented Jan 15, 2024

Hello,

I get powershell errors and an unknown state when running the Invoke-IcingaCheckHyperVVMHealth, Invoke-IcingaCheckHyperVOverCommitment and Invoke-IcingaCheckHyperVSnapshot against an hyper-v host with normal windows storage pools using storage spaces (not storage spaces direct!!!).

The problem seems to be in the following region:

            foreach ($disk in $VComputerHardDisks.Keys) {
                $PhysicalDisk = $VComputerHardDisks[$disk];
                if ($PhysicalDisk.DriveReference.ContainsKey($SnapshotPart) -eq $FALSE) {
                    continue;
                }

                [string]$DiskId = $PhysicalDisk.DriveReference[$SnapshotPart];
                $FreeSpace      = $PhysicalDisk.PartitionLayout[$DiskId].FreeSpace;
                $PartSize       = $PhysicalDisk.PartitionLayout[$DiskId].Size;

For example my output for Invoke-IcingaCheckHyperVOverCommitment -Verbosity 2 looks like this. The errors for Invoke-IcingaCheckHyperVSnapshot and Invoke-IcingaCheckHyperVVMHealth look similar.

Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:1880 Zeichen:21
+ ...         if ($PhysicalDisk.DriveReference.ContainsKey($SnapshotPart) - ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:1884 Zeichen:17
+ ...             [string]$DiskId = $PhysicalDisk.DriveReference[$SnapshotP ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:1885 Zeichen:17
+ ...             $FreeSpace      = $PhysicalDisk.PartitionLayout[$DiskId]. ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:1886 Zeichen:17
+ ...             $PartSize       = $PhysicalDisk.PartitionLayout[$DiskId]. ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:2056 Zeichen:17
+ ...         if ($PhysicalDisk.DriveReference.ContainsKey($details.Partiti ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:2060 Zeichen:13
+             [string]$PartitionId = $PhysicalDisk.DriveReference[$deta ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:2063 Zeichen:13
+             $PartitionSize = $PhysicalDisk.PartitionLayout[$Partition ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Es wurde versucht, durch 0 (null) zu teilen.
In C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:2104 Zeichen:17
+ ...             $ConvertToPercent = ([System.Math]::Round((($VComputerDat ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException


.... Please see the attachement for the full error text.
[Powershell Errors on Hyper-V Hosts running normal Windows Storage Pools - Full error Text.txt](https://github.com/Icinga/icinga-powershell-hyperv/files/13942134/Powershell.Errors.on.Hyper-V.Hosts.running.normal.Windows.Storage.Pools.-.Full.error.Text.txt)

[WARNING] Hyper-V Overcommitment: 1 Warning 3 Ok [WARNING] VM images seem to be located on a Cluster Shared Volume but Cluster-Plugins are not installed (0)
\_ [OK] CPUOverCommit
   \_ [OK] F1R2-HYP01 Used Cores: 34c
   \_ [OK] F1R2-HYP01 Used Percent: 6.2500%
\_ [OK] RAMOverCommit
   \_ [OK] F1R2-HYP01 Used Bytes: 1.13TiB
   \_ [OK] F1R2-HYP01 Used Percent: 202.1200%
\_ [OK] StorageOverCommit
   \_ [OK] Partition D: Overcommitment
      \_ [OK] D: Used Bytes: 2.21TiB
      \_ [OK] D: Used Percent: 0%
   \_ [OK] Partition E: Overcommitment
      \_ [OK] E: Used Bytes: 0B
      \_ [OK] E: Used Percent: 0%
\_ [WARNING] VM images seem to be located on a Cluster Shared Volume but Cluster-Plugins are not installed: 0

Moreover the Warning "VM images seem to be located on a Cluster Shared Volume but Cluster-Plugins are not installed" is wrong. The storage pool is no cluster shared volume, just a standard storage spaces pool on a standalone hyper-v host with internal nvme ssds.

As a quick, temporary workaround would it be possible to suppress the powershell errors and if so how can I achieve this? I am asking because as you can see I get a valid output at the end (for all three checks) but due to the powershell errors it's returning an unknown state in icingaweb2

image

Icinga 2.14.1
Icinga Web 2.12.1
Icinga Director 1.11
Icinga for Windows 1.11.1
Hyper-V Plugins: 1.3.0

@audiocoach
Copy link
Author

Hi, I noticed there was already an issue (#66) with the same errors which was closed because of no further feedback from the op. It seems to be related to storage pools, in my case normal standard pools, in #66 S2D (Storage Spaces direct) pools.

@audiocoach
Copy link
Author

audiocoach commented Jan 31, 2024

I think I have found a way to suppress the powershell errors and the warning about the cluster shared volume. I don't know if it is a good way because I am not very experienced with powershell but for me it seems to work

C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\provider\vcomputer\Get-IcingaVirtualComputerInfo.psm1
Add try and catch in the follwing section

            foreach ($disk in $VComputerHardDisks.Keys) {
                try{
                $PhysicalDisk = $VComputerHardDisks[$disk];
                
                if ($PhysicalDisk.DriveReference.ContainsKey($SnapshotPart) -eq $FALSE) {
                    continue;
                }

                [string]$DiskId = $PhysicalDisk.DriveReference[$SnapshotPart];
                $FreeSpace      = $PhysicalDisk.PartitionLayout[$DiskId].FreeSpace;
                $PartSize       = $PhysicalDisk.PartitionLayout[$DiskId].Size;

                if ($details.Snapshots.Info[$SnapshotPart].ContainsKey('FreeSpace') -eq $FALSE) {
                    $details.Snapshots.Info[$SnapshotPart].Add('FreeSpace', $FreeSpace);
                }

                if ($details.Snapshots.Info[$SnapshotPart].ContainsKey('Size') -eq $FALSE) {
                    $details.Snapshots.Info[$SnapshotPart].Add('Size', $PartSize);
                }

                break;
                }
                catch {
                continue
                }
            }

and also in the following section

            try{
            if ($PhysicalDisk.DriveReference.ContainsKey($details.Partition) -eq $FALSE) {
                continue;
            }
            }
            catch {
            continue
            }
            [string]$PartitionId = $PhysicalDisk.DriveReference[$details.Partition];

            # Gather informations about the virtual computers hard disk drive
            $PartitionSize = $PhysicalDisk.PartitionLayout[$PartitionId].Size;

For the wrong warning regarding the cluster shared volume do the following:
C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\plugins\Invoke-IcingaCheckHyperVSnapshot.psm1
Comment line 307 - 314

   # if ($VirtualComputers.Summary.ContainsKey('SnapshotLocated')) {
   #     $CheckPackage.AddCheck(
   #         (
   #             New-IcingaCheck `
   #                 -Name 'Snapshot images seem to be located on a Cluster Shared Volume but Cluster-Plugins are not installed' -NoPerfData
   #         ).SetWarning()
   #     );
   # }

After the manual changes you have to rebuild the cache and restart the icinga services:

icinga -rebuildcache
Restart-IcingaService icinga2
Restart-IcingaService icingapowershell

@audiocoach audiocoach changed the title Powershell Errors on Hyper-V Hosts running normal Windows Storage Pools Powershell Errors on Hyper-V Hosts running Windows Storage Spaces Apr 4, 2024
@audiocoach
Copy link
Author

Fixed with changes according to Icinga/icinga-powershell-plugins#390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant