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

configuration.import, Importing a host causes an error (selectParentTemplates) if the host already exists

    XMLWordPrintable

Details

    • Problem report
    • Status: Confirmed
    • Major
    • Resolution: Unresolved
    • 6.2.2, 6.2.3, 6.4.0beta2
    • None
    • API (A)
    • None
    • docker containers

    Description

      Create Zabbix with these containers: * zabbix/zabbix-server-pgsql

      • zabbix/zabbix-web-nginx-pgsql

       
      Create data to import the host (you can use the "zabbix-web" container):

      cat > test.yaml <<-EOF
      zabbix_export:
        version: '6.4'
        date: '2022-10-10T12:26:24Z'
        host_groups:
          -
            uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
            name: Applications
        hosts:
          -
            host: test
            name: test
            templates:
              -
                name: 'Apache by HTTP'
            groups:
              -
                name: Applications
            interfaces:
              -
                type: SNMP
                port: '161'
                details:
                  community: '{$SNMP_COMMUNITY}'
                interface_ref: if1
            inventory_mode: DISABLED
      EOF
      

       
      Import host data:

      apk add jq
      
      ZABBIX_API_HOST="${ZABBIX_API_HOST:-zabbix-web}"
      ZABBIX_USER="${ZABBIX_USER:-Admin}"
      ZABBIX_PASSWORD="${ZABBIX_PASSWORD:-zabbix}"
      
      zabbixApiRequest() {
      	curl \
      		--url "http://${ZABBIX_API_HOST}:8080/api_jsonrpc.php" \
      		--header 'Content-Type: application/json-rpc' \
      		--request POST \
      		--data @- \
      		--silent \
      	| jq \
      		--raw-output "${raw_output}"
      }
      
      get_auth() {
      	local raw_output='.result'
      	zabbixApiRequest <<-EOF
      		{
      			"jsonrpc": "2.0",
      			"method": "user.login",
      			"params": {
      				"user": "${ZABBIX_USER}",
      				"password": "${ZABBIX_PASSWORD}"
      			},
      			"id": ${RANDOM}
      		}
      	EOF
      }
      
      configurationImport() {
      	zabbixApiRequest <<-EOF
      		{
      			"jsonrpc": "2.0",
      			"method": "configuration.import",
      			"params": {
      				"format": "yaml",
      				"rules": {
      					"discoveryRules": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"graphs": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"host_groups": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"template_groups": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"hosts": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"httptests": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"images": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"items": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"maps": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"mediaTypes": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"templateLinkage": {
      						"createMissing": true,
      						"deleteMissing": true
      					},
      					"templates": {
      						"createMissing": true,
      						"updateExisting": true
      					},
      					"templateDashboards": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"triggers": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					},
      					"valueMaps": {
      						"createMissing": true,
      						"updateExisting": true,
      						"deleteMissing": true
      					}
      				},
      				"source": "$(
      					sed \
      						"${1}" \
      						--expression ':a ; N ; $!ba ; s/\n/\\n/g' \
      						--expression 's/"/\\"/g'
      				)"
      			},
      			"auth": "${auth}",
      			"id": ${RANDOM}
      		}
      	EOF
      }
      
      # Authentication:
      auth=$( get_auth )
      
      # First try:
      configurationImport test.yaml
      
      # Second try:
      configurationImport test.yaml
      

       
      The first attempt is successful:

       

      {
        "jsonrpc": "2.0",
        "result": true,
        "id": 4111
      }
      

       
      But the second attempt calls for an error:

      {
        "jsonrpc": "2.0",
        "error": {
          "code": -32602,
          "message": "Invalid params.",
          "data": "Invalid parameter \"/selectParentTemplates/1\": value must be one of \"templateid\", \"host\", \"name\", \"description\", \"uuid\", \"link_type\"."
        },
        "id": 17414
      }
      

       
      The workaround is to change the `templateLinkage` parameters of the `configuration.import` method to:

      "templateLinkage": {
        "createMissing": true,
        "deleteMissing": false
      },
      

       
      But this is not a workaround when you need to maintain a clear configuration match.

      Attachments

        Activity

          People

            zabbix.dev Zabbix Development Team
            nnlkcncff Vasiliy Nikonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: