-
Notifications
You must be signed in to change notification settings - Fork 386
Windows Client Not Reporting Correct Powershell Exit Code #1919
Comments
Hey, Use this one for exit code 2: [System.Environment]::Exit(2) |
That one seems to exit the parent shell environment. Im not sure that's what we want... although it might work. I'm assuming existing check scripts should work with standard exit... e.g: https://github.com/sensu-plugins/sensu-plugins-windows/blob/f772fc42129b113c493243d758560cef32fe52b1/bin/powershell/check-windows-log.ps1#L39 |
'Exit 2’ didn’t work for me.
That’s why I changed all my powershell checks to -
[System.Environment]::Exit(2)
When It was EXIT 2, It got out as a warning and not as critical.
Why Does it matter if it exit the parent shell environment ?
… On Oct 29, 2018, at 4:27 AM, Daniel Korel ***@***.***> wrote:
That one seems to exit the parent shell environment. Im not sure that's what we want... although it might work.
I'm taking this example from existing published check scripts, e.g: https://github.com/sensu-plugins/sensu-plugins-windows/blob/f772fc42129b113c493243d758560cef32fe52b1/bin/powershell/check-windows-log.ps1#L39 <https://github.com/sensu-plugins/sensu-plugins-windows/blob/f772fc42129b113c493243d758560cef32fe52b1/bin/powershell/check-windows-log.ps1#L39>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#1919 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/Ah4l9AfHjFoO-uYGusqS46GcuyWH5YKAks5upmeTgaJpZM4X2aCM>.
|
Its useful to know, but I think it's a workaround and there is an underlying issue with how exit codes are caught. As I pointed out - all the powershell scripts I've seen published by Sensu use 'Exit [code]' I think that when a script exits, it's supposed to return control and exit codes to the calling shell. If we exit the parent shell, well it makes it difficult to develop and test code... and it goes against the intended design. |
well if you find another way that working, and the events get exit code 2 and seen as critical, update here plz :) |
I don't have a solution... i think it's a bug... so i think the project maintainers will assess the priority, and assign resources appropriately to hopefully fix it like the champs they are 🥇 :) I guess using ruby instead of powershell would be another possible workaround... |
Yes ruby is another possible workaround, but we had issue with it, because sometimes it couldn’t query services, so it causing an alert, watch it
… On Nov 1, 2018, at 7:10 AM, Daniel Korel ***@***.***> wrote:
I don't have a solution... i think it's a bug... so i think the project maintainers will assess the priority, and assign resources appropriately to hopefully fix it like the champs they are 🥇 :)
I guess using ruby instead of powershell would be another possible workaround...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#1919 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/Ah4l9Nac1kN4wHKTgN7dHXoZrkJ0J9LOks5uqoI2gaJpZM4X2aCM>.
|
I can't seem to reproduce this. Please let me know if I'm doing something differently than you. I copied your example into a file called Write-Host "TEST"
Exit 2 I then created a check definition: {
"checks": {
"check-test": {
"command": "powershell.exe -f c:\\users\\vagrant\\test.ps1",
"interval": 10,
"subscribers": ["windows"]
}
}
} The check results contain a status of |
Looks like the issue is with omitting the '-f' param. Thanks for picking this up! much appreciated |
No problem! Just to confirm, adding |
Correct. -f solves the issue. Thanks. |
When doing
Exit 2
in powershell, sensu-client only seems to capture a status of 1.Expected Behavior
I believe the status should be 2 when the exit code is 2.
Current Behavior
Status code 1 or 0 works as expected. If the process exits with something else, it translates to 1.
Possible Solution
I would guess windows Ruby implementation does not look to
$LASTEXITCODE
, but instead loots to$?
which only contains a True|False value.Steps to Reproduce (for bugs)
Run a powershell script with sensu client containing
Sensu history and status should see a status of 2. It sees a status of 1.
Your Environment
Windows Server 2012R2
Multiple versions of sensu-client for windows. Including the latest (sensu-1.5.0-1-x86.msi)
The text was updated successfully, but these errors were encountered: