Icinga / icinga-powershell-hyperv

A collection of Hyper-V plugins for the Icinga Powershell Framework
GNU General Public License v2.0
5 stars 0 forks source link

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

Open audiocoach opened 5 months ago

audiocoach commented 5 months ago

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 commented 5 months ago

Powershell Errors on Hyper-V Hosts running normal Windows Storage Pools - Full error Text.txt

audiocoach commented 5 months ago

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 commented 5 months ago

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 commented 2 months ago

Fixed with changes according to https://github.com/Icinga/icinga-powershell-plugins/issues/390