10 Replies Latest reply on Jun 7, 2020 12:02 PM by JAYENDRA SAXENA

    Subnet to Location for Storage Devices / Mgt Controllers

      Share This:

      BMC Community

       

      Is it possible to assign a location to Storage Devices and Management devices the way that you can to Hosts,  Network devices and Printers ?

       

       

      If so, what would the trigger condition be for each?

       

      ----------------------------------------------------------------------------------------------------------

      So far I use the following triggers to assign location for Hosts and Network Devices:

      triggers

                on host := Host created, confirmed;

        end triggers;

       

      triggers

        on netdev := NetworkDevice created, confirmed;

        end triggers

      ------------------------------------------------------------------------------------------------------------

       

      Thank You

        • 1. Re: Subnet to Location for Storage Devices / Mgt Controllers
          Andrew Waters

          Yes - you just need to write an equivalent pattern which triggers on the appropriate node kind, e.g. ManagementController.

          • 2. Re: Subnet to Location for Storage Devices / Mgt Controllers

            Thanks Andrew - I got it working using same method we use for hosts & network devices (we use part of the hostname). However, I did download a pattern form the Communities Forum that seems like it would much more efficient for us, but only if there is a way to wildcard the range in the snippet below to only look at the first two octets  in the table even though the ranges in the ADDM scan schedule (for example)  are all set as follows 10.160.192.0/24

             

            tpl 1.5 module HostLocationFromSubnet;

            2

            3

            4

            5 table SubnetToName 1.0

            6

            7   // Update the table below to map the Subnet names to Location names you want

            8

            9 "10.160.192.0/24"->"DC-IOWA";

            10

            11

            12   // A lookup that doesn't have an entry gets a none value

            13   default -> none;

            14 end table;

            15

            16 pattern HostLocationFromSubnet 1.0

            17   '''

            18   Link Hosts to Locations based on subnet.

            19   '''

            20

            21   overview

            22     tags LocationDemo;

            23   end overview;

            24

            25   triggers

            26     on host := Host created, confirmed;

            27   end triggers;

            28  

            29   body

            30     // Extract first subnet linked to the host. If you have multiple subnets -

            31     // you could extend the pattern to link a Host to multiple Locations.

            32     // Does that make sense logically? You decide.

            33

            34     subnets := search(in host traverse DeviceWithAddress:DeviceAddress::IPAddress traverse DeviceOnSubnet:DeviceSubnet:Subnet:Subnet);

            35    

            36    subnet := '';

            37    if not subnets then

            38       // No subnet for this location

            39       log.info('No subnet found for host %host.name%; stopping pattern');

            40       stop;

            41    else

            42      subnet := subnets[0].ip_address_range;

            43     end if;

            44

            45     // Look up the location name from the table

            46     location_name := SubnetToName[subnet];

            47

            48     if not location_name then

            49       // Unknown location

            50       log.info('No location found for host %host.name% (subnet %subnet%); stopping pattern');

            51       stop;

            52     end if;

            53

            54     // Find the Location node(s) for the location. Create one if it does not exist.

            55     location := search(Location where name = '%location_name%');

            56    

            57     if not location then

            58       location := model.Location(name := location_name, key := location_name,

            59                                  description := 'Location generated by HostLocationFromSubnet pattern');

            60     end if;

            61    

            62     // Link the Host to only one Location node

            63     model.uniquerel.Location(

            64       ElementInLocation := host,

            65       Location := location

            66     );

            67    

            68   end body;

            69 end pattern;

            1 of 1 people found this helpful
            • 3. Re: Subnet to Location for Storage Devices / Mgt Controllers
              JAYENDRA SAXENA

              Hi George,

               

              I am able to map the Subnet to Host, which means i can map the location of Servers to Subnet using table

              But i am not able to map the Network Devices by putting "netdev:" in the trigger condition

               

              Can you help me out with the exact TPL using which i can map subnet to network devices as well.

               

              I tried below which is failing

              // Pattern to build Subnet  to location in ADDM.

              tpl 1.11 module SubnetToLocation;

              // Map subnet to location

              table SubnetToLocation 1.0

                "x.x.x.x/24" -> "HQO";

                  "x.x.x.x/24" -> "DCL";

                  "x.x.x.x./24" -> "HQO";

                end table;

              pattern SubnetLocation 1.1

                  '''Pattern to determine and record location of a networkDevices.'''

                  overview

                      tags Extension;

                  end overview;

               

               

                triggers

               

               

                on netdev := NetworkDevice created, confirmed;

               

               

                end triggers

               

               

                  body

                      // Get the list of subnets.

               

               

                          subnets := search(in host

                                        traverse DeviceWithAddress:DeviceAddress:IPv4Address:IPAddress

                                        traverse DeviceOnSubnet:DeviceSubnet:Subnet:Subnet

                                        show ip_address_range);

               

               

                      for subnet in subnets do

                          if subnet in SubnetToLocation then

                              // Found a location. Ensure we have a Location node.

               

               

                              location      := SubnetToLocation[subnet];

                              location_node := model.Location(key  := text.hash(location),

                                                              name := location);

               

               

                              // Relation host to location using uniquerel to ensure single location.

               

               

                              model.uniquerel.Location(ElementInLocation := host,

                                                       Location          := location_node);

               

               

                              stop;

                          end if;

                      end for;

               

               

                  end body;

               

               

              end pattern;

              • 4. Re: Subnet to Location for Storage Devices / Mgt Controllers
                Andrew Waters

                The body of your pattern still refers to host but you changed the trigger to netdev so you would also need to change it in the body.

                1 of 1 people found this helpful
                • 5. Re: Subnet to Location for Storage Devices / Mgt Controllers
                  JAYENDRA SAXENA

                  Hi Andy.

                   

                  What is the "Node" name i should change in the body

                  Should i change the host  -> NetworkDevice

                   

                  body

                          // Get the list of subnets.

                   

                   

                              subnets := search(in host

                                            traverse DeviceWithAddress:DeviceAddress:IPv4Address:IPAddress

                                            traverse DeviceOnSubnet:DeviceSubnet:Subnet:Subnet

                                            show ip_address_range);

                  • 6. Re: Subnet to Location for Storage Devices / Mgt Controllers
                    Bob Anderson

                    Jayendra:

                     

                    Your NetworkDevice pattern needs the following changes:  where you used the variable 'host', switch to the trigger variable 'netdev' (see below)

                     

                    If you also want ManagementControllers and StorageDevices, you will need to duplicate this pattern, for each node kind, changing the pattern name to reflect the node kind each pattern triggers on.  All the patterns can be in the same tpl module.

                     

                    Then for each pattern:

                     

                    change the trigger as needed:

                    on <trigger_variable> := ManagementController created, confirmed;

                    on <trigger_variable> := StorageDevice createc, confirmed;

                     

                    and where you do the subnet search:

                    searc(in <trigger_variable>....);

                     

                    and where ou do the relationship :

                    model.uniquerel.Location( ElementInLocation := <trigger_variable>....);

                     

                    // Pattern to build Subnet  to location in ADDM.

                    tpl 1.11 module SubnetToLocation;

                     

                    // Map subnet to location

                    table SubnetToLocation 1.0

                        "x.x.x.x/24" -> "HQO";

                        "x.x.x.x/24" -> "DCL";

                        "x.x.x.x./24" -> "HQO";

                    end table;

                    pattern SubnetLocation 1.1

                     

                        '''Pattern to determine and record location of NetworkDevices.'''

                        overview

                            tags Extension;

                        end overview;

                     

                        triggers

                            on netdev := NetworkDevice created, confirmed;

                        end triggers

                     

                        body

                            // Get the list of subnets.

                           

                           

                            subnets := search(in netdev

                                        traverse DeviceWithAddress:DeviceAddress:IPv4Address:IPAddress

                                        traverse DeviceOnSubnet:DeviceSubnet:Subnet:Subnet

                                        show ip_address_range);

                           

                           

                            for subnet in subnets do

                                if subnet in SubnetToLocation then

                                    // Found a location. Ensure we have a Location node.

                     

                                    location      := SubnetToLocation[subnet];

                                    location_node := model.Location(

                                                                    key  := text.hash(location),

                                                                    name := location

                                                                    );

                     

                                    // Relation host to location using uniquerel to ensure single location.

                     

                                    model.uniquerel.Location(

                                                            ElementInLocation := netdev,

                                                            Location          := location_node

                                                            );

                     

                                    stop;

                                end if;

                            end for;

                           

                        end body;

                     

                    end pattern;

                     

                     

                    Hope this helps

                     

                    Bob

                    1 of 1 people found this helpful
                    • 7. Re: Subnet to Location for Storage Devices / Mgt Controllers
                      JAYENDRA SAXENA

                      Hi Bob, can you see the below error which is failing to activate this pattern

                      It is showing something wrong at or near line 17

                       

                       

                       

                      • 9. Re: Subnet to Location for Storage Devices / Mgt Controllers
                        Bob Anderson

                        I'm assuming you have made appropriate entries in the SubnetToLocation table which 'moved' the body statement to line 17.

                         

                        I did not test the code above as I was just pointing out the changes that needed to be made.  After actually trying to upload the code, after adding some dummy vaues to the table, I did notice a typo on the 'triggers' block where the 'end triggers' was missing the semi-colon (;) to mark the end of the block.  It should look like end triggers;

                         

                        HTH

                         

                        Bob

                        2 of 2 people found this helpful