Hello!
I have a little problem with the Zabbix api.
This is the bash script:
#!/bin/bash
USER='Admin'
PASS='zabbix'
ZABBIX_SERVER='127.0.0.1'
API='http://127.0.0.1/zabbix/api_jsonrpc.php'
# Authenticate with Zabbix API
authenticate()
{
echo `curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"user.login\",\"params\":{\"us er\":\""${USER}"\",\"password\":\""${PASS}"\"},\"a uth\": null,\"id\":0}" $API`
}
AUTH_TOKEN=`echo $(authenticate)|jq -r .result`
echo "Auth token:"$AUTH_TOKEN
# Get This Host HostId:
HOST_NAME=test2
create_host()
{
echo `curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"host.create\",\"params\":{\"h ost\":\""$HOST_NAME"\",\"interfaces\": [{\"type\": 1,\"main\": 1,\"useip\": 1,\"ip\": \"192.168.3.2\",\"dns\": \$
}
RESPONSE=$(create_host)
echo ${RESPONSE}
Output message when i run this script:
Auth token:51338083b2dee2475f8450ccddc6d308
{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request.","data":"JSON-rpc version is not specified."},"id":null}
I tested a host remove, and it's worked.
The authentication is good.
The JSON-rpc version is specified in the script...
I have no idea what's wrong with this script.
Please help!
Thanks!
I have a little problem with the Zabbix api.
This is the bash script:
#!/bin/bash
USER='Admin'
PASS='zabbix'
ZABBIX_SERVER='127.0.0.1'
API='http://127.0.0.1/zabbix/api_jsonrpc.php'
# Authenticate with Zabbix API
authenticate()
{
echo `curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"user.login\",\"params\":{\"us er\":\""${USER}"\",\"password\":\""${PASS}"\"},\"a uth\": null,\"id\":0}" $API`
}
AUTH_TOKEN=`echo $(authenticate)|jq -r .result`
echo "Auth token:"$AUTH_TOKEN
# Get This Host HostId:
HOST_NAME=test2
create_host()
{
echo `curl -s -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\": \"2.0\",\"method\":\"host.create\",\"params\":{\"h ost\":\""$HOST_NAME"\",\"interfaces\": [{\"type\": 1,\"main\": 1,\"useip\": 1,\"ip\": \"192.168.3.2\",\"dns\": \$
}
RESPONSE=$(create_host)
echo ${RESPONSE}
Output message when i run this script:
Auth token:51338083b2dee2475f8450ccddc6d308
{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request.","data":"JSON-rpc version is not specified."},"id":null}
I tested a host remove, and it's worked.
The authentication is good.
The JSON-rpc version is specified in the script...
I have no idea what's wrong with this script.
Please help!
Thanks!
Comment