【发布时间】:2020-02-18 10:20:45
【问题描述】:
我正在尝试使用 Zabbix API 将模板导入我的 Zabbix 服务器,我使用了这个:
fileJSON=\""$(cat template_file)"\"
curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
"jsonrpc": "2.0",
"method": "configuration.import",
"params": {
"format": "json",
"rules": {
"templates": {
"createMissing": true,
"updateExisting": true
}
},
"source": $fileJSON
},
"auth": "6a977cd94b26b6156698459ac4d0f769",
"id": 1
}' 'http://127.0.0.1/zabbix/api_jsonrpc.php' | jq '.'
这是输出:
{"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}
我只是没有看到任何错误……我尝试使用在线解析器网站,但他没有看到任何错误。 这个var直接填充了Zabbix的导出方式(JSON格式)。 这是文件的内容:
{
"jsonrpc": "2.0",
"result": "{\"zabbix_export\":{\"version\":\"4.4\",\"date\":\"2020-02-18T08:47:31Z\",\"groups\":[{\"name\":\"System\"}],\"templates\":[{\"template\":\"Template Systeme\",\"name\":\"Template Systeme\",\"groups\":[{\"name\":\"System\"}],\"discovery_rules\":[{\"name\":\"D\\u00e9couverte des services\",\"key\":\"service.discovery\",\"delay\":\"30s\"}]}]}}",
"id": 1
}
我认为错误是fileJSON的格式,如何将这个变量编码为JSON格式?
【问题讨论】:
-
作为一个建议,您为什么不在将 JSON 放入 Curl 之前创建它,以便检查其有效性?