[ZBXNEXT-4761] Zabbix Item Type External Check wraps each argument in quotation marks, which breaks PowerShell Core Created: 2018 Aug 10  Updated: 2018 Sep 27

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: Proxy (P), Server (S)
Affects Version/s: None
Fix Version/s: None

Type: Change Request Priority: Major
Reporter: Marco Hofmann Assignee: Zabbix Support Team
Resolution: Unresolved Votes: 0
Labels: externalchecks, items, powershell, scripts
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian 9 Stretch amd64
zabbix_proxy (Zabbix) 3.4.12



 Description   

Due to the new possibilites Microsoft offers the Linux community, I installed Microsoft PowerShell and Vmware PowerCLI on Debian.

I want Zabbix Proxy to query VMware vCenter via External check.

I created a ps1 script which accepts several copmmand line arguments.

Zabbix wraps each argument in quotation marks, but PowerShell can't interpret arguments in quotation marks.

 

Steps to reproduce:

  1. Create an Item of Type "External check"
  2. Create the Key. Can be Any Key with script name and at least 1 Parameter. For example:
  3. vmware.ps.wrapper.shvmware.vm.snapshot.count.ps1,{HOST.CONN},{$USERNAME},'{$PASSWORD}',{#VM.NAME}
  4. Set Debug Log to Level 4

Result:

zabbix_proxy.log:

 

13741:20180809:094425.082 In get_value() key:'vmware.vm.snapshot.count.ps1[-Server {HOST.CONN},-User {$USERNAME},-Password '{$PASSWORD}',-VM {#VM.NAME}]'

13741:20180809:094425.082 In get_value_external() key:'vmware.vm.snapshot.count.ps1[-Server 10.23.0.200,-User [email protected],-Password 'XXX',-VM server.domain.local]'

13741:20180809:094425.083 In zbx_popen() command:'/usr/lib/zabbix/externalscripts/vmware.vm.snapshot.count.ps1 "-Server 10.23.0.200" "-User [email protected]" "-Password 'XXX'" "-VM server.domain.local"'

 

 Zabbix puts quotation marks around any argument:

vmware.vm.snapshot.count.ps1 "-Server 10.23.0.200" "-User [email protected]" "-Password 'XXX'" "-VM server.domain.local"'

These arguments won't get parsed in the script.

 

Expected:

The String should be created as following:

vmware.vm.snapshot.count.ps1 -Server 10.23.0.200 -User [email protected] -Password 'XXX' -VM server.domain.local

I need Zabbix to let the Admin choose, if the arguments are put in quotation marks or not.

 

I solved it, by calling a Linux Bash Script first, which accepts five arguments and parses the arguments to the powershell script without quotation marks:

 

/usr/lib/zabbix/externalscripts/vmware.ps.wrapper.sh:

 

#!/bin/bash

/usr/bin/pwsh -File /usr/lib/zabbix/externalscripts/$1 -Server $2 -User $3 -Password $4 -VM $5

 



 Comments   
Comment by Edgar Akhmetshin [ 2018 Aug 10 ]

Hello, Marco

Thank you for contacting Zabbix. Beginning with version 2.0.0, quotation marks are used for all arguments of the external checks. You can process arguments with quotes using the capabilities of a powershell script. Looks like a ZBXNEXT request.

Please note that ZBX is a Bug Tracker, no indication of a bug here.

Comment by Marco Hofmann [ 2018 Sep 27 ]

Thank you very much, for moving my Request into the right Tracker!

"You can process arguments with quotes using the capabilities of a powershell script."

I'm a PowerShell beginner, as far as I found out, arguments in quotes won't get parsed into the script, but if I'm wrong I would gladly correct myself.

The Bash Wrapper script to strip the quotation marks down is overhead, but works very well!

Generated at Fri Mar 29 13:14:52 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.