Ad Widget

Collapse

Problem with API host.create

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitrogene
    Junior Member
    • Dec 2011
    • 1

    #1

    Problem with API host.create

    Hi,

    I'm working on an automate to add host in zabbix. I use API but I have a problem beetween two request very similar.
    The first one is :
    {"jsonrpc":"2.0","method":"host.create","params":{ "host":"localhost","interfaces":{"type":1,"main":1 ,"useip":0,"ip":"127.0.0.1","dns":"localhost","por t":"10050"},"groups":{"groupid":"2"},"templates":{ "templateid":"10001"}},"auth":"ede78a7c25cd00bc3ef acf68a6a04051","id":"13548799648877"}
    and return OK
    {"jsonrpc":"2.0","result":{"hostids":["10147"]},"id":"13548799648877"}
    but the second one :
    {"jsonrpc":"2.0","method":"host.create","params":{ "host":"jkdmsklqxq","interfaces":{"type":1,"main": 1,"useip":0,"ip":"127.0.0.5","dns":"jkdmsklqxq.jms p.prod","port":"10050"},"groups":{"groupid":"27"}, "templates":{"templateid":"10001"}},"auth":"9424af 3de542f831db97c7151fb0fa25","id":"13548800841662"}
    return KO (debug is activated)

    {"jsonrpc":"2.0","error":{"code":-32500,"message":"Application error.","data":"No permissions to referred object or it does not exist!","debug":[{"file":"\/usr\/share\/zabbix\/api\/classes\/CHost.php","line":1318,"function":"exception","cla ss":"CZBXAPI","type":"::","args":[120,"No permissions to referred object or it does not exist!"]},{"file":"\/usr\/share\/zabbix\/api\/classes\/CHost.php","line":1466,"function":"checkInput","cl ass":"CHost","type":"->","args":[[{"host":"jkdmsklqxq","interfaces":{"type":1,"main" :1,"useip":0,"ip":"127.0.0.5","dns":"jkdmsklqxq.jm sp.prod","port":"10050"},"groups":{"groupid":"27"} ,"templates":{"templateid":"10001"},"name":"jkdmsk lqxq"}],"create"]},{"function":"create","class":"CHost","type":"->","args":[{"host":"jkdmsklqxq","interfaces":{"type":1,"main" :1,"useip":0,"ip":"127.0.0.5","dns":"jkdmsklqxq.jm sp.prod","port":"10050"},"groups":{"groupid":"27"} ,"templates":{"templateid":"10001"}}]},{"file":"\/usr\/share\/zabbix\/api\/rpc\/class.czbxrpc.php","line":107,"function":"call_use r_func","args":[[{},"create"],{"host":"jkdmsklqxq","interfaces":{"type":1,"main ":1,"useip":0,"ip":"127.0.0.5","dns":"jkdmsklqxq.j msp.prod","port":"10050"},"groups":{"groupid":"27" },"templates":{"templateid":"10001"}}]},{"file":"\/usr\/share\/zabbix\/api\/rpc\/class.czbxrpc.php","line":65,"function":"callAPI", "class":"czbxrpc","type":"::","args":["host.create",{"host":"jkdmsklqxq","interfaces":{" type":1,"main":1,"useip":0,"ip":"127.0.0.5","dns": "jkdmsklqxq.jmsp.prod","port":"10050"},"groups":{" groupid":"27"},"templates":{"templateid":"10001"}}]},{"file":"\/usr\/share\/zabbix\/api\/rpc\/class.cjsonrpc.php","line":66,"function":"call","c lass":"czbxrpc","type":"::","args":["host.create",{"host":"jkdmsklqxq","interfaces":{" type":1,"main":1,"useip":0,"ip":"127.0.0.5","dns": "jkdmsklqxq.jmsp.prod","port":"10050"},"groups":{" groupid":"27"},"templates":{"templateid":"10001"}} ,"9424af3de542f831db97c7151fb0fa25"]},{"file":"\/usr\/share\/zabbix\/api_jsonrpc.php","line":54,"function":"execute","c lass":"CJSONrpc","type":"->","args":[]}]},"id":"13548800841662"}

    The group is correct and i use superadministrator group for logging so right restriction.

    I don't find what is the mistake between this two requests.

    Somebody have some idea??

    Thank' all lot for your help.
  • Pavels
    Member
    • Oct 2011
    • 83

    #2
    It looks like you don't have write permissions to host group 27.

    Comment

    • Javier
      Member
      Zabbix Certified Specialist
      • Jan 2010
      • 58

      #3
      I use zabbix api from php, and I make a host ...
      PHP Code:
      $host = array(
         
      'host' => "name",
         
      'interfaces' => array(array('type' => 1,'ip' => '0.0.0.0','dns' => "name.localhost",'port' => 10050,'useip' => 0,'main' => 1)),
         
      'groups' => array(array("groupid" => 25),array("groupid" => 115));
         
      'templates' => array(array("templateid" => 9),array("templateid" => 12));
         
      'inventory' => array("type" => "Linux""tag" => "SO");
         
      'inventory_mode' => 0
      );
      $r API::Host()->create($host); 
      In Zabbix 1.8 you can see to use zabbix api here: http://puppetlinux.blogspot.com.es/2...ostcreate.html

      Comment

      Working...