Ad Widget

Collapse

zabbixapi hosts.delete error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbadmin
    Junior Member
    • Jan 2018
    • 22

    #1

    zabbixapi hosts.delete error

    I have an array of 5 host IDs I want to delete. Believe I am forming the request properly but I am getting an error. Zabbix version 3.0

    Here is my line of (ruby) code:
    zbx.hosts.delete(a_hostid)

    and the content of a_hostid, which is an array of strings
    ["10695", "10747", "10769", "10787", "10798"]

    {
    "code": -32500,
    "message": "Application error.",
    "data": "No permissions to referred object or it does not exist!"
    }
    on request:
    {
    "method": "host.delete",
    "params": [
    [
    "10695",
    "10747",
    "10769",
    "10787",
    "10798"
    ]
    ],
    "id": 94763,
    "jsonrpc": "2.0",
    "auth": "ddc51ff311cc3ae0f1f9df48a9661b31"
    }

    I have tried with an array of integers and received the same error.
    Last edited by mbadmin; 27-03-2018, 16:57.
  • mbadmin
    Junior Member
    • Jan 2018
    • 22

    #2
    Still facing this issue. Since I believe my zabbix api usage to be correct, would this make more sense as a bug report? If so, anyone know where I'd file one?

    Comment

    • tcilmo
      Senior Member
      • Nov 2016
      • 122

      #3
      I have not used the API before, but what permissions does it or are you using to access Z? Instead of using the API to delete multiple hosts, just try using it to delete a single host in your list. Make sure it is a host from the list above to make the test as accurate a possible. If you try it on a different host, it is possible it could have different permissions from the ones in your list. Make sense? If that works, you have at least ruled out permissions as your issue.

      Comment

      • mbadmin
        Junior Member
        • Jan 2018
        • 22

        #4
        So according to the documentation, the hosts.delete api should accept an array of host IDs. More here: https://www.zabbix.com/documentation...ce/host/delete

        Of note, the documentation references this as host.delete, but when you change to host.delete, this happens:

        Code:
        test:18:in `<main>': undefined method `host' for #<ZabbixApi:0x0000000000b80038> (NoMethodError)
        Did you mean? hosts
        So I have been using hosts.delete as per the above error.

        I will note I am able to delete the hosts by making an individual API call for each one.

        This does not work and gives a permissions error "No permissions to referred object or it does not exist!":

        Code:
        zbx = ZabbixApi.connect(
        :url => 'http://localhost/zabbix/api_jsonrpc.php',
        :user => 'username',
        :password => 'redacted'
        
        hostid = ["10747", "10695"]
        
        zbx.hosts.delete(hostid)
        ---


        But if I change hostid to simply:

        Code:
        hostid = "10747"

        or even as an integer:

        Code:
        hostid = 10747

        then zbx.hosts.delete(hostid) works just fine. I am just trying to figure out how to pass an array of host IDs in so I don't have to make a bunch of API calls instead of just one.

        Comment

        • DmitryL
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • May 2016
          • 278

          #5
          Looks like you have extra brackets [] in your first post around array.

          Comment

          • mbadmin
            Junior Member
            • Jan 2018
            • 22

            #6
            I don't disagree, but my array is properly created. If there is an extra square bracket that seems out of my control, no?

            Comment

            • vesper1978
              Member
              • Nov 2016
              • 59

              #7
              Code:
               
               hostid = ["10747", "10695"]
              Try changing to

              Code:
               
               hostid = "10747", "10695"

              Comment

              • mbadmin
                Junior Member
                • Jan 2018
                • 22

                #8
                Here's the full output.

                Code:
                [root@server]# /opt/puppetlabs/puppet/bin/ruby test
                /opt/puppetlabs/puppet/lib/ruby/gems/2.4.0/gems/zabbixapi-3.2.1/lib/zabbixapi/client.rb:117:in `_request': Server answer API error (ZabbixApi::ApiError)
                 {
                  "code": -32500,
                  "message": "Application error.",
                  "data": "No permissions to referred object or it does not exist!"
                }
                 on request:
                 {
                  "method": "host.delete",
                  "params": [
                    [
                      "10747",
                      "10695"
                    ]
                  ],
                  "id": 99853,
                  "jsonrpc": "2.0",
                  "auth": "7a1e55ee33d27b8aec3c6ad33b0ad9cb"
                }
                    from /opt/puppetlabs/puppet/lib/ruby/gems/2.4.0/gems/zabbixapi-3.2.1/lib/zabbixapi/client.rb:135:in `api_request'
                    from /opt/puppetlabs/puppet/lib/ruby/gems/2.4.0/gems/zabbixapi-3.2.1/lib/zabbixapi/basic/basic_logic.rb:30:in `delete'
                    from test:19:in `<main>'

                Here's the full script, with username and password "masked"

                Code:
                [root@server]# cat ./test
                require "zabbixapi"
                require 'json'
                require 'rubygems'
                require 'net/https'
                require 'date'
                require 'getoptlong'
                require 'yaml'
                require 'ruby_dig'
                
                zbx = ZabbixApi.connect(
                  :url => 'http://localhost/zabbix/api_jsonrpc.php',
                  :user => 'username',
                  :password => 'redacted'
                )
                
                hostid = "10747", "10695"
                
                zbx.hosts.delete(hostid)

                Comment

                Working...