Below is the API call which works perfectly while adding a host via API Call.
curl -H "Content-type: application/json-rpc" -X POST http://xyz.com/zabbix/api_jsonrpc.php -d'
{
"jsonrpc": "2.0",
"method": "configuration.import",
"params": {
"format": "xml",
"rules": {
"valueMaps": {
"createMissing": true,
"updateExisting": false
},
"hosts": {
"createMissing": true,
"updateExisting": true
},
"items": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
}
},
"source": "<?xml version="1.0" encoding="UTF-8"?>\n<zabbix_export><version>5.4</version><date>2021-10-06T04:07:43Z</date><groups><group><uuid>48f2bbf98cdb402c90252c76 424b35f3</uuid><name>test servers</name></group></groups><hosts><host><host>testh</host><name>testh</name><groups><group><name>test servers</name></group></groups><interfaces><interface><ip>1.1.1.1</ip><interface_ref>if1</interface_ref></interface></interfaces><inventory_mode>DISABLED</inventory_mode></host></hosts></zabbix_export>"
},
"auth": "xxxx",
"id": 1
}'
I get an error if I try to add the template in above API call as shown below. I get an error as "Template "TemplateModuleICMPPing" for host "test host" does not exist." My requirement is to create a host and attach the templates to that host with single API Call. Please help to resolve the issue.
curl -H "Content-type: application/json-rpc" -X POST http://xyz.com/zabbix/api_jsonrpc.php -d'
{
"jsonrpc": "2.0",
"method": "configuration.import",
"params": {
"format": "xml",
"rules": {
"valueMaps": {
"createMissing": true,
"updateExisting": false
},
"hosts": {
"createMissing": true,
"updateExisting": true
},
"templates": {
"createMissing": true,
"updateExisting": true
},
"items": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
}
},
"source": "<?xml version="1.0" encoding="UTF-8"?>\n<zabbix_export><version>5.4</version><date>2020-03-13T15:31:45Z</date><groups><group><uuid>6f6799aa69e844b4b3918f77 9f2abf08</uuid><name>test servers</name></group></groups><hosts><host><host>test host</host><name>test host</name><templates><template><name>TemplateModuleICMP Ping</name></template></templates><groups><group><name>test servers</name></group></groups><interfaces><interface><interface_ref>if1</interface_ref></interface></interfaces><items><item><name>Item</name><key>item.key</key><delay>30s</delay><valuemap><name>Host status</name></valuemap><interface_ref>if1</interface_ref><request_method>POST</request_method></item></items><valuemaps><valuemap><name>Host status</name><mappings><mapping><value>0</value><newvalue>Up</newvalue></mapping><mapping><value>2</value><newvalue>Unreachable</newvalue></mapping></mappings></valuemap></valuemaps></host></hosts></zabbix_export>"
},
"auth": "xxxx",
"id": 1
}'
curl -H "Content-type: application/json-rpc" -X POST http://xyz.com/zabbix/api_jsonrpc.php -d'
{
"jsonrpc": "2.0",
"method": "configuration.import",
"params": {
"format": "xml",
"rules": {
"valueMaps": {
"createMissing": true,
"updateExisting": false
},
"hosts": {
"createMissing": true,
"updateExisting": true
},
"items": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
}
},
"source": "<?xml version="1.0" encoding="UTF-8"?>\n<zabbix_export><version>5.4</version><date>2021-10-06T04:07:43Z</date><groups><group><uuid>48f2bbf98cdb402c90252c76 424b35f3</uuid><name>test servers</name></group></groups><hosts><host><host>testh</host><name>testh</name><groups><group><name>test servers</name></group></groups><interfaces><interface><ip>1.1.1.1</ip><interface_ref>if1</interface_ref></interface></interfaces><inventory_mode>DISABLED</inventory_mode></host></hosts></zabbix_export>"
},
"auth": "xxxx",
"id": 1
}'
I get an error if I try to add the template in above API call as shown below. I get an error as "Template "TemplateModuleICMPPing" for host "test host" does not exist." My requirement is to create a host and attach the templates to that host with single API Call. Please help to resolve the issue.
curl -H "Content-type: application/json-rpc" -X POST http://xyz.com/zabbix/api_jsonrpc.php -d'
{
"jsonrpc": "2.0",
"method": "configuration.import",
"params": {
"format": "xml",
"rules": {
"valueMaps": {
"createMissing": true,
"updateExisting": false
},
"hosts": {
"createMissing": true,
"updateExisting": true
},
"templates": {
"createMissing": true,
"updateExisting": true
},
"items": {
"createMissing": true,
"updateExisting": true,
"deleteMissing": true
}
},
"source": "<?xml version="1.0" encoding="UTF-8"?>\n<zabbix_export><version>5.4</version><date>2020-03-13T15:31:45Z</date><groups><group><uuid>6f6799aa69e844b4b3918f77 9f2abf08</uuid><name>test servers</name></group></groups><hosts><host><host>test host</host><name>test host</name><templates><template><name>TemplateModuleICMP Ping</name></template></templates><groups><group><name>test servers</name></group></groups><interfaces><interface><interface_ref>if1</interface_ref></interface></interfaces><items><item><name>Item</name><key>item.key</key><delay>30s</delay><valuemap><name>Host status</name></valuemap><interface_ref>if1</interface_ref><request_method>POST</request_method></item></items><valuemaps><valuemap><name>Host status</name><mappings><mapping><value>0</value><newvalue>Up</newvalue></mapping><mapping><value>2</value><newvalue>Unreachable</newvalue></mapping></mappings></valuemap></valuemaps></host></hosts></zabbix_export>"
},
"auth": "xxxx",
"id": 1
}'