Event status does not match script exit code

I used check-windows-disk.ps1 powershell script from asset samroy92/sensu-plugins-windows.
When I execute manually the script on my Windows Server environment, it detects a 99% full disk and as expected the exit code is 2

PS C:\ProgramData\Sensu\cache\sensu-agent\7606a43a1fb5bcfb8b13d29293fae26f83239ae96f089c3930f5d46dc72ffb7101478e5c023aa2c384b582e574d04a6a433c5e1f65f708f0f67afa5d173859c3\bin> .\check-windows-disk.ps1

cmdlet check-windows-disk.ps1 at command pipeline position 1
Supply values for the following parameters:
WARNING: 75
CRITICAL: 90
CheckDisk CRITICAL: 1 disks in critical state
(D:) 99.67%, FREE: 0 GB, SIZE: 31 GB

PS C:\ProgramData\Sensu\cache\sensu-agent\7606a43a1fb5bcfb8b13d29293fae26f83239ae96f089c3930f5d46dc72ffb7101478e5c023aa2c384b582e574d04a6a433c5e1f65f708f0f67afa5d173859c3\bin> $LASTEXITCODE
2

However the status which is retrieved by Sensu is 1 (not 2 as expected).

tribvn@sensu:~$ sudo sensuctl event info CalopixIntegrat windows-check-disk-usage
=== CalopixIntegrat - windows-check-disk-usage
Entity:    CalopixIntegrat
Check:     windows-check-disk-usage
Output:    CheckDisk CRITICAL: 1 disks in critical state
(D:) 99.67%, FREE: 0 GB, SIZE: 31 GB

Status:    1
History:   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Silenced:  false
Timestamp: 2023-06-14 18:23:08 +0200 CEST
UUID:      4742815a-5116-4d5a-add9-83f9426089ce

Why the exit code of the powershell code and the status of the matching check is not the same?

Sensu version is 5.21.0

Thanks by advance for your help.

Hey Romain, :wave:

I am one of the community volunteers here in the Sensu Community Forum. I will say, first off, that sounds like a bug. The version of Sensu you’re using is quite old and unsupported, with one major and many minor versions back from the current version, 6.10. Many improvements and fixes have been committed since 5.21.0:

It may be worth looking at the release notes and considering upgrading to a supported version. It’s important to note there are some significant things to note before going through an upgrade procedure when you’re coming from that far back:

I’d strongly recommend reading through that doc before proceeding.

I can confirm that older versions of Sensu had a bug with check execution under powershell. The process return code is not reflected correctly in powershell commands unless special care is taken. The issue has been fixed for several years now.

1 Like

Thanks, Eric. :wave:

I thought that might be the case.

Thanks @JustinToo, indeed I should upgrade my sensu version.
Romain.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.