confirm / PhpZabbixApi

A PHP library for the Zabbix™ JSON-RPC API.
MIT License
114 stars 62 forks source link

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

Closed nimafam closed 3 years ago

nimafam commented 6 years ago

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:

<?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(); }

is there anything wrong here? please help me with!

riogezz commented 6 years ago

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.

nimafam commented 6 years ago

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.

chadmandoo commented 6 years ago

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!"

chadmandoo commented 6 years ago

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

domibarton commented 6 years ago

See #30 and #36

mckayclarey commented 6 years ago

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.."

}

github-actions[bot] commented 3 years ago

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.