CMDBUtil - 전역

  • 릴리스 버전: Zurich
  • 업데이트 날짜 2025년 07월 31일
  • 소요 시간: 17분
  • CMDBUtil API는 에서 구성 관리 데이터베이스(CMDB) 테이블 관계를 생성 및 관리하고 기준선을 관리하는 CMDB 유틸리티 메서드를 제공합니다.

    CMDBUtil은 JavaScript로 액세스할 수 있는 ScriptableObject입니다. CMDBUtil API에는 동적 메서드와 정적 메서드가 있습니다. SNC를 생성하여 동적 메서드에 액세스합니다. CMDBUtil 객체입니다. SNC를 사용하여 정적 메서드에 액세스합니다. 메서드를 호출할 CMDBUtil 전역 객체입니다.

    이 예시에서는 CMDBUtil 객체를 생성합니다.
    var cu = new SNC.CMDBUtil();
    cu.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));
    이 예제에서는 정적 메서드를 호출합니다.
    var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');

    다음 방법을 사용하여 테이블 관계와 기준선을 관리합니다 CMDB .

    CMDBUtil - baselineProposedChangesApplyChanges(GlideRecord proposedChanges)

    작업과 연결된 모든 CI의 업데이트 세트를 나타내는 task_ci 기록에 제안된 변경을 적용합니다.

    이는 동적 메서드입니다.

    표 1. 매개변수
    이름 유형 설명
    제안된 변경 사항 GlideRecord 변경 요청(CHG)에서 제안된 변경의 컬렉션입니다.
    표 2. 반환
    유형 설명
    void
    //Where current is a GlideRecord and action is the current UI action
    var base = new SNC.CMDBUtil();
    base.baselineProposedChangesApplyChanges(current);

    CMDBUtil - baselineProposedChangesGenDiff(GlideRecord current, string changeSet)

    제안된 변경 diff에 대한 XML을 작성하고 해당 task_ci 기록에 추가합니다.

    이는 동적 메서드입니다.

    표 3. 매개변수
    이름 유형 설명
    current GlideRecord 제안된 변경 내용의 컬렉션을 포함하는 GlideRecord입니다.
    changeSet 문자열 사용할 변경 세트를 나타내는 task_ci 기록의 sysid입니다.
    표 4. 반환
    유형 설명
    void
    //Where current is a GlideRecord and action is the current UI action
    var base = new SNC.CMDBUtil();
    base.baselineProposedChangesGenDIFF(current, action.get('sysparm_changeset'));

    CMDBUtil - 부트스트랩(문자열 dictFile)

    데이터베이스를 작성하고, 시스템 사전 테이블을 작성하고, 시스템 사전 테이블이 자신을 설명하도록 하여 환경을 부트스트랩합니다.

    이는 정적 메서드입니다.

    표 5. 매개변수
    이름 유형 설명
    dict파일 문자열 로드할 딕셔너리의 경로를 포함한 파일 이름입니다.
    표 6. 반환
    유형 설명
    void

    CMDBUtil - createCIRelationship(String tableName, String parent, String child, String parentField, String childField)

    필드 간에 CI 관계를 작성합니다.

    표 7. 매개변수
    이름 유형 설명
    tableName 문자열 옵션입니다. 관계 대상 테이블의 이름입니다.

    기본값: CI 관계 [cmdb_rel_ci] 테이블.

    상위 문자열 구성 항목 [cmdb_ci] 테이블에 있는 상위 CI 기록의 Sys_id.
    하위 문자열 구성 항목 [cmdb_ci] 테이블에 있는 하위 CI 기록의 Sys_id입니다.
    parentField 문자열 CI 관계 유형 [cmdb_rel_type] 테이블에 나열된 상위 관계 레이블입니다.
    childField 문자열 CI 관계 유형 [cmdb_rel_type] 테이블에 나열된 하위 관계 레이블입니다.
    표 8. 반환
    유형 설명
    문자열 CI 관계 [cmdb_rel_ci] 테이블에 나열된 새 기록의 Sys_id입니다.

    다음 예시에서는 상위 CI 포함 필드와 하위 CI contained_by 필드 간에 CI 관계를 생성하는 방법을 보여줍니다. 관계는 CI 관계 [cmdb_rel_ci] 테이블에 나열됩니다.

    var base = new SNC.CMDBUtil();
    base.createCIRelationship('<parent_ci_sys_id>', '<child_ci_sys_id>, 'Contains', 'Contained by');

    CMDBUtil - getAllChildrenOfAsCommaList(String baseTable)

    지정된 테이블의 모든 하위 테이블을 쉼표로 구분된 목록으로 가져옵니다.

    이는 정적 메서드입니다.

    표 9. 매개변수
    이름 유형 설명
    기본 테이블 문자열 기본 테이블 이름입니다.
    표 10. 반환
    유형 설명
    문자열 기본 테이블을 확장하는 테이블 sys_ids 쉼표로 구분된 목록입니다.
    //Where cmdv_ci_computer is a table.
    var output = SNC.CMDBUtil.getAllChildrenOfAsCommaList('cmdb_ci_computer');
    gs.print(output);

    CMDBUtil - getCMDBViews()

    CMDB 뷰 [cmdb_view] 테이블의 모든 기록을 가져옵니다.

    이 방법은 동적입니다.

    표 11. 매개변수
    이름 유형 설명
    없음
    표 12. 반환
    유형 설명
    배열 CMDB 뷰 [cmdb_view] 테이블의 기록 목록입니다.

    다음 예시에서는 CMDB 뷰를 나열하는 방법을 보여줍니다.

    var util = new SNC.CMDBUtil(); 
    var cmdbViews = util.getCMDBViews();
    gs.info(cmdbViews);
    
    // Note that the output in the example is type: java.util.ArrayList
    // To convert to JS Array, use ArrayUtils (add these lines preceding gs.info):
    // var arrUtil = new global.ArrayUtil();
    // var arrViews = arrUtil.convertArray(cmdbViews);

    출력:

    [View 3, View 1, View 2, Another view]

    CMDBUtil - getTables0(문자열 tableName)

    테이블의 모든 상위 항목 목록을 가져옵니다.

    이 메서드는 정적 메서드입니다.

    표 13. 매개변수
    이름 유형 설명
    tableName 문자열 테이블 이름입니다.
    표 14. 반환
    유형 설명
    배열 지정된 테이블의 상위 테이블 목록입니다.

    다음 예에서는 서버 [cmdb_ci_server] 테이블의 상위 테이블을 나열하는 방법을 보여줍니다.

    var gr = new GlideRecord('incident');
    
    // Querying the incident table
    gr.addQuery('number','INC0000005'); 
    gr.query();
    
    
    if(gr.next()){
      // Find the list of parent tables for Configuration item field of this Incident
      var ciParent = SNC.CMDBUtil.getTables0(gr.cmdb_ci.sys_class_name); 
      gs.print("Parent Tables for the Configuration Item '" + gr.cmdb_ci.name + "' belonging to the CMDB Class '"+ gr.cmdb_ci.sys_class_name+ "' are: \n" + ciParent);
    }

    출력:

    Parent Tables for the Configuration Item 'ApplicationServerPeopleSoft' belonging to the CMDB Class 'cmdb_ci_server' are: 
    [cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb]

    CMDBUtil - isExcludedFromBR(문자열 클래스 이름)

    CI 클래스가 비즈니스 규칙 제외 목록 [cmdb_business_rule_exclusions] 테이블에 정의되어 있는지 확인합니다. 제외된 CI 클래스에서 비즈니스 규칙이 실행되지 않도록 하려면 고급 조건에서 이 방법을 사용하십시오.

    예를 들어, 삽입 시 자산 생성 비즈니스 규칙은 고급 조건에서 이 방법을 사용하여 규칙이 cmdb_ci_qualifier, cmdb_ci_endpoint, cmdb_ci_storage_volume, cmdb_ci_vcenter_datastore_disk와 같은 CI 클래스에 대한 자산을 생성하지 못하도록 합니다. 비즈니스 규칙 제외 목록 [cmdb_business_rule_exclusions] 테이블에서 제외할 클래스를 정의합니다.

    표 15. 매개변수
    이름 유형 설명
    className 문자열 제외를 확인할 클래스의 이름입니다.
    표 16. 반환
    유형 설명
    부울 클래스가 비즈니스 규칙 제외 목록 [cmdb_business_rule_exclusions] 테이블에 정의되어 있는 경우 예입니다. 그렇지 않으면 false입니다.
    //Returns true if the cmdb_ci_endpoint class is defined 
    //in the Business Rule Exclusion Lists table
    var exclusion = SNC.CMDBUtil.isExcludedFromBR("cmdb_ci_endpoint");
    
    //Advanced condition that prevents business rules from executing on 
    //classes in the Business Rule Exclusion Lists table
    (!SNC.CMDBUtil.isExcludedFromBR(current.getTableName()))

    CMDBUtil - processCIChange(GlideRecord 이벤트, GlideRecord 대상)

    CI 관계에 대한 모든 변경을 처리하는 RelationshipEventProcessor()에 대한 호출을 래핑합니다.

    이는 동적 메서드입니다.

    표 17. 매개변수
    이름 유형 설명
    이벤트 GlideRecord 이벤트 기록입니다.
    대상 GlideRecord 대상 기록입니다.
    표 18. 반환
    유형 설명
    void

    CMDBUtil - processRelChange(GlideRecord 이벤트, GlideRecord 현재, 문자열 relType, 문자열 삼중항)

    지정된 유형 및 트리플렛을 사용하여 CI 관계에 대한 모든 변경을 처리하는 RelationshipEventProcessor()에 대한 호출을 래핑합니다.

    이는 동적 메서드입니다.

    표 19. 매개변수
    이름 유형 설명
    이벤트 GlideRecord 이벤트 기록
    current GlideRecord 현재 기록으로, 현재 프로세스가 삭제되는 경우 관계 기록 또는 사용자 기록입니다.
    relType 문자열 변경된 관계의 유형입니다.
    삼중항 문자열 변경된 관계의 자식, 상위 및 클래스 이름입니다.
    표 20. 반환
    유형 설명
    void

    CMDBUtil - removeCIRelationship(String tableName, String parentField, String childField, String parentDesc, Object childDesc)

    지정된 CI 관계를 삭제합니다.

    이는 동적 메서드입니다.

    표 21. 매개변수
    이름 유형 설명
    tableName 문자열 옵션입니다. 테이블 이름

    기본값: CI 관계 [cmdb_rel_ci] 테이블

    parentField 문자열 상위 필드
    childField 문자열 하위 필드
    상위 설명 문자열 상위 관계 설명자
    childDesc 객체 하위 관계 설명자
    표 22. 반환
    유형 설명
    void

    이 코드 예제에서는 지정된 상위 항목에 대해 모든 관계 유형 'Depends on::Used by'를 제거하는 방법을 보여 줍니다.

    var cu = new SNC.CMDBUtil();
    var parentSysID = '27d18f6fc0a8000b00ad14d4929d1b45';
    var parentDesc = 'Depends on';
    var childDesc = 'Used by'
     
    // Get records with parent equal parentSysID
    var relation = new GlideRecord('cmdb_rel_ci');
    relation.addQuery('parent', parentSysID);
    relation.query();
    while(relation.next()){
        // Remove every relation of type: 'Depends on::Used by' for the parent
        // If the relation type does not exist, it inserts this relation type into [cmdb_rel_type].
        cu.removeCIRelationship('cmdb_rel_ci', parentSysID, relation.child.getValue('sys_id'), parentDesc, childDesc)
    }

    CMDBUtil - reParentTable(문자열 테이블, 문자열 oldParent, 문자열 newParent)

    지정된 테이블의 상위 항목을 새 상위 항목으로 변경합니다.

    표 23. 매개변수
    이름 유형 설명
    테이블 문자열 상위 항목을 재지정할 테이블입니다.
    oldParent 문자열 늙은 부모.
    newParent 문자열 새 상위 항목입니다.
    표 24. 반환
    유형 설명
    부울

    상위 변경이 성공했는지 여부를 나타내는 플래그입니다.

    유효한 값은 다음과 같습니다.
    • true: 상위 변경에 성공했습니다.
    • false: 상위 변경에 성공하지 못했습니다.

    다음 예시를 다시 작성하려면 제공된 코드를 사용하여 사용자 지정 테이블을 생성합니다. 다음으로 기록을 생성하고 작업 테이블에서 체크 인합니다. 생성된 사용자 지정 테이블은 작업 테이블에서 확장되며, 이는 성공적으로 상위 항목이 재지정되었음을 의미합니다. 이 코드는 복사 및 붙여넣기를 통해 직접 사용하기 위한 것이 아닙니다. 출력을 표시하기 위해 코드를 실행하기 전에 사용자 지정 테이블이 생성되었습니다.

    /*
      Before running the code in the background Script Make Sure 'Record For Rollback' is unchecked.
    
      This API CMDBUtil.reParentTable changes the parent of the table but will not allow the OOB tables to change the parent it works only in the custom table. Hence this script contains the creation of the custom table.
      API CMDBUtil.reParentTable has 3 parameters (Table, Old Parent , New Parent);
      We can make the Parent as Null as well by using this (Table, Old Parent, '');
    
      The code in this example shows how to create a custom table without any extension.
      Then creating a record and then again creating a record and checking in the task table after it gets extended to the task table.
    
      If the code returns false means the record is not present in the task table as it is not extended. It returns true only when the record is found in the task table after the table is extended.
    
    */
    
    /* Run the following code to create the custom table without an extension
    createCustomTable('u_custom_table','Custom Table'); // Creating a custom Table (don't create if you have one)
    var CreatedRecord = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    
    var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); // Extending the custom table to task table . This Works only when the table is extendable
    var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); // Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  // Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    */
    
    // If the custom Table is already created, run this. (Do not run these 4 lines when creating the table)
    gs.print(CheckRecord('u_custom_table')); //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    var getParentTables = new SNC.CMDBUtil.reParentTable('u_custom_table','','task'); //Extending the custom table to task table . This Works only when the table is extendable
    var CreatedRecordAfter = CreateCustomRecord('u_custom_table'); //Creating a record in the custom table
    gs.print(CheckRecord('u_custom_table'));  //Checking of the record in the task table by passing the Class Name (A.K.A your custom Table)
    
    
    function createCustomTable(Name, Label)
    {
      var customTable = new GlideRecord('sys_db_object');
      customTable.initialize();
      customTable.name=  Name ;
      customTable.label= Label ;
      customTable.is_extendable= true;
      customTable.insert();
    }
    
    function CreateCustomRecord(customTableName)
    {
      var customTable = new GlideRecord(customTableName);
      customTable.initialize();
      return customTable.insert();
    }
    
    function CheckRecord(customTableName)
    {
      var task =new GlideRecord('task');
      task.addQuery('sys_class_name', customTableName);
      task.query();
    
      if(task.next())
      {
        return true;
      }
    
      return false;
    }

    출력:

    *** Script: true
    *** Script: true