我有一个登录脚本如下:
curl --location --request POST 'https://zabbixUrl.com/api_jsonrpc.php' \
--header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "user",
"password": "pass"
},
"id": 1
}'
返回:
{"jsonrpc":"2.0","result":"1g1hd43j4d3jd4jsl4n35b4211n1d2e2","id":1}
有了这个 Api token ( result
),我可以执行所有 Zabbix 的方法,例如:
curl --location --request POST 'https://zabbixUrl.com/api_jsonrpc.php' \
--header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' \
--header 'Content-Type: application/json' \
--data-raw '
{
"jsonrpc": "2.0",
"method": "screenitem.get",
"params": {
"output": "extend",
"screenids": "258"
},
"auth": "1g1hd43j4d3jd4jsl4n35b4211n1d2e2",
"id": 1
}'
现在我正在尝试获取 PNG 格式的图表。在中间屏幕中插入user
和后,我可以以 PNG 格式查看此图:pass
现在我要做的是通过 API 获取这个 PNG 图。我的方法如下(ps:包含的网址与浏览器上使用的网址相同,它确实有效):
curl --header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' --data-raw 'auth:1g1hd43j4d3jd4jsl4n35b4211n1d2e2' http://zabbixUrl.com/chart2.php?graphid=123456&period=604800&stime=1614012539
使用这种形式,我得到一个401 error
. 我猜它没有正确检测到令牌。
因此,我的问题是,如何通过 API 获取这个 Zabbix 图形的 PNG?我该怎么做才能正确检测到令牌?