Syncmapping to help SerialNumber be unique in the CMDB for Stacked switches

Version 2
    Share This:

    ============================================================================================================================

    How to get Started creating CMDB Syncmapping Extension patterns:  Getting Started creating a CMDB Syncmapping Extension pattern

    Info about custom patterns and syncmappings, how to test, etc:  Helix Support: Discovery custom patterns discussion

    Sample syncmapping 'stubs' / starting points :  Helix Support: Discovery: Sharing my library of syncmapping extension stubs

    Sample patterns and syncmappings posted by Lisa:  https://goo.gl/8KUS3S

    ============================================================================================================================

    DISCLAIMER: Samples provided on the communities are only examples to be tested by the customer on a TEST system.  

    Adding additional data to the CMDB may adversely affect the AR Server and CMDB performance.      

    Swim at your own risk.

    ============================================================================================================================

     

     

    BMC Discovery aims to create a unique combination of serial# and partition_id for stacked devices.

    So, the serial# by itself is not necessarily unique in Discovery.

     

    Some customers require the serial# (by itself) to be unique in the CMDB.

    That is the aim of this syncmapping.

     

    If there is a partition_id but no serial, then the SerialNumber (in CMDB) is set to partition_id, for any device type.

     

    If device.type matches "Stack" or device.type = "Switch / SANSwitch" then there is more logic to make SerialNumber unique.

     

        ===============================================================================

        Examples of the (more unique) SerialNumber created by this syncmapping:

        ===============================================================================

        partition_id                                 serial in discovery         SerialNumber in cmdb

        ===============================================================================

        01234                                        <none>                      01234

        XYZ7777008M:1                                XYZ7777008M_STACK           XYZ7777008M_STACK:1

        StackMember/CHASSIS:777122/DDD2118R0E3/3     DDD2118R0E3                 DDD2118R0E3/3

        ===============================================================================

     

    The last 2 examples above only work where device.type = "Stack" or "Switch / SANSwitch".

     

    Here is the pattern, and also is attached.

     

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

     

    tpl 1.14 module CMDB.Extension.NetworkDevice_Extend;

     

    from CMDB.NetworkDevice_ComputerSystem import NetworkDevice_ComputerSystem 2.1;

     

    syncmapping NetworkDevice_Extend 1.0

        """

        Extend syncmapping for NetworkDevice node to BMC_ComputerSystem CI.

        Add unique identifier to the SerialNumber in the CMDB for stacked devices

     

        BMC Discovery aims to create a unique combination of serial# and partition_id for stacked devices.

     

        Some customers require the SerialNumber (by itself) to be unique in the CMDB.

        That is the aim of this syncmapping.

     

        If there is a partition_id but no serial, then the SerialNumber in CMDB is set to partition_id, for any device type.

     

        If device.type matches "Stack" or device.type = "Switch / SANSwitch" then there is more logic to make SerialNumber unique.

     

        ===============================================================================

        Examples of the (more unique) serial_in_cmdb created by this syncmapping:

        ===============================================================================

        partition_id                                 serial in discovery         SerialNumber in cmdb

        ===============================================================================

        01234                                        <none>                      01234

     

    Only for Stack or Switch / SANSwitch types below:

        XYZ7777008M:1                                XYZ7777008M_STACK           XYZ7777008M_STACK:1

        StackMember/CHASSIS:777122/DDD2118R0E3/3     DDD2118R0E3                 DDD2118R0E3/3

        ===============================================================================

        """

     

        overview

            tags CMDB, Extension;

        end overview;

     

        mapping from NetworkDevice_ComputerSystem.device as device

            // No additional structure -- we are just modifying the

            // existing ComputerSystem CI.

        end mapping;

     

        body

            computersystem := NetworkDevice_ComputerSystem.device_cs;

            hostname := computersystem.HostName;

            parts := [];

            new_serial := device.serial;

            partition_id := device.partition_id;

     

            log.debug("UNIQUE_SERIAL 1: I am in the extension syncmapping.");

            log.debug("UNIQUE_SERIAL 2: original serial=%new_serial%  partition_id=%partition_id% type=%device.type%");

     

            if partition_id and not new_serial then

                new_serial := partition_id;

                log.debug("UNIQUE_SERIAL 3: new serial=%new_serial%  partition_id=%partition_id% type=%device.type%");

     

            elif partition_id and partition_id <> new_serial then

                log.debug("UNIQUE_SERIAL 4: orig serial=%new_serial%  partition_id=%partition_id% type=%device.type%");

     

                //maybe append partition_id or part of partition_id to the serial number

                if device.type matches "Stack" or device.type = "Switch / SANSwitch" then

     

                    serial_portion := new_serial;

                    if new_serial has subword "_STACK" then

                        serial_portion := text.split(new_serial, "_");

                        serial_portion := serial_portion[0];

                    end if;

     

                    log.debug("UNIQUE_SERIAL 5: orig serial=%new_serial% serial_portion=%serial_portion% partition_id=%partition_id%");

     

                    if '/' in partition_id then

                        //split the partition_id on a slash

                        parts := text.split(partition_id, "/");

                        log.debug("UNIQUE_SERIAL 5.1: split on slash.");

                    elif ':' in partition_id then

                        //split the partition_id on a colon

                        parts := text.split(partition_id, ":");

                        log.debug("UNIQUE_SERIAL 5.2: split on colon.");

                    end if;

     

                    for part in parts do

                        log.debug("UNIQUE_SERIAL 6: serial=%new_serial% serial_portion=%serial_portion% partition_id=%partition_id% part=%part%");

     

                        if (part <> "StackMember") and

                            (part <> new_serial) and

                            (not part has subword "CHASSIS") and

                            (part <> "%new_serial%_STACK") and

                            (part <> serial_portion) then

                                extended_new_serial := "%new_serial%:%part%";

                                log.debug("UNIQUE_SERIAL 6.5: extended_new_serial = %extended_new_serial%");

                                new_serial := extended_new_serial;

                                log.debug("UNIQUE_SERIAL 7: new serial=%new_serial%  partition_id=%partition_id%");

                        end if;

                    end for;

                end if;

            end if;

     

            log.debug("UNIQUE_SERIAL 8: new serial=%new_serial%  partition_id=%partition_id%");

            computersystem.SerialNumber := new_serial;

            log.debug("UNIQUE_SERIAL 9: FINAL new serial=%computersystem.SerialNumber%  partition_id=%computersystem.PartitionId%");

     

            if new_serial <> device.serial then

                log.debug("UNIQUE_SERIAL 10: Serial number was changed in the CMDB.  old=%device.serial%  new=%new_serial%");

            else

                log.debug("UNIQUE_SERIAL 11: Serial number was NOT changed in the CMDB.  serial=%new_serial%");

            end if;

        end body;

    end syncmapping;

     

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++