[ZBX-4601] API Host.create() seems to be not working Created: 2012 Feb 03  Updated: 2017 May 30  Resolved: 2012 Feb 13

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 1.9.9 (beta)
Fix Version/s: None

Type: Incident report Priority: Blocker
Reporter: Sergey Syreskin Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: api
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

RHEL 5 clone, PostgreSQL 8.4, Perl 5.8.8 + Perl-JSON-RPC-0.96 + Perl-JSON-2.51



 Description   

I am trying to create a host in 1.9.9 using Zabbix API, but it fails.

Here is my JSON-RPC object:
{
"params" : {
"interfaces" : [

{ "useip" : 1, "ip" : "10.1.2.3", "type" : 1, "port" : 10050 }

,

{ "useip" : 1, "ip" : "10.1.2.3", "type" : 2, "port" : 161 }

],
"groups" : [

{ "groupid" : "11" }

],
"templates" : [

{ "templateid" : "10049" }

],
"host" : "myhost1"
},
"auth" : "f201fa9018f8f59fca8aea5577aab156",
"jsonrpc" : "2.0",
"method" : "host.create",
"id" : 7
}

I get the following error message:
In create_host: Error:

{"data":"Incorrect arguments passed to function","message":"Invalid params.","code":-32602}

I have double checked that group and template ids do exist. I guess this might be a typo or brackets issue, but I can't find it.

Host.create() call worked for me flawlessly in 1.8. I modified it for use with 1.9 according to this manual: http://www.zabbix.com/documentation/2.0/manual/appendix/api/host/create

I'm very sorry if I have overlooked something, and this error is caused by my mistake, please forgive me in that case.



 Comments   
Comment by Sergey Syreskin [ 2012 Feb 06 ]

By debugging Zabbix API I have figured out, that fields "main" and "dns" are mandatory in the "interfaces" section. However, after adding the above fields to my JSON request, I get another error: "You do not have permission to perform this operation". The user, that connects to Zabbix API is a member of the "Zabbix administrators" group and is a Zabbix Super-Administrator, so the problem seems to be in permission check routines.

So two issues should be fixed:
1) Zabbix 2.0 documentation at the page http://www.zabbix.com/documentation/2.0/manual/appendix/api/host/create
2) Zabbix user permission checks for API access

Comment by Sergey Syreskin [ 2012 Feb 06 ]

This issue is probably related to https://support.zabbix.com/browse/ZBX-1721

Comment by Sergey Syreskin [ 2012 Feb 06 ]

Here is the debug message, that appears after I turn on debuging for Zabbix API user:

In create_host: Error: {"debug":[

{"function":"exception","args":[120,"You do not have permission to perform this operation"],"file":"/usr/share/zabbix/api/classes/class.ctriggerprototype.php","type":"::","class":"CZBXAPI","line":1581}

,{"function":"syncTemplates","args":[

{"templateids":"10049","hostids":"10052"}

],"file":"/usr/share/zabbix/api/classes/class.ctemplate.php","type":"->","class":"CTriggerPrototype","line":1892},

{"function":"link","args":[["10049"],["10052"]],"file":"/usr/share/zabbix/api/classes/class.ctemplate.php","type":"->","class":"CTemplate","line":1299}

,{"function":"massAdd","args":[{"hosts":[{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"name":"noname_1.mysite.org","groups":[

{"groupid":"11"}

],"hostid":"10052","host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]}],"templates":[

{"templateid":"10049"}

]}],"file":"/usr/share/zabbix/api/classes/class.chost.php","type":"->","class":"CTemplate","line":1630},{"function":"massAdd","args":[{"hosts":{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"name":"noname_1.mysite.org","groups":[

{"groupid":"11"}

],"hostid":"10052","host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]},"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"templates":[

{"templateid":"10049"}

]}],"file":"/usr/share/zabbix/api/classes/class.chost.php","type":"->","class":"CHost","line":1512},{"function":"create","args":[{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"groups":[

{"groupid":"11"}

],"host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]}],"type":"->","class":"CHost"},{"function":"call_user_func","args":[[{},"create"],{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"groups":[

{"groupid":"11"}

],"host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]}],"file":"/usr/share/zabbix/api/rpc/class.czbxrpc.php","line":105},{"function":"callAPI","args":["host.create",{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"groups":[

{"groupid":"11"}

],"host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]}],"file":"/usr/share/zabbix/api/rpc/class.czbxrpc.php","type":"::","class":"czbxrpc","line":63},{"function":"call","args":["host.create",{"interfaces":[

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":1,"port":10050,"main":1}

,

{"dns":"noname_1.mysite.org","useip":1,"ip":"10.1.2.3","type":2,"port":161,"main":1}

],"groups":[

{"groupid":"11"}

],"host":"noname_1.mysite.org","templates":[

{"templateid":"10049"}

]},"7cc6b770a861fed3bb5a5363247741c7"],"file":"/usr/share/zabbix/api/rpc/class.cjsonrpc.php","type":"::","class":"czbxrpc","line":66},

{"function":"execute","args":[],"file":"/usr/share/zabbix/api_jsonrpc.php","type":"->","class":"CJSONrpc","line":54}

],"data":"You do not have permission to perform this operation","message":"Application error.","code":-32500}

Comment by Sergey Syreskin [ 2012 Feb 06 ]

I have tried to log in with API user account to Zabbix web interface and create a host with the same parameters. Here is the error message:

  • Created: Item "ICMP Ping: задержка" on "myhost".
  • Created: Trigger "Доступность по IP" on "myhost".
  • pg_escape_string() expects parameter 1 to be string, array given [include/db.inc.php:631]
  • pg_escape_string() expects parameter 1 to be string, array given [include/db.inc.php:631]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: syntax error at or near "," LINE 1: ...name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array) ^ [include/db.inc.php:500]
  • Error in query [INSERT INTO auditlog_details (auditdetailid,auditid,table_name,field_name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array)] [ERROR: syntax error at or near "," LINE 1: ...name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array) ^]
  • Updated: Trigger "Доступность по IP" on "myhost".
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT h.*,f.triggerid FROM hosts h,functions f,items i WHERE h.hostid BETWEEN 000000000000000 AND 099999999999999 AND h.status=3 AND (f.triggerid IN ('13215')) AND h.hostid=i.hostid AND f.itemid=i.itemid AND f.triggerid BETWEEN 000000000000000 AND 099999999999999] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT t.triggerid,t.description FROM triggers t WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND ( (t.templateid IN ('13215')) AND (t.flags IN ('0','4')) )] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT h.hostid,h.name,f.triggerid FROM hosts h,functions f,items i WHERE 1=0 AND h.hostid=i.hostid AND f.itemid=i.itemid AND f.triggerid BETWEEN 000000000000000 AND 099999999999999 AND h.status I * Created: Item "ICMP Ping: задержка" on "myhost".
  • Created: Trigger "Доступность по IP" on "myhost".
  • pg_escape_string() expects parameter 1 to be string, array given [include/db.inc.php:631]
  • pg_escape_string() expects parameter 1 to be string, array given [include/db.inc.php:631]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: syntax error at or near "," LINE 1: ...name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array) ^ [include/db.inc.php:500]
  • Error in query [INSERT INTO auditlog_details (auditdetailid,auditid,table_name,field_name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array)] [ERROR: syntax error at or near "," LINE 1: ...name,oldvalue,newvalue) VALUES (9,77,'','hosts',Array,Array) ^]
  • Updated: Trigger "Доступность по IP" on "myhost".
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT h.*,f.triggerid FROM hosts h,functions f,items i WHERE h.hostid BETWEEN 000000000000000 AND 099999999999999 AND h.status=3 AND (f.triggerid IN ('13215')) AND h.hostid=i.hostid AND f.itemid=i.itemid AND f.triggerid BETWEEN 000000000000000 AND 099999999999999] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT t.triggerid,t.description FROM triggers t WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND ( (t.templateid IN ('13215')) AND (t.flags IN ('0','4')) )] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT h.hostid,h.name,f.triggerid FROM hosts h,functions f,items i WHERE 1=0 AND h.hostid=i.hostid AND f.itemid=i.itemid AND f.triggerid BETWEEN 000000000000000 AND 099999999999999 AND h.status IN (0,1,3)] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT t.triggerid,t.templateid,i.hostid FROM triggers t,functions f,items i WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND (i.hostid IN ('10049')) AND f.triggerid=t.triggerid AND f.itemid=i.itemid AND ( (t.flags IN ('0','4')) )] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT td.triggerid_up,td.triggerid_down FROM trigger_depends td WHERE 1=0 ] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT t.triggerid,h.name AS hostname,h.host,h.hostid FROM triggers t,functions f,items i,hosts h WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND 1=0 AND ( (t.flags IN ('0','4')) ) AND f.triggerid=t.triggerid AND f.itemid=i.itemid AND h.hostid=i.hostid] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT h.hostid FROM hosts h WHERE (h.hostid IN ('10052')) AND h.hostid BETWEEN 000000000000000 AND 099999999999999 AND h.status IN (0,1,3)] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • You do not have permission to perform this operation [CHost.create -> CHost.massAdd -> CTemplate.massAdd -> CTemplate.link -> CTriggerPrototype.syncTemplates]N (0,1,3)] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT t.triggerid,t.templateid,i.hostid FROM triggers t,functions f,items i WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND (i.hostid IN ('10049')) AND f.triggerid=t.triggerid AND f.itemid=i.itemid AND ( (t.flags IN ('0','4')) )] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT td.triggerid_up,td.triggerid_down FROM trigger_depends td WHERE 1=0 ] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT DISTINCT t.triggerid,h.name AS hostname,h.host,h.hostid FROM triggers t,functions f,items i,hosts h WHERE t.triggerid BETWEEN 000000000000000 AND 099999999999999 AND 1=0 AND ( (t.flags IN ('0','4')) ) AND f.triggerid=t.triggerid AND f.itemid=i.itemid AND h.hostid=i.hostid] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: current transaction is aborted, commands ignored until end of transaction block [include/db.inc.php:430]
  • Error in query [SELECT h.hostid FROM hosts h WHERE (h.hostid IN ('10052')) AND h.hostid BETWEEN 000000000000000 AND 099999999999999 AND h.status IN (0,1,3)] [ERROR: current transaction is aborted, commands ignored until end of transaction block]
  • pg_fetch_assoc() expects parameter 1 to be resource, boolean given [include/db.inc.php:565]
  • pg_free_result(): supplied argument is not a valid PostgreSQL result resource [include/db.inc.php:566]
  • You do not have permission to perform this operation [CHost.create -> CHost.massAdd -> CTemplate.massAdd -> CTemplate.link -> CTriggerPrototype.syncTemplates]

Host creation succeeds without linking a host to template both through JSON RPC and web interface. So the problem actually is linking templates to hosts.

Comment by Sergey Syreskin [ 2012 Feb 06 ]

This issue is related to https://support.zabbix.com/browse/ZBX-4615

Comment by Alexei Vladishev [ 2012 Feb 13 ]

It is a duplicate of ZBX-4605.

Generated at Sat Aug 02 09:51:16 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.