I'm trying to import a Template to my Zabbix server with Zabbix API, i used this:
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 '.'
Here is the output:
{"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}
I just don't see any error… i tried to use an online parser website but he Don't see any error. This var is directly filled with the export method of Zabbix (in JSON). Here is the content of the file:
{
"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
}
I think that the error is the format of the fileJSON, how to encode this variable in JSON format ?