Zabbix 6.2
Hey guys.
I'm trying to update a global macro using the Zabbix API.
For testing, I used the "usermacro.updateglobal" method.
The script:
The actual payload.
The issue is that the "usermacro.updateglobal" JSON response is an error.
For the "event.acknowledge" method, the requests have no issues, but the same is not true for the "usermacro.updateglobal".
The API user role has the "event.acknowledge" and "usermacro.*" permissions. (there's no "usermacro.updateglobal" available on the list).
I'm not sure if the issue is related to permissions or an invalid parameter.
Any thoughts?
Hey guys.
I'm trying to update a global macro using the Zabbix API.
For testing, I used the "usermacro.updateglobal" method.
The script:
Code:
#!/bin/bash
# Zabbix Auth
ZABBIX_URL="https://zabbix.url/api_jsonrpc.php"
ZBXTOKEN="zabbix_api_token"
# Global Macro ID to update
GMACROID_1="4"
GMACROID_2="5"
GMACROID_3="6"
# Datas
DATA1=$(data 1)
DATA2=$(data 2)
DATA3=$(data 3)
# Zabbix API payload
PAYLOAD='{
"jsonrpc": "2.0",
"method": "usermacro.updateglobal",
"params": [{
"globalmacroid": "'"${GMACROID_1}"'",
"value": "'"${DATA1}"'"
},
{
"globalmacroid": "'"${GMACROID_2}"'",
"value": "'"${DATA2}"'"
},
{
"globalmacroid": "'"${GMACROID_3}"'",
"value": "'"${DATA3}"'"
}],
"auth": "'"$ZBXTOKEN"'",
"id": 2
}'
echo -e "PAYLOAD\n $PAYLOAD"
# Curl response
RESPONSE="$(curl --silent -k \
--show-error \
--request POST \
--header "Content-Type: application/json" \
--data "${PAYLOAD}" \
--url $ZABBIX_URL)"
echo -e "\n\nRESPONSE\n $RESPONSE"
# Erro check
ERROR=$(echo "${RESPONSE}" | jq -r '.error.message')
if [ "${ERROR}" != "null" ]; then
echo -e "\nError Zabbix API:"
echo "${ERROR}"
exit 1
fi
Code:
{
"jsonrpc": "2.0",
"method": "usermacro.updateglobal",
"params": [{
"globalmacroid": "4",
"value": "1"
},
{
"globalmacroid": "5",
"value": "2"
},
{
"globalmacroid": "6",
"value": "3"
}],
"auth": "1122334455",
"id": 2
}
Code:
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"No permissions to call \"usermacro.updateglobal\"."},"id":2}
The API user role has the "event.acknowledge" and "usermacro.*" permissions. (there's no "usermacro.updateglobal" available on the list).
I'm not sure if the issue is related to permissions or an invalid parameter.
Any thoughts?
Comment