I would like to automate host creation on zabbix
server without using agent on hosts. Tried to use Discovery rules and sending JSON data
with zabbix_sender
. But without luck. Server does not accept data
.
Environment: Zabbix server 3.4 installed on Centos 7.Hosts with Windows or Ubuntu.
On server I created host
with name zab_trap
In that host I created Discovery rule with key zab_trap.discovery
and type Zabbix_trapper
. Then in Discovery rule I created Host prototype with name {#RH.NAME}.
Command line with JSON “data”:
zabbix_sender.exe -z zab_server -s zab_trap -k zab_trap.discovery -o "{"data":[{"{#RH.NAME}":"HOST1"}]}"
I expected that “HOST1” will be created. But after execution I got:
"info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000188"
sent: 1; skipped: 0; total: 1"
And there is no error in zabbix_server.log (with debug level 5)
I see this:
trapper got '{"request":"sender data","data":[{"host":"zab_trap","key":"zab_trap.discovery","value":"'{data:[{{#RH.NAME}:HOST1}]}'"}]}'
I think that maybe there is something wrong with JSON syntax.
Please help.
2
Answers
It seems I have found solution. Problem is hidden in a way to send JSON. As I understood it does not work properly or there is problem with syntax(quotes) if write JSON directly in command line. But it works if zabbix_sender send file with JSON.
Command line:
zabbix_sender -z zab_server -s zab_trap -i test.json
File test.json contain line:
- zab_trap.discovery {"data":[{"{#RH.NAME}":"HOST1"}]}
Host created.
If you want to use the command line, without file json, you need to clean the string with:
zabbix_sender.exe -z zab_server -s zab_trap -k zab_trap.discovery -o “$(echo ‘{“data”:[{“{#RH.NAME}”:”HOST1″}]}’ | tr -cd ‘[:print:]’)”