I am trying to get the Zabbix HTTP Agent item configured to pull API data from my Zabbix server through my proxy.
1. I have written a script in python to use the Zabbix API and it returns the expected data. Along with a json formatted response this is the script output "Number of problems with tags 'device=camera' and 'status=offline' and 'technician=belair': 22"
import requests
import json
# Replace with your Zabbix server URL and credentials
zabbix_url = "http://myserver.yisd.net/zabbix/api_jsonrpc.php"
api_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx"
# Headers for the request
headers = {
'Content-Type': 'application/json-rpc',
'Authorization': f'Bearer {api_token}'
}
# Data for the request
data = {
'jsonrpc': '2.0',
'method': 'problem.get',
'params': {
'output': 'extend',
'selectTags': 'extend',
'tags': [
{'tag': 'status', 'value': 'offline'},
{'tag': 'technician', 'value': 'delvalle'},
{'tag': 'device', 'value': 'camera'}
]
},
'id': 1
}
# Send the request
response = requests.post(zabbix_url, headers=headers, json=data)
# Check for errors
if response.status_code != 200:
print(f"Error: {response.status_code}")
# print(response.json())
else:
response_json = response.json()
if 'error' in response_json:
print(f"API Error: {response_json['error']}")
else:
problems = response_json.get('result', [])
print(f"Number of problems with tags 'status=offline' and 'technician=belair': {len(problems)}")
# print(response.json())
2. However if I take the same json response body from my python script and use it for my HTTP Agent item it only returns this result {}. Here is my complete json response body being used
{
"jsonrpc": "2.0",
"method": "problem.get",
"params": {
"output": "extend",
"countOutput": "true",
"selectTags": "extend",
"tags": [
{"tag": "status", "value": "offline"},
{"tag": "technician", "value": "delvalle"},
{"tag": "device", "value": "camera"}
]
}
}
Screenshots of my HTTP Agent configuration


This is the result using the HTTP Agent item test button

3. I have tried performing an API request using curl for something very basic and for my failing json request body on the same proxy server
This curl version of my request returns an error
curl --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0", "method": "problem.get", "params": { "username": "zabbixapi_ro", "password": "xxxxxxxxxxxxxx", "output": "extend", "countOutput": "true", "selectTags": "extend", "tags": [{"tag": "status", "value": "offline"}, "tag": "technician", "value": "delvalle"},{"tag": "device", "value": "camera"}]},"id":1}' "http://zabbix1.yisd.net/zabbix/api_jsonrpc.php"
Returns this error
{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}
This curl command on my proxy returns the expected result
curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0", "method": "user.login", "params": {"username": "zabbixapi_ro", "password": "xxxxxxxxxxxxxxx"}, "id": 1}' "http://myserver.yisd.net/zabbix/api_jsonrpc.php"
Good Result
{"jsonrpc":"2.0","result":"xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxx","id":1}zabbix@zabbixproxy2
This has led me to believe that I am missing some configuration requirement in the HTTP Agent configuration page. I have tried every possible variation from documentation and so at this point I am hoping just another set of eyes will be helpful.
1. I have written a script in python to use the Zabbix API and it returns the expected data. Along with a json formatted response this is the script output "Number of problems with tags 'device=camera' and 'status=offline' and 'technician=belair': 22"
import requests
import json
# Replace with your Zabbix server URL and credentials
zabbix_url = "http://myserver.yisd.net/zabbix/api_jsonrpc.php"
api_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx xxxxxxxxxxxxxxx"
# Headers for the request
headers = {
'Content-Type': 'application/json-rpc',
'Authorization': f'Bearer {api_token}'
}
# Data for the request
data = {
'jsonrpc': '2.0',
'method': 'problem.get',
'params': {
'output': 'extend',
'selectTags': 'extend',
'tags': [
{'tag': 'status', 'value': 'offline'},
{'tag': 'technician', 'value': 'delvalle'},
{'tag': 'device', 'value': 'camera'}
]
},
'id': 1
}
# Send the request
response = requests.post(zabbix_url, headers=headers, json=data)
# Check for errors
if response.status_code != 200:
print(f"Error: {response.status_code}")
# print(response.json())
else:
response_json = response.json()
if 'error' in response_json:
print(f"API Error: {response_json['error']}")
else:
problems = response_json.get('result', [])
print(f"Number of problems with tags 'status=offline' and 'technician=belair': {len(problems)}")
# print(response.json())
2. However if I take the same json response body from my python script and use it for my HTTP Agent item it only returns this result {}. Here is my complete json response body being used
{
"jsonrpc": "2.0",
"method": "problem.get",
"params": {
"output": "extend",
"countOutput": "true",
"selectTags": "extend",
"tags": [
{"tag": "status", "value": "offline"},
{"tag": "technician", "value": "delvalle"},
{"tag": "device", "value": "camera"}
]
}
}
Screenshots of my HTTP Agent configuration
This is the result using the HTTP Agent item test button
3. I have tried performing an API request using curl for something very basic and for my failing json request body on the same proxy server
This curl version of my request returns an error
curl --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0", "method": "problem.get", "params": { "username": "zabbixapi_ro", "password": "xxxxxxxxxxxxxx", "output": "extend", "countOutput": "true", "selectTags": "extend", "tags": [{"tag": "status", "value": "offline"}, "tag": "technician", "value": "delvalle"},{"tag": "device", "value": "camera"}]},"id":1}' "http://zabbix1.yisd.net/zabbix/api_jsonrpc.php"
Returns this error
{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}
This curl command on my proxy returns the expected result
curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc": "2.0", "method": "user.login", "params": {"username": "zabbixapi_ro", "password": "xxxxxxxxxxxxxxx"}, "id": 1}' "http://myserver.yisd.net/zabbix/api_jsonrpc.php"
Good Result
{"jsonrpc":"2.0","result":"xxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxx","id":1}zabbix@zabbixproxy2
This has led me to believe that I am missing some configuration requirement in the HTTP Agent configuration page. I have tried every possible variation from documentation and so at this point I am hoping just another set of eyes will be helpful.
Comment