IPAddressFixup - グローバル

  • リリースバージョン: Yokohama
  • 更新日 2025年01月30日
  • 所要時間:11分
  • IPAddressFixup スクリプトインクルードは、デバイスが正常に検出された後に、他のデバイスに同じ IP アドレスが割り当てられないようにするメソッドを提供します。重複が見つかると、IP アドレスのフィールドがクリアされます。

    サーバー側の検出スクリプトと一緒に使用して、IP アドレスを検証します。

    IPAddressFixup - dedupe(文字列 tableName, 文字列 ip)

    指定されたテーブル内の、指定された IP アドレスの重複を削除します。

    デバイスが正常に検出された後、dedupe() メソッドを使用してそのデバイスの重複する IP アドレスを削除できます。

    表 : 1. パラメーター
    名前 タイプ 説明
    tableName 文字列 重複を確認するテーブル。
    ip 文字列 確認する IP アドレス。
    表 : 2. 返される内容
    タイプ 説明
    なし

    次の例は、バックグラウンドスクリプトで 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. 返される内容
    タイプ 説明
    なし

    次の例は、バックグラウンドスクリプトで 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. 返される内容
    タイプ 説明
    なし

    次の例は、バックグラウンドスクリプトで 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. 返される内容
    タイプ 説明
    なし

    次の例は、バックグラウンドスクリプトで 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. 返される内容
    タイプ 説明
    なし

    これは、バックグラウンドスクリプトでの 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);