AbstractDBObject - 전역

  • 릴리스 버전: Washingtondc
  • 업데이트 날짜 2024년 02월 01일
  • 읽기3분
  • AbstractDBObject API는 데이터베이스의 레코드를 기반으로 클래스에 대한 공통 메서드를 제공합니다.

    이 스크립트 포함을 기본 클래스로 사용하여 사용자 고유의 데이터베이스 오브젝트 클래스를 작성할 수 있습니다.

    AbstractDBObject - isValid()

    현재 데이터베이스 기록이 유효한지 여부를 확인합니다.

    IPService - 전역 또한 참조하십시오.

    표 1. 매개변수
    이름 유형 설명
    없음
    표 2. 반환
    유형 설명
    부울 데이터베이스 기록이 유효하면 True이고, 그렇지 않으면 false입니다.

    데이터베이스 기록이 유효한지 여부를 나타내는 플래그입니다.

    유효한 값은 다음과 같습니다.
    • true: 데이터베이스 기록이 유효합니다.
    • false: 데이터베이스 기록이 잘못되었습니다.

    다음 예제에서는 IP Services [cmdb_ip_service] 테이블에서 IPService() 클래스를 사용하여 유효한 인스턴스 목록을 가져오는 방법을 보여 줍니다. IPService 클래스는 AbstractDBObject() 클래스를 확장합니다.

    /**
     * IPService class Encapsulates the notion of an IP Service. Instances in which isValid() returns true have the 
     * following properties initialized: 
     *  sysID:       sys_id of this record
     *  port:        the TCP or UDP port used by the service
     *  protocol:    protocol used by the service ("UDP", "TCP", or "TCP/UDP")
     *  name:        short name or handle
     *  serviceName: long, descriptive English name
     *  creates:     table that this service creates entries in
     *  description: description
     */
    
    var result = [];
    // Array of sys_id's from the IP Service class which we want to get the abstract details
    var list = ['db9840e10ab3015500f5e3fe8f78da42', 'a1505ebc7782330099808d1168106179', 'abc05ebc7782330099808d1168106112'];
    
    // query for the records on the list
    var ipservice = new GlideRecord('cmdb_ip_service');
    ipservice.addQuery('sys_id', 'IN', list.toString());
    ipservice.query();
    while (ipservice.next()) {
        var ip = new IPService(ipservice); // IPService class extends AbstractDBObject class and this class 
        if (ip.isValid())      // check whether the record is valid or not
            result.push(ip);   // if valid get the properties for 
    }
    
    gs.info(JSON.stringify(result, null, 2));

    출력:

    [
      {
        "valid": true,
        "sysID": "a1505ebc7782330099808d1168106179",
        "port": "8882",
        "protocol": "TCP",
        "name": "blkbry-uem-enroll",
        "serviceName": "Blackberry Enrollment Request",
        "creates": null,
        "description": null
      },
      {
        "valid": true,
        "sysID": "db9840e10ab3015500f5e3fe8f78da42",
        "port": "548",
        "protocol": "TCP",
        "name": "afp",
        "serviceName": "Apple File Protocol",
        "creates": null,
        "description": null
      }
    ]