6 Replies Latest reply on Oct 23, 2019 1:52 AM by Andrew Waters

    Regex assist

    Ryan Nicosia
      Share This:

      I've got a sync mapping that I want to parse out the 4 - 7 characters to set into a field in CMDB.

       

      I'm having issues with figuring out the regex syntax

       

      Name:  01-abcd-efgh-a-001

       

      What I need is to cut out the abcd value so I can map that to an attribute in CMDB as part of my sync mapping.   I can figure out how to extract the 4th character but can't figure out how to extract the 4 - 7th so I get the entire string.

        • 1. Re: Regex assist
          Andrew Waters

          If you know if it a string you can just use slicing, value[3:7]

          3 of 3 people found this helpful
          • 2. Re: Regex assist
            Ryan Nicosia

            Thanks for the quick assist.  I'm assuming that will be more efficient than this?

             

            regex "^...(....)");

             

            If so, is this the correct syntax?

             

            computersystem.SiteGroup := device_cs.name[3:7];

            • 3. Re: Regex assist
              Danny Fleer

              Yes the syntax is correct. But you should test if the string is really minimum 8 characters long.

               

              if size(computersystem.SiteGroup) >= 8 then
                  computersystem.SiteGroup := device_cs.name[3:7];
              end if;
              2 of 2 people found this helpful
              • 4. Re: Regex assist
                Andrew Waters

                That will cause a failure if the value is not present. Unless you are sure it exist then you need to check if it has a value.

                 

                If you know if exists and the string is not long enough it will just return an empty string.

                2 of 2 people found this helpful
                • 5. Re: Regex assist
                  Ryan Nicosia

                  Alright, so I think I'm about 90% there but running into a use case I can't figure out how to address.

                   

                  I've got another pattern that I'm using to set cdm_company based on first couple of characters in the name of these network devices.  That works fine and I'm only wanting to set site group if cdm_company value has been set.  That is also working fine.  However, there may be an instance, although rare, where the site group does not exist in Remedy.

                   

                  Example below:

                   

                  Failed creation of BMC_ComputerSystem:01-ca01-abcd-a-001-fw-01 : ERROR (44900): ; The Location Information is not valid. Please use the menus provided on the 'Region' and 'Site Group' fields to select this information. (44900)

                   

                  In this "sample", abcd is not a valid site group yet.  Easy fix is just make sure site group exists, but is there a way on the discovery side I can just tell it that if value is not valid on CMDB side, to just ignore?   Probably a silly question.

                   

                  Here is the pattern I'm using

                   

                  28    body

                  29

                  30 device_cs := NetworkDevice_ComputerSystem.device_cs;

                  31 name := text.lower(device_cs.Name);

                  32   device_cs.Name := name;

                  33

                  34    if device.type <> "Access Point" and name has substring "." then

                  35

                  36   device_cs.Name := text.split(name, ".")[0];

                  37

                  38 end if;

                  39   device_cs.Company := device.cdm_company;

                  40    if device.cdm_company then

                  41   device_cs.SiteGroup := device.name[3:7];

                  42    end if;

                  43   

                  44    end body;

                  45

                  46 end syncmapping;

                   

                   

                   

                   

                  • 6. Re: Regex assist
                    Andrew Waters

                    You cannot look up valid entries for values in the CMDB and use them in a syncmapping.

                    1 of 1 people found this helpful