IPAddressFixup - 전역

  • 릴리스 버전: Xanadu
  • 업데이트 날짜 2024년 08월 01일
  • 읽기11분
  • IPAddressFixup 스크립트 포함은 장치가 성공적으로 검색된 후 다른 장치에 동일한 IP 주소가 없도록 하는 메서드를 제공합니다. 중복된 항목이 발견되면 IP 주소 필드가 지워집니다.

    서버 쪽 검색 스크립트와 함께 사용하여 IP 주소를 확인합니다.

    IPAddressFixup - 중복 제거(문자열 tableName, 문자열 ip)

    지정된 테이블에서 지정된 IP 주소의 중복을 제거합니다.

    장치가 성공적으로 검색되면 dedupe() 메서드를 사용하여 해당 장치에 대한 중복 IP 주소를 제거할 수 있습니다.

    표 1. 매개변수
    이름 유형 설명
    tableName 문자열 중복을 확인할 테이블입니다.
    ip 문자열 확인할 IP 주소입니다.
    표 2. 반환
    유형 설명
    void

    다음 예제에서는 백그라운드 스크립트에서 dedupe() 를 사용하여 cmdb_ci_hardware 테이블 내에서 지정된 IP 주소에 대한 중복 IP 주소를 제거하는 방법을 보여 줍니다.

    var grDiscovery=new GlideRecord("discovery_device_history");
    grDiscovery.addQuery('sys_id','<sys id of the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference 
        fx.dedupe('cmdb_ci_hardware','192.161.1.1'); // Pass the IP address and table which removes duplicates of the specified IP address in the specified table.
      }

    다음 예는 비즈니스 규칙에서 dedupe() 를 사용하여 cmdb_ci_hardware 테이블 내에서 지정된 IP 주소에 대한 중복 IP 주소를 제거하는 방법을 보여줍니다.

    (function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        ipf.dedupe('cmdb_ci_hardware','168.128.1.1'); // Removes duplicates of the specified IP address in the specified table.
      }
    })(current, previous);

    IPAddressFixup - dedupeAll()

    테이블에서 중복된 IP 주소를 모두 제거합니다.

    표 3. 매개변수
    이름 유형 설명
    없음
    표 4. 반환
    유형 설명
    void

    다음 예제에서는 백그라운드 스크립트에서 dedupeAll() 을 사용하여 중복된 IP 주소를 모두 제거하는 방법을 보여 줍니다.

    var grDiscovery=new GlideRecord("discovery_device_history"); 
    grDiscovery.addQuery('sys_id','<sys id of the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
    {
      var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Call script include IPAddressFixup and pass cmdb reference
      fx.dedupeAll(); //Removes all duplicate IP addresses from the tables.
    }

    다음 예는 비즈니스 규칙에서 dedupeAll() 을 사용하여 중복된 IP 주소를 모두 제거하는 방법을 보여줍니다.

    (function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
    {
      var ipf = new IPAddressFixup(cmdb_ci); //call script include IPAddressFixup and pass cmdb reference
      ipf.dedupeAll(); //Removes all duplicate IP addresses from the tables.
    })(current, previous);

    IPAddressFixup - fix()

    중복 IP 주소를 모두 제거하고 상위 ip_address 기록이 네트워크 인터페이스 카드(NIC)의 IP 주소 중 하나로 설정되도록 합니다.

    장치가 성공적으로 검색되면 dedupe() 메서드를 사용하여 해당 장치에 대한 중복 IP 주소를 제거하고 상위 ip_address 레코드 값을 설정할 수 있습니다.

    표 5. 매개변수
    이름 유형 설명
    없음
    표 6. 반환
    유형 설명
    void

    다음 예제에서는 백그라운드 스크립트에서 fix() 를 사용하여 중복 IP 주소를 제거하고 상위 IP 주소를 설정하는 방법을 보여줍니다.

    var grDiscovery=new GlideRecord("discovery_device_history"); 
    grDiscovery.addQuery('sys_id','<sys id of the the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        fx.fix(); // Remove all duplicate IP addresses and ensure that the parent ip_address record is set to one of the NIC's IP addresses.
      }

    다음 예는 비즈니스 규칙에서 fix() 를 사용하여 중복 IP 주소를 제거하고 상위 IP 주소를 설정하는 방법을 보여줍니다.

    (function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        ipf.fix(); /// Remove all duplicate IP addresses and ensure that the parent ip_address record is set to one of the NIC's IP addresses.
      }
    })(current, previous);

    IPAddressFixup - getParentIP()

    현재 장치의 상위 IP 주소를 반환합니다.

    표 7. 매개변수
    이름 유형 설명
    없음
    표 8. 반환
    유형 설명
    문자열 상위 IP 주소

    다음 예제에서는 백그라운드 스크립트에서 getParentIP() 를 사용하여 상위 IP 주소를 가져오는 방법을 보여 줍니다.

    var grDiscovery=new GlideRecord("discovery_device_history"); // current.cmdb_ci can be used in case of Business rule on discovery_device_history table
    grDiscovery.addQuery('sys_id','<sys id of the the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        gs.info(fx.getParentIP()); // Display the parent IP address of the device 
      }

    출력:

    172.21.12.11

    다음 예는 비즈니스 규칙에서 getParentIP() 를 사용하여 상위 IP 주소를 가져오는 방법을 보여줍니다.

    ((function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        gs.log(ipf.getParentIP()); // Log the parent IP address of the device. Located in the system logs table 
      }
    })(current, previous);

    IPAddressFixup - setParentIP(문자열 ip)

    현재 CI의 상위 IP 주소 필드를 설정합니다.

    표 9. 매개변수
    이름 유형 설명
    ip 문자열 현재 CI의 상위 IP 주소입니다.
    표 10. 반환
    유형 설명
    void

    다음 예제에서는 백그라운드 스크립트에서 setParentIP() 를 사용하여 상위 IP 주소를 저장하는 방법을 보여 줍니다.

    var grDiscover=new GlideRecord("discovery_device_history"); 
    grDiscover.addQuery('sys_id','a14e43b31bb4051070cb96c6b04bcb23'); // sys_id of the device in discovery_device_history table. Put your own sys_id here.
    grDiscover.query();
    if(grDiscover.next())
      {
        var fx=new IPAddressFixup(grDiscover.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference.
        fx.setParentIP('197.111.1.1'); // Pass IP address to set as new IP on current mentioned CI.
      }

    다음 예는 비즈니스 규칙에서 setParentIP() 를 사용하여 상위 IP 주소를 저장하는 방법을 보여줍니다.

    ((function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        fx.setParentIP('195.11.1.1'); // Set the new IP address of the CI 
      }
    })(current, previous);

    IPAddressFixup - syncIP()

    상위 ip_address 레코드가 NIC의 IP 주소 중 하나로 설정되어 있는지 또는 NIC가 없는 경우 그대로 두는지 확인합니다.

    표 11. 매개변수
    이름 유형 설명
    없음
    표 12. 반환
    유형 설명
    void

    다음은 백그라운드 스크립트에서 syncIP() 메서드를 사용하는 예를 보여 줍니다.

    var grDevHistory=new GlideRecord("discovery_device_history");
    grDevHistory.addQuery('sys_id','a14e43b31bb4051070cb96c6b04bcb23'); // Sys_id of the device in discovery_device_history table. Put your own sys_id here.
    grDevHistory.query();
    if(grDevHistory.next())
      {
        var fx=new IPAddressFixup(grDevHistory.cmdb_ci); // Call the script include IPAddressFixup and pass cmdb reference
        fx.syncIP(); // Ensures that the parent ip_address record is set to one of the NIC's IP addresses, or leaves it alone if there were no NICs.
      }

    다음은 비즈니스 규칙에서 syncIP() 메서드를 사용하는 예를 보여 줍니다.

    (function executeRule(current, previous /*null when async*/) {
    
    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Call script include IPAddressFixup and pass cmdb reference
        ipf.syncIP(); // Ensures that the parent ip_address record is set to one of the NIC's IP addresses, or leaves it alone if there were no NICs.
      }
    })(current, previous);