[ZBX-16668] Running remote command on zabbix app server strips json formatting from arguments Created: 2019 Sep 23  Updated: 2019 Sep 23  Resolved: 2019 Sep 23

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Carl Slaughter Assignee: Zabbix Support Team
Resolution: Won't fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Zabbix_1.1_action.png     PNG File Zabbix_1.1_operation.png     PNG File image-2019-09-23-17-37-33-511.png    

 Description   

I have configured my agent installers so that it adds a json formatted metadata string to the config file like the one shown below.

HostMetadata="{"version":"rhel7","account":363748,"os":"RHEL-Cent","osfamily":"Linux","datacenter":"dal13","evault":"true","type":"VSI","objectid":89956126}"

In my auto registration, I have an action (with no criteria defined to it will run on all hosts as they auto register) defined that runs a remote command locally on the zabbix server. This remote command passes the

{HOST.HOST}

,

{HOST.IP}

, and

{HOST.METADATA}

to a script that dumps the current time stamp and the variables passed to a log file so I can easily track the autoregistration process.

#!/bin/bash
timestamp=`date +%s`
echo $timestamp `date ` $@ >> /tmp/autoreg.log

The issue that I found is that although the zabbix server receives and saves the full json object to the database

|          53042 |        12142 | 363748VN51RP001                    | 10.73.223.158  |       10050 |                                | {"version":"rhel7","account":363748,"os":"RHEL-Cent","osfamily":"Linux","datacenter":"dal13","evault":"true","type":"VSI","objectid":89956126}                                                   |

when it passes the metedata to the script, it strips out the json formatting. (See the output from the log used in the script above)

1569165618 Sun Sep 22 10:20:18 CDT 2019 1.1 363748VN51RP001 10.73.223.158 version:rhel7 account:363748 os:RHEL-Cent osfamily:Linux datacenter:dal13 evault:true type:VSI objectid:89956126

This in turn negates the useful nature of preformatting this data so that I can post process it on the zabbix server during auto registration.



 Comments   
Comment by Aigars Kadikis [ 2019 Sep 23 ]

Hello and thank you for registering this use case. If you will create a simple bash script:

cat << 'EOF' > /tmp/argument-test.sh
#!/bin/bash
echo $1
EOF
chmod +x /tmp/argument-test.sh

and try to post the same thing

cd /tmp
./argument-test.sh {"version":"rhel7","account":363748,"os":"RHEL-Cent","osfamily":"Linux","datacenter":"dal13","evault":"true","type":"VSI","objectid":89956126}

You will also receive a dropped content.

To make this work you must escape all double quotes regarding JSON content and put the whole info inside double-quotes (not escaped) like:

HostMetadata="{\"version\":\"rhel7\",\"account\":363748,\"os\":\"RHEL-Cent\",\"osfamily\":\"Linux\",\"datacenter\":\"dal13\",\"evault\":\"true\",\"type\":\"VSI\",\"objectid\":89956126}"

A different workaround is to put the {HOST.METADATA} variable in single quotes like:

I will close this issue now. Feel free to comment or register another one.

Generated at Sat Mar 15 09:57:21 EET 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.