1

SOLVED

Thanks to @mklement0 's advice, I tried to get an exit code from rstcli64.exe:

  • from cmd I get 0
  • from zabbix-agent I get 3 (INVALID_DEVICE, according to manual) So, the culprit is not PowerShell, but rstcli64.exe exiting with an error in conditions: Windows Server 2019 and ran from PS script ran by zabbix-agent. I've updated rstcli from Intel's website and new version has the same syntax and works perfectly in new conditions.

ORIGINAL POST

I have Windows Zabbix Agent, which runs a PowerShell script, which runs a command line application, parses output and gives 1 or 0.

$states = C:\util\rstcli64.exe --information --volume 2> $null | select-string -Pattern "State:"

$notNormalStates = $states | Select-String -Pattern "Normal" -NotMatch
if ($states.Count -gt 0 -and $notNormalStates.Count -eq 0){
    "1"
} Else {
    "0"
}

This script worked on Windows Server 2012 R2, but after migration to Windows Server 2019 (with PowerShell 5.1) it began to output only 0.

This is a wave-particle duality situation: if I run this script from command line (User, Administrator, System - the same), it gives 1, because it receives the output from rstcli64.exe; and if zabbix-agent runs this exact script, it gets nothing from rstcli64.exe, thus gives 0.

So I guess the difference is that I run the script from an interactive shell and zabbix-agent runs the script from background.

And the question is: how do I get the output from a command line application in PowerShell 5.1 (Windows Server 2019), when run in background?

MORE INFO

If I just use this:

$states = C:\util\rstcli64.exe --information --volume
$states
exit

It shows a lot of data if I run the script in command line:

--VOLUME INFORMATION--

Name: HDD_MIRROR Raid Level: 1 Size:
1863 GB StripeSize: 64 KB Num Disks: 2 State:
Normal System: True Initialized: True Cache Policy:
R

--DISKS IN VOLUME: HDD_MIRROR --

ID: 0-0-0-0 Type: Disk Disk Type:
SATA Disk State: Normal

But if ran from zabbix - there's nothing:

6304:20201014:170446.686 EXECUTE_STR() command:'%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -nologo -ExecutionPolicy ByPass -File "C:\util\intel_rst_raid.ps1"' len:0 cmd_result:'' 6304:20201014:170446.686 Sending back []
8208:20201014:170446.687 End of collect_perfstat()

MORE INFO

It just does it with rstcli64.exe. With few other command line tools I get the same output when manually running script in cmd and triggering it from zabbix-agent. Again, only in PowerShell 5.1 in Windows Server 2019, so...

13
  • 1
    OK, thank you for that. But the main issue remains a secret. Commented Oct 14, 2020 at 14:17
  • 1
    Another aspect - though, again, it shouldn't really matter here and doesn't explain the symptom - is the PowerShell instance that zabbix runs the 32-bit version of PowerShell? Commented Oct 14, 2020 at 14:40
  • 1
    Re 64-bit: What matters is whether zabbix itself is 32-bit or 64-bit - 32-bit processes see a different directory as %SystemRoot%\system32. From a 32-bit process you'd have to use `%SystemRoot%\SysNative` to access the 64-bit dir. Commented Oct 14, 2020 at 14:52
  • 1
    I've never used rstcli64.exe, so I can't be of help there. But note that there's also the added mystery of no output at all getting captured - unless zabbix captures stderr (from PowerShell's errors in that case) as well. If you can inspect the process exit code, see if it is 1: that would indicate that execution of the script failed fundamentally (if it even got to that point), due to a script-terminating error (loosely speaking, an unhandled exception). Commented Oct 14, 2020 at 15:03
  • 1
    @mklement0 I've got the exit code of rstcli by using $lastExitCode! In cmd it is 0 and from zabbix it is 3! So, definitely nothing to do with Powershell. Thank you! I will be researching that. Commented Oct 14, 2020 at 15:13

1 Answer 1

2

This sounds like an issue with redirection and streams. The information stream was introduced in 5.0 and Windows 2012R2 comes with 4.0. Which might explain the different behavior.

About_Redirection

I'd play around with the redirection operators to see if you can get what you need piped to Select-String. It might look something like:

$states = C:\util\rstcli64.exe --information --volume *>&1 | select-string -Pattern "State:" 

This takes all streams and redirects them to the success stream, this way everything goes down the pipeline to Select-string.

I'd also advise you can make your RegEx a little more precise. Maybe "^State:" so you are capturing lines that start with "State:". Though I don't know if there may be preceding white space.

Sign up to request clarification or add additional context in comments.

3 Comments

The RegEx is fine. If I output the $states variable, I receive a lot of "State: Normal State: Normal State: Normal" in $states. If I run in cmd. But if zabbix-agent runs the same script - there is nothing. "*>&1" did not help, the result is the same
Unfortunately I don't know enough about the executable to test on my own. You might try Start-Process which has -RedirectStabdardError & -RedirectStandardOutput parameters. Based on other comments that might be something to experiment with.
rstcli64.exe is Intel Rapid Storage Command Line Interface tool that outputs different info about RST controller and drives. you can download it from Intel website and run it even if you don't have Intel controller

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.