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

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

Closed
Aleksey-Maksimov opened this issue Jul 4, 2024 · 3 comments · Fixed by #80
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Aleksey-Maksimov
Copy link

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.

@LordHepipud LordHepipud added this to the v1.3.1 milestone Jan 17, 2025
@LordHepipud LordHepipud added the bug Something isn't working label Jan 17, 2025
@LordHepipud LordHepipud self-assigned this Jan 17, 2025
@Aleksey-Maksimov
Copy link
Author

Hello.

I updated the plugin to the latest version 1.3.1, but the problem remains.

Installed components on this system:
agent 2.14.4
cluster 1.3.0
framework 1.13.2
hyperv 1.3.1
plugins 1.13.0
service 1.2.0

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

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
0

@adn77
Copy link

adn77 commented Feb 14, 2025

@Aleksey-Maksimov I believe you are running into the same issues as I am...

This line

if ([string]::IsNullOrEmpty($details.Partition)) {

should fail as there is no $PhysicalDisk.DriveReference for the snapshot in question. This line works for me:

          if ([string]::IsNullOrEmpty($details.Partition) -or [string]::IsNullOrEmpty($PhysicalDisk.DriveReference) ) {

I would guess you're running your VMs on "Microsoft Storage Spaces" (no CSV), which are not listed in the regular disk views.
@LordHepipud this Icinga/icinga-powershell-plugins#390 code seems to fix the underlying issue. Unfortunately there doesn't seem to be a nice way to merge the two disk types:
Physical Disks

Get-IcingaWindowsInformation MSFT_PhysicalDisk -Namespace 'root\Microsoft\Windows\Storage'

Microsoft Storage Spaces

Get-IcingaWindowsInformation MSFT_VirtualDisk -Namespace 'root\Microsoft\Windows\Storage'

I am running a modified version incorporating those changes and could provide a PR if you see this fit.

Alex

@Aleksey-Maksimov
Copy link
Author

We do not use "Microsoft Storage Spaces". All our virtual disks are located on a CSV volume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants