2 Replies Latest reply on Aug 27, 2019 1:40 AM by Andrew Waters

    associate Host to Location using "Scanned Via"

    Eric Plunk
      Share This:

      BMC Discovery 11.1

       

      I found Host to Location Mapping , but I'm not sure if it fits exactly our goal.

       

      Locations are already created within BMC Discovery.  67% of our Hosts are in a data center, which has IP Ranges 10.116.0.0/15 and 10.192.0.0/16.

       

      The goal is any discovered Host with an IP Address in either range is assigned to the data center location.

       

      I tried associating subnets to locations, but this did not propagate to the Hosts like I hoped.

       

      How do I create a pattern (or modify existing one) that associates a Host with this location upon discovery?

       

      Thanks.

        • 1. Re: associate Host to Location using "Scanned Via"
          Brian Morris

          Hey Eric, This might work for you. I haven't fully tested it, but it compiles. It assumes you've created custom categories for your locations in Discovery, and you have DC1, DC2, and Unknown created. You could also modify this to loop through IPV4 or IPV6 if desired. (#DeviceWithAddress:DeviceAddress:IPv4Address:IPAddress) or (#DeviceWithAddress:DeviceAddress:IPv6Address:IPAddress) You could also have a table at the top of this pattern and just keep track of the octets you care about instead of using IF to assign them. For only 2 possibilities using an IF block is probably fine.

           

          tpl 1.15 module Custom.Location_Mapping;

           

          metadata

              publisher := 'Custom';

              origin := 'YourCompany';

              tkn_name := 'Datacenter Location Mapping';

              tree_path := 'Custom Modules','TPL','Datacenter Location Mapping';

           

          end metadata;

           

          pattern Host_Location_Mapping 1.0

          """

           

          This pattern maps discovered hosts to locations based on the first 2 octets of their IP.

          """

           

          // Required overview section. Tags must be defined.

          overview

               tags Location, mapping;

          end overview;

           

           

          // Trigger when a Host is created, or confirmed on a subsequent discovery

           

          triggers

              on host := Host created, confirmed;

          end triggers;

           

          body

              ip_list := search(in host traverse Device:ChosenEndpoint:Endpoint:Endpoint

                                    );

           

              // Initialize variables

              site := '';

           

              if not ip_list then

                  log.debug ("No Endpoint found");

                  stop;

              else

              for ip_node in ip_list do

                  log.debug("Looking up %ip_node.endpoint%");

               

                  //extract the first 2 octets

                  location_prefix := regex.extract(ip_node.endpoint, regex '(\d{1,3}.){1}\d{1,3}');

               

                  if location_prefix = ('10.116' or '10.117') then

                      // Find the Location

                      site := search(Location where name = 'DC1');

                  elif location_prefix = '10.192' then

                      site := search(Location where name = 'DC2');

                  else

                      site := search(Location where name = 'Unknown');

                  end if;

           

                  if site then

                  // Relate the host to the site

                  model.uniquerel.Location(

                  ElementInLocation := host,

                  Location := site

                  );

                 end if;

           

              end for;

              end if;

           

          end body;

          end pattern;

          1 of 1 people found this helpful
          • 2. Re: associate Host to Location using "Scanned Via"
            Andrew Waters

            discovery.access() will return the current DiscoveryAccess which contains the endpoint being scanned.

             

            You would, in general, be better served in creating Location nodes rather than searching and then linking them which ensures you will have a Location node.

            2 of 2 people found this helpful