Ad Widget

Collapse

UUID when importing new items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mseemann
    Junior Member
    • Aug 2022
    • 3

    #1

    UUID when importing new items

    when i try to set a (huge bunch of items, which i do not want to configure manually), the import does not like it:
    Invalid tag "/zabbix_export/templates/template(1)/items/item(1)": the tag "uuid" is missing.
    However, the docs say it is generated if missing: "Universal unique identifier, used for linking imported item to already existing ones. Used only for items on templates. Auto-generated, if not given."
    If this is not working, can someone point out how to create one? randomly using 0-9a-z does not work
  • stu_net
    Junior Member
    • Oct 2022
    • 2

    #2
    Hi,

    The thing is that all new items/templates whatever need to have unique uuid's.

    I had a similar challenge. I tried to export an existing template, add a lot of items and reimport. What I did:
    Use a UUID (V4) generator like uuidgenerator.net
    Copy a bulk number of UUIDs
    Use text editor like Sublime to multi edit and copy
    Per UUID remove the - characters to get plain 32 characters
    Import the template and done


    Comment

    • thisjrodriguez
      Junior Member
      • Aug 2023
      • 1

      #3
      Hello,

      I know this article is a year old, but it has no answer and I am here to give it.​

      I have generated a PHP code that changes all the UUIDs for you to upload.

      Just set your .yaml as old.yaml, run the php and it will create a new.yaml.

      If you want a saas version, let me know.​

      PHP Code:
      <?php

          
      //content
          
      $content file_get_contents('old.yaml');
          
      $content preg_replace_callback("|uuid: (.*)\n|U", function ($matches) { return "uuid: ".str_replace('-'''generateUUIDv4())."\n"; }, $content);
          
          
      $fp fopen("new.yaml""w");
          
      fwrite($fp$content);
          
      fclose($fp);
              
          
          function 
      generateUUIDv4() {
              
      $data random_bytes(16);

              
      // Set version (4) and variant (2) bits
              
      $data[6] = chr(ord($data[6]) & 0x0f 0x40);
              
      $data[8] = chr(ord($data[8]) & 0x3f 0x80);

              
      // Convert binary data to hexadecimal format
              
      $uuid vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($data), 4));

              return 
      $uuid;
          }


          echo 
      $content
          

      ?>

      Comment

      • Roberto Machado
        Junior Member
        • Jun 2020
        • 11

        #4
        Try this:

        HTML Code:
        # Define the file path
        $filePath = "C:\path\to\your\file.yaml"
        
        # Read the file content
        $content = Get-Content $filePath -Raw
        
        # Define the regex pattern to find UUIDs
        $pattern = '(?<=uuid:\s)[0-9a-f]{32}'
        
        # Function to generate a new UUID
        function New-UUID {
        return [guid]::NewGuid().ToString('N')
        }
        
        # Replace all found UUIDs with new ones
        $newContent = [regex]::Replace($content, $pattern, { param($match) New-UUID })
        
        # Write the modified content back to the file
        $newContent | Set-Content $filePath -NoNewline
        
        Write-Host "UUIDs successfully replaced in file $filePath"

        Comment

        • uniken1
          Member
          • Sep 2012
          • 91

          #5
          Im use Notepad++ with plugin PythonScript and simple script for regenerate uuid
          Code:
          import uuid
          
          def calculate(match):
              IdNew = str(uuid.uuid4()).replace("-", "")
              return '- uuid: ' + IdNew
              
          editor.rereplace(r'- uuid: [A-Za-z0-9]+', calculate)

          Comment

          Working...