Icinga / icinga-powershell-hyperv

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

Invoke-IcingaCheckHyperVSnapshot - You cannot call a method on a null-valued expression. #77

Open Aleksey-Maksimov opened 4 months ago

Aleksey-Maksimov commented 4 months ago

Hello.

The snapshot checking plugin Invoke-IcingaCheckHyperVSnapshot works fine if all virtual machines are included in the scan

Invoke-IcingaCheckHyperVSnapshot -Verbosity 2 -CountSnapshotWarning 0 -NoPerfData -AvoidEmptyCheck

[OK] VM Snapshots: 4 Ok
\_ [OK] KOM-WS41
   \_ [OK] KOM-WS41
      \_ [OK] No snapshots created: 0
\_ [OK] KOM-WS42
   \_ [OK] KOM-WS42
      \_ [OK] No snapshots created: 0
\_ [OK] KOM-WS43
   \_ [OK] KOM-WS43
      \_ [OK] No snapshots created: 0
\_ [OK] KOM-WS44
   \_ [OK] KOM-WS44
      \_ [OK] No snapshots created: 0

Also, the plugin works fine if we add the -ExcludeVms filter and a certain part of the virtual machines is included in the selection

Invoke-IcingaCheckHyperVSnapshot -Verbosity 2 -CountSnapshotWarning 0 -NoPerfData -ExcludeVms "*-WS41" -AvoidEmptyCheck

[OK] VM Snapshots: 3 Ok
\_ [OK] KOM-WS42
   \_ [OK] KOM-WS42
      \_ [OK] No snapshots created: 0
\_ [OK] KOM-WS43
   \_ [OK] KOM-WS43
      \_ [OK] No snapshots created: 0
\_ [OK] KOM-WS44
   \_ [OK] KOM-WS44
      \_ [OK] No snapshots created: 0

However, if the plugin filters out all virtual machines, we will receive an error

Invoke-IcingaCheckHyperVSnapshot -Verbosity 2 -CountSnapshotWarning 0 -NoPerfData -ExcludeVms "*-WS4*" -AvoidEmptyCheck

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-hyperv\compiled\icinga-powershell-hyperv.ifw_compilation.psm1:785 char:9
+     if ($VirtualComputers.Summary.ContainsKey('SnapshotLocated')) {
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

[OK] VM Snapshots

We need an additional option that allows us to set the status to OK if the VMs are not selected. Thank you.