confirm/PhpZabbixApi

Cannot create a host! API ERROR: -32500 No permissions to referred object or it does not exist!

nimafam opened this issue · 7 comments

Hi,
I try to create a host with confirm library, everything works fine ( I mean can create a host group, interfaces and etc) but can not create a host,
here is my code:

hostCreate([ "host" => "Ino", "interfaces" => [ "type" => 1, "main" => 1, "useip" => 1, "ip" => "192.168.3.1", "dns"=> "", "port" => "10050" ], "groups" => [ "groupid" => "35" ], "templates" => [ "templateid" => "10272" ] ]); }catch (\ZabbixApi\Exception $e){ echo $e->getMessage(); } is there anything wrong here? please help me with!

Hi,

please provide zabbix server version.
The user you are using to create host has permissions on that group (groupid = 35)?
Are you still authenticated and passing auth when executing that line of code? Without the rest of your code is not easy to understand that.

Hi,
Zabbix Version is 3.4 and user is Admin so has grant permission in Zabbix.

sorry I forgot to paste the code:

<?php 
require_once (__DIR__) . "/lib/ZabbixApi.class.php";

use ZabbixApi\ZabbixApi;

try {

    $api = new ZabbixApi('http://192.168.1.114/zabbix/api_jsonrpc.php', 'Admin', 'zabbix');

    $api->hostCreate([
        "host" => "Ino",
        "interfaces" => [
            "type" => 1,
            "main" => 1,
            "useip" => 1,
            "ip" => "192.168.3.1",
            "dns"=> "",
            "port" => "10050"
        ],
        "groups" => [
            "groupid" => "35"
        ],
        "templates" => [
            "templateid" => "10272"
        ]
    ]);



}catch (\ZabbixApi\Exception $e){
    echo $e->getMessage();
}

I can easily create host on web interface with this user and I also tried to create a host with python API and it worked well.

I try it locally on Ubuntu 16.04.

This is certainly an issue and a bug. You can add a user to any group below 10 but anything 10 or above it gives a "No permissions to referred object or it does not exist!"

This is not a problem with this API but a problem on Zabbix itself.

See #30 and #36

I am having the same issue with this library, which I just worked around by manually generating the JSON for this specific create host request. I can send the same request via Postman directly to Zabbix API and it works with any groupid as seen below, however when using this library I get that same error.

Here is the working format of JSON body request to create hosts.

{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"proxy_hostid": "10767",
"host": "zs5",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.2.2.2",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "80"
},
{
"groupid": "1"
}

    ],
    	"templates": [
        {
            "templateid": "10772"
        }
    ]		

},
"id": 1,
"auth": "xxxxxxxx.."

}

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.