Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-11906

template.massAdd API endpoint does not return error when empty values given

XMLWordPrintable

    • Icon: Incident report Incident report
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • None
    • 3.0.7, 3.0.8
    • API (A)

      When making calls against the `template.massAdd` endpoint, the API returns no error when run with nil values

      For example, using the zabbixapi gem:

      require "zabbixapi"
      
      zbx = ZabbixApi.connect(
        :url => 'http://localhost/zabbix/api_jsonrpc.php',
        :user => 'Admin',
        :password => 'zabbix'
      )
      
      result = zbx.api_request(
        :method => "template.massAdd",
        :params => {
          :hosts => data[:hosts_id].map { |t| {:hostid => t} },
          :templates => data[:templates_id].map { |t| {:templateid => t} }
        }
      )
      
      puts result
      
      {"templateids"=>[]}
      

      If you specifically give template_ids or host_ids that don't exist, an error is raised as expected:

      data[:hosts_id] = ['1']
      data[:templates_id] = ['1']
      
      result = @client.api_request(
        :method => "template.massAdd",
        :params => {
          :hosts => data[:hosts_id].map { |t| {:hostid => t} },
          :templates => data[:templates_id].map { |t| {:templateid => t} }
        }
      )
      
      puts result
      
      ZabbixApi::ApiError: Server answer API error
       {
        "code": -32500,
        "message": "Application error.",
        "data": "No permissions to referred object or it does not exist!"
      }
       on request:
       {
        "method": "template.massAdd",
        "params": {
          "hosts": [
            {
              "hostid": "1"
            }
          ],
          "templates": [
            {
              "templateid": "1"
            }
          ]
        },
        "id": 93168,
        "jsonrpc": "2.0",
        "auth": "3047835e2bd5be76b69e053724f9baf4"
      }
      

      This appears to be a bug with Zabbix upstream rather than the gem.

      Expected behaviour:

      Zabbix returns Application error when given no IDs for server_id or template_id

            Unassigned Unassigned
            petems Peter Souter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: