[ZBX-19278] Powershell script run via system.run in Agent 2 not executing correctly Created: 2021 Apr 23 Updated: 2022 Jul 18 |
|
Status: | Open |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Incident report | Priority: | Trivial |
Reporter: | Shane Arnold | Assignee: | Zabbix Support Team |
Resolution: | Unresolved | Votes: | 1 |
Labels: | agent2, nowait, passive, powershell | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Attachments: |
![]() ![]() ![]() ![]() ![]() ![]() |
Description |
Executing a system.run command as shown in the example below does not execute correctly when nowait parameter is set. Removing the nowait parameter allows the script to execute correctly. Steps to reproduce: Create passive check, key "system.run["powershell.exe -executionpolicy bypass -File \"C:\Program Files\Zabbix Agent 2\Scripts\Get-PendingReboot.ps1\" check",nowait]" Execute check either via "Execute" or using zabbix_get Confirm that command was received and excuted on Agent 2 (DebugLevel=4) 2021/04/23 12:23:34.796755 received passive check request: 'system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]' from '192.168.10.100' 2021/04/23 12:23:34.797732 [1] processing update request (1 requests) 2021/04/23 12:23:34.797732 [1] adding new request for key: 'system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]' 2021/04/23 12:23:34.798731 [1] created direct exporter task for plugin 'SystemRun' itemid:0 key 'system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]' 2021/04/23 12:23:34.798731 executing direct exporter task for key 'system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]' 2021/04/23 12:23:34.799731 [SystemRun] Executing command:'powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check' 2021/04/23 12:23:34.808731 executed direct exporter task for key 'system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]' 2021/04/23 12:23:34.812733 sending passive check response: '1' to '192.168.10.100' Expected output should be zabbix_sender called to send back a value (and output to a log file at each function/step to show that script has been run). No file is created Expected A system.run item with a nowait command should work as expected. |
Comments |
Comment by Shane Arnold [ 2021 Apr 23 ] |
Extra notes:
zabbix_get -s 192.168.10.34 -k system.run[powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check,nowait]
zabbix_get [929699]: invalid option -- e
Attempting to escape the quotes so that the path is correctly provided to powershell results in the same
root@ITDVZX001:~# zabbix_get -s 192.168.10.34 -k system.run[powershell.exe -executionpolicy bypass -File \"C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1\" check,nowait]
zabbix_get [930300]: invalid option -- e
Correcting the key to single-quote the powershell command works, however is not valid powershell (execution fails if this is run locally). Is received by Agent2.
root@ITDVZX001:~# zabbix_get -s 192.168.10.34 -k system.run['powershell.exe -executionpolicy bypass -File \"C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1\" check',nowait]
1
Removing the escaping for the double-quotes should be valid powershell (but there is no execution of powershell from what I can tell). Is received by Agent2.
root@ITDVZX001:~# zabbix_get -s 192.168.10.34 -k system.run['powershell.exe -executionpolicy bypass -File "C:\Program Files\Zabbix Agent 2\Scripts\Get-WindowsUpdateLastInstalled.ps1" check',nowait]
1
Running the above valid command locally works, generates the Out-File as expected and correctly executes and sends the value |
Comment by Dmitry Krupornitsky [ 2021 May 14 ] |
Hello, Shane
It's really a complex thing to do if you try to use long shell commands (with special chars like " ' [ ] ) for system.run key. When constructing such long system.rum key, first of all you have to follow item key syntax requirements: So, all the data inside square brackets is highly recommended to enclose in double quotes. But, you have double quotes in shell command itself, so they must be escaped, manually: https://www.zabbix.com/documentation/5.0/manual/config/items/item/key#parameter_-_quoted_string Does the problem persist? |