Obtain authorization key:
auth=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"id":1,"auth":null}' http://127.0.0.1/api_jsonrpc.php | jq -r '.result')
Set IP address for host:
ip=192.168.3.5
Prepare the call:
todo="{ \"jsonrpc\": \"2.0\", \"method\": \"host.create\", \"params\": { \"host\": \"$ip\", \"interfaces\": [ { \"type\": 1, \"main\": 1, \"useip\": 1, \"ip\": \"$ip\", \"dns\": \"\", \"port\": \"10050\" } ], \"groups\": [ { \"groupid\": \"15\" } ], \"templates\": [ { \"templateid\": \"10254\" } ], \"inventory_mode\": 0, \"inventory\": { \"macaddress_a\": \"01234\", \"macaddress_b\": \"56768\" } }, \"auth\": \"$auth\", \"id\": 1 }"
Summary the query:
echo $todo | jq
Execute:
curl -s -X POST -H 'Content-Type: application/json' -d "$todo" http://127.0.0.1/api_jsonrpc.php | jq -r '.result'