Ad Widget

Collapse

Zabbix XML import via API does not create host groups

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MJ@1234
    Junior Member
    • Sep 2017
    • 6

    #1

    Zabbix XML import via API does not create host groups

    Hi All, I'm having an issue in Zabbix 6.4 where we are using a script to import an XML of hosts but it's not creating the missing host groups automatically. The import works great for any hosts we import that we are adding to existing host groups.

    Error is: @{code=-32500; message=Application error.; data=Group "Clients/Client1" for host "test-host" does not exist.}

    Below is an example of my XML file host section

    Code:
    <hosts>
    <host>
    <host>test-host</host>
    <name>test-host</name>
    <status>ENABLED</status>
    <templates>
    <template>
    <name>ICMP Ping</name>
    </template>
    </templates>
    <groups>
    <group>
    <name>Routers - External</name>
    </group>
    <group>
    <name>Clients/Client1</name>
    </group>
    </groups>
    <interfaces>
    <interface>
    <ip>1.1.1.1</ip>
    <port>0</port>
    <interface_ref>if1</interface_ref>
    </interface>
    </interfaces>
    <inventory>
    <serialno_a>ABCDEFGHIJKL</serialno_a>
    <location_lat>-39.004519</location_lat>
    <location_lon>147.284774</location_lon>
    </inventory>
    </host>​
    The import script uses import params as follows (AUTHGUID is an actual string in my script):

    Code:
    $importparams= @{
    jsonrpc = "2.0"
    method = "configuration.import"
    params = @{
    format = "xml"
    rules = @{
    host_groups = @{
    updateExisting = $true
    createMissing = $true
    }
    hosts = @{
    updateExisting = $true
    createMissing = $true
    }
    templateLinkage = @{
    createMissing = $true
    }
    valueMaps = @{
    updateExisting = $true
    createMissing = $true
    }
    }
    source = "$xmlfile"
    }
    auth ="<AUTHGUID>"
    id = 5
    }

    Any help would be much appricated as my understanding was that having the following section would make this work?

    (Documentation Ref: https://www.zabbix.com/documentation...uration/import)

    Code:
    host_groups = @{
    updateExisting = $true
    createMissing = $true
    }​​
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Sorry about my ignorant question but ... Shouldn't it be just true, not $true ?? Or should you declare somewhere that value for it, like for source and format..

    Comment

    • MJ@1234
      Junior Member
      • Sep 2017
      • 6

      #3
      Thanks cyber I was just following the other sections that worked like the hosts, templatelinkage etc. They seem to be OK with $true. But I'll try with just true and report back.

      Comment

      • MJ@1234
        Junior Member
        • Sep 2017
        • 6

        #4
        cyber, gave that a go but it is expecting $true according to this error:

        Code:
        Error is: @{code=-32602; message=Invalid params.; data=Invalid parameter "/rules/host_groups/createMissing": a boolean is expected.}
        Return code is: -32602​

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #5
          "createMissing": true
          vs "
          "createMissing"= true

          ??

          TBH, I am not good at any codewriting, so I may aswell talk sh... here..

          Comment

          • MJ@1234
            Junior Member
            • Sep 2017
            • 6

            #6
            Have re-visited this issue as we are still having trouble getting the import API to create host groups.
            I have tried editing the file "/usr/share/zabbix/include/classes/import/CConfigurationImport.php" this has the defaults for the host_groups import set to false and changing those to true as per snippet below. Restarted server & tested again, no luck

            Code:
            $default_options = [
            'template_groups' => ['updateExisting' => false, 'createMissing' => false],
            'templates' => ['updateExisting' => false, 'createMissing' => false],
            'host_groups' => ['updateExisting' => true, 'createMissing' => true],
            'hosts' => ['updateExisting' => false, 'createMissing' => false],
            This has really got me stumped as host creation​ works fine if the host_group already exists. the options are there to create host_groups but they don't work.

            Does anyone know where I can fid good logging on this so I can see if there is any helpful data returned apart form what i'm getting from my PowerShell script Output?

            Comment

            Working...